Olympiad in Informatics

AtCoder Regular Contest 091 - Problem-Solving Report

The code for this round is all so short.

C - Flip,Flip, and Flip......

Stupid-easy problem; just do whatever.

// ARC091A.cpp
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, m;

int main()
{
    scanf("%d%d", &n, &m);
    if (n > m)
        swap(n, m);
    if (n == 1)
    {
        if (m == 1)
            puts("1");
        else
            printf("%d\n", max(0, m - 2));
        return 0;
    }
    printf("%lld\n", max(0LL, 1LL * (n - 2) * (m - 2)));
    return 0;
}

D - Remainder Reminder

This problem is also pretty stupid: enumerate \(b\), then count the number of \(a\).

// ARC091B.cpp
#include <bits/stdc++.h>

using namespace std;

int n, k;

int main()
{
    scanf("%d%d", &n, &k);
    long long ans = 0;
    for (int b = max(k + 1, 1); b <= n; b++)
    {
        int rem = (n + 1) % b, loop_num = (n + 1) / b;
        int bpart = b - k;
        long long pans = 1LL * loop_num * bpart + max(0, rem - k) - (k == 0);
        ans += pans;
    }
    printf("%lld\n", ans);
    return 0;
}

E - LISDL

This problem is fairly interesting.

Consider constructing a sequence of length \(AB\); then a sequence satisfying the conditions can be constructed as:

\[ (B - 1)A + 1, (B - 1)A + 2, \dots, BA, (B - 2)A + 1, (B - 2)A + 2, \dots \]

We notice that the only parts of this sequence that do any work are the \(B\) descent points overall and at least one increasing run of length \(A\). So we can throw away some of the useless information and then relabel what remains into a permutation.

// ARC091C.cpp
#include <bits/stdc++.h>

using namespace std;

int n, a, b;

int main()
{
    scanf("%d%d%d", &n, &a, &b);
    if (a + b - 1 > n || 1LL * a * b < n)
        puts("-1"), exit(0);
    while (n > 0)
    {
        int rd = min(a, n - b + 1);
        for (int i = n - rd + 1; i <= n; i++)
            printf("%d ", i);
        n -= rd, b--;
    }
    puts("");
    return 0;
}

F - Strange Nim

Godlike game theory.

Each pile of stones is independent, so we just compute the SG function values separately and XOR them together. Notice that:

\[ SG(X, K) = \begin{cases} \frac{X}{K}, X \bmod K \equiv 0 \\ SG(X - \lfloor \frac{X}{K} \rfloor + 1), \text{otherwise} \end{cases} \]

And then it’s OK.

// ARC091D.cpp
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, ans = 0;
    scanf("%d", &n);
    for (int i = 1, x, k; i <= n; i++)
    {
        scanf("%d%d", &x, &k);
        while (x % k != 0)
            x -= ((x % k - 1) / (x / k + 1) + 1) * (x / k + 1);
        ans ^= x / k;
    }
    puts(!ans ? "Aoki" : "Takahashi");
    return 0;
}