1334A - Level Statistics

Click to show code.


using namespace std;
const int NMAX = 100 + 11;
int n, p[NMAX], c[NMAX];
bool solve(void)
{
    int lp, lc, dp, dc;
    lp = lc = 0;
    for (int i = 0; i < n; ++i)
    {
        dp = p[i] - lp;
        dc = c[i] - lc;
        if (dp < 0 or dc < 0 or dp < dc)
            return false;
        lp = p[i];
        lc = c[i];
    }
    return true;
}
int main(void)
{
    int t;
    cin >> t;
    while (t--)
    {
        cin >> n;
        for (int i = 0; i < n; ++i)
            cin >> p[i] >> c[i];
        cout << (solve() ? "YES" : "NO") << endl;
    }
}


1333B - Kind Anton

Click to show code.


using namespace std;
const int NMAX = 1e5 + 11;
int n, a[NMAX], b[NMAX];
bool prefplus[NMAX], prefminus[NMAX];
bool solve(void)
{
    for (int i = n - 1; i >= 0; --i)
    {
        if (b[i] > a[i] and not prefplus[i])
            return false;
        if (b[i] < a[i] and not prefminus[i])
            return false;
    }
    return true;
}
int main(void)
{
    int t;
    cin >> t;
    while (t--)
    {
        cin >> n;
        bool prefix_plus, prefix_minus;
        prefix_minus = prefix_plus = false;
        for (int i = 0; i < n; ++i)
        {
            cin >> a[i];
            prefplus[i] = prefix_plus;
            prefminus[i] = prefix_minus;
            prefix_plus |= (a[i] == 1);
            prefix_minus |= (a[i] == -1);
        }
        for (int i = 0; i < n; ++i)
            cin >> b[i];
        cout << (solve() ? "YES" : "NO") << endl;
    }
    return 0;
}


1333A - Little Artem

Click to show code.


using namespace std;
int main(void)
{
    int t, n, m;
    cin >> t;
    while (t--)
    {
        cin >> n >> m;
        bool black = true;
        for (int row = 0; row < n; ++row)
        {
            for (int col = 0; col < m; ++col)
            {
                if (row == 0 and col == 1 and (n * m) % 2 == 0)
                    cout << (black ? "W" : "B");
                else
                    cout << (black ? "B" : "W");
                black = !black;
            }
            cout << endl;
        }
    }
    return 0;
}


1332B - Composite Coloring

Click to show code.


using namespace std;
const int NMAX = 1000 + 11;
int ccolor;
int colors[NMAX];
map<int, int> rankdiv;
int smallest_div(int x)
{
    if (x % 2 == 0)
        return 2;
    for (int i = 3; i * i <= x; i += 2)
        if (x % i == 0)
            return i;
    return x;
}
int main(void)
{
    int t, n, x, sd;
    cin >> t;
    while (t--)
    {
        rankdiv.clear();
        ccolor = 1;
        cin >> n;
        for (int i = 0; i < n; ++i)
        {
            cin >> x;
            sd = smallest_div(x);
            colors[i] = rankdiv[sd] = (rankdiv[sd] ? rankdiv[sd] : ccolor++);
        }
        cout << ccolor - 1 << endl;
        for (int i = 0; i < n; ++i)
            cout << colors[i] << " ";
        cout << endl;
    }
    return 0;
}


1332A - Exercising Walk

Click to show code.


using namespace std;
int l, r, d, u;
int x, y;
int x1, y1, x2, y2;
inline bool contained(int val, int l1, int l2)
{
    return l1 <= val and val <= l2;
}
bool solve(void)
{
    int xf, yf;
    xf = x + (r - l);
    yf = y + (u - d);
    if (x1 == x2 and (l or r))
        return false;
    if (y1 == y2 and (d or u))
        return false;
    if (contained(xf, x1, x2) and contained(yf, y1, y2))
        return true;
    return false;
}
int main(void)
{
    int t;
    cin >> t;
    while (t--)
    {
        cin >> l >> r >> d >> u;
        cin >> x >> y;
        cin >> x1 >> y1 >> x2 >> y2;
        cout << (solve() ? "YES" : "NO") << endl;
    }
    return 0;
}


1331H - Its Showtime

Click to show code.


using namespace std;
int main(void)
{
    int input, n, mod, lower, ans = 1;
    cin >> input;
    mod = input % 1000;
    n = (input - mod) / 1000;
    lower = (input % 2 == 0 ? 2 : 1);
    cout << n << endl << mod << endl;
    for (int i = n; i >= lower; i -= 2)
        ans = (ans * i) % mod;
    cout << lower << endl;
    cout << ans << endl;
    cout << ans % mod << endl;
    return 0;
}


1331B - Limericks

Click to show code.


using namespace std;
int main(void)
{
    string s;
    int n;
    cin >> s;
    n = s.size();
    cout << (s[n - 1] % 2 == 1) << endl;
    return 0;
}


1331A - Is It Rated

Click to show code.


using namespace std;
int main(void)
{
    cout << "NO\n";
    return 0;
}


1328D - Carousel

Click to show code.


using namespace std;
using ll = long long;
using vi = vector<int>;
int main(void)
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vi t(n);
        for (auto &ti : t)
            cin >> ti;
        int changes = 0;
        for (int i = 0; i < n; ++i)
            if (t[i] != t[(i - 1 + n) % n])
                ++changes;
        int color;
        if (changes % 2 == 0)
        {
            cout << (changes == 0 ? 1 : 2) << endl;
            color = 0;
            for (int i = 0; i < n; ++i)
            {
                cout << color + 1 << " ";
                if (t[i] != t[(i + 1 + n) % n])
                    color = 1 - color;
            }
            cout << endl;
        }
        else
        {
            if (changes == n)
            {
                cout << 3 << endl;
                color = 0;
                for (int i = 0; i < n; ++i)
                {
                    cout << color + 1 << " ";
                    if (i == n - 2)
                        color = 2;
                    else if (t[i] != t[(i + 1 + n) % n])
                        color = 1 - color;
                }
                cout << endl;
            }
            else
            {
                int start = 0;
                while (t[(start + n) % n] != t[(start - 1 + n) % n])
                    start = (start + 1 + n) % n;
                while (t[(start + n) % n] == t[(start + 1 + n) % n])
                    start = (start + 1 + n) % n;
                vi ans(n);
                cout << 2 << endl;
                color = 0;
                for (int i = 0; i < n; ++i)
                {
                    ans[(start + i) % n] = color + 1;
                    if (t[(start + i) % n] != t[(start + i + 1 + n) % n])
                        color = 1 - color;
                }
                for (auto x : ans)
                    cout << x << " ";
                cout << endl;
            }
        }
    }
    return 0;
}


1328C - Ternary Xor

Click to show code.


using namespace std;
int main(void)
{
    int t, n, x, y;
    bool bigger;
    string s, a, b;
    cin >> t;
    while (t--)
    {
        cin >> n >> s;
        bigger = false;
        for (int i = 0; i < n; ++i)
        {
            if (not bigger)
            {
                y = (s[i] - '0') / 2;
                x = (s[i] - '0') - y;
                a.push_back(x + '0');
                b.push_back(y + '0');
                if (x > y)
                    bigger = true;
            }
            else
            {
                a.push_back('0');
                b.push_back(s[i]);
            }
        }
        cout << a << endl << b << endl;
        a.clear();
        b.clear();
    }
    return 0;
}