---
id: 2432
lang: en
translation_of: index.md
source_sha256: 566d024005a793d75ebec1533465248e0558874f855d178eb1a0937827195506
title: "AtCoder Regular Contest 091 - Problem-Solving Report"
description: "Solutions to problems C to F of AtCoder Regular Contest 091: two easy ones, a constructive LIS/LDS problem and a Nim variant solved with SG values."
tags: ["OI","Game Theory","Constructive","AtCoder"]
translated: 2026-11-27
translator: Claude Opus 5.5
translator_model: claude-opus-5-5
translation_notes:
  - "解题报告 rendered as “Problem-Solving Report” (glossary jargon); the stored ' - ' in the title and headings is kept."
  - "The Chinese ellipsis …… in the heading of problem C becomes ......, as in the official AtCoder problem name; the comma without a space in “Flip,Flip” is kept as stored."
  - "随便搞 rendered “just do whatever” without a chip, as in post 1747."
---

The code for this round is all so short.

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

<span class="slang" data-zh="傻逼题" data-gloss="shǎbī tí, “idiot problem”. Vulgar: a problem so easy that it is insulting.">Stupid-easy problem</span>; just do whatever.

```cpp
// 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;
}
```

<!--more-->

## D - Remainder Reminder

This problem is also pretty <span class="slang" data-zh="傻逼" data-gloss="shǎbī. A vulgar insult, roughly “idiot” or “stupid”.">stupid</span>: enumerate $b$, then count the number of $a$.

```cpp
// 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.

```cpp
// 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

<span class="slang" data-zh="神仙" data-gloss="shénxiān, “immortal”. Someone, or a problem or idea, so brilliant it seems superhuman.">Godlike</span> 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.

```cpp
// 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;
}
```
