---
id: 1751
lang: en
translation_of: index.md
source_sha256: 4ef32172a476f7abd61a1c4fa7ec2d019bdcab9689e5b61dbc19d96656e01587
title: "[Nowcoder OI Weekly Contest 2 - Senior Division] Problem-Solving Report"
description: "Solutions to Nowcoder OI Weekly Contest 2 (Senior Division): working inward from the edges for A, a pattern from small cases for B, and digit DP for C."
tags: ["OI","Problem-Solving Report"]
translated: 2026-11-27
translator: Claude Opus 5.5
translator_model: claude-opus-5-5
translation_notes:
  - "取模 (take the modulus) rendered as “take the remainder”; the modulus is not named in the original."
  - "Problem names translated: 游戏 Game, 水果蛋糕 Fruit Cake, 好朋友 Good Friends; 牛客 rendered as Nowcoder, 提高组 as Senior Division."
---

## A - Game

I basically just <span class="slang" data-zh="乱搞" data-gloss="luàngǎo, “random messing”. Unproven heuristic or randomized tricks that happen to pass.">messed around</span>: operate from the outermost layer inward, count the operations, take the remainder, and map it to the corresponding name. I don't really understand why it passed.

```cpp
// A.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e3 + 200;

char mp[MAX_N][MAX_N];
int n, m, T, delta[MAX_N][MAX_N], now[MAX_N][MAX_N], matrix[MAX_N][MAX_N];

int main()
{
    scanf("%d", &T);
    while (T--)
    {
        memset(delta, 0, sizeof(delta)), memset(now, 0, sizeof(now));
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= n; i++)
            scanf("%s", mp[i] + 1);
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                if (mp[i][j] == 'R')
                    matrix[i][j] = 1;
                else if (mp[i][j] == 'G')
                    matrix[i][j] = 2;
                else
                    matrix[i][j] = 0;
        int cnt = 0;
        for (int i = n; i >= 1; i--)
        {
            delta[i][m + 1] += delta[i + 1][m + 1];
            for (int j = m; j >= 1; j--)
            {
                delta[i][j] += delta[i + 1][j];
                now[i][j] = now[i][j + 1] + delta[i][j + 1];
                int curt = (matrix[i][j] + now[i][j]) % 3;
                cnt += (3 - curt) % 3;
                now[i][j] += (3 - curt) % 3, delta[i][j + 1] += (3 - curt) % 3;
            }
        }
        printf("%s\n", cnt % 3 == 2 ? "dreagonm" : (cnt % 3 == 1 ? "fengxunling" : "BLUESKY007"));
    }
    return 0;
}
```

<!--more-->

## B - Fruit Cake

First I <span class="slang" data-zh="打了个表" data-gloss="dǎle ge biǎo, “made a table”. Here: brute-forcing answers for small inputs to look for a pattern.">made a table</span>, running through every case with $n \in [3, 6]$, and then spotted the pattern; unfortunately I wrote it in a really ugly way, and <span class="slang" data-zh="打表打废掉了" data-gloss="dǎbiǎo dǎ fèi diào le, “made the table and wrecked it”. The table-making attempt was botched and came to nothing.">the table attempt went to waste</span>. In the end I only got 20 points. The intended solution is as follows:

```cpp
// B.cpp
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main()
{
    ll n, m;
    scanf("%lld%lld", &n, &m);
    if (n < m)
        swap(n, m);
    if (m <= 2)
        printf("%lld", n * m);
    else if (m == 3)
        printf("%lld", n + 6 * (n / 6) + 2 * min(n % 6, 3LL));
    else if (m == 4)
    {
        if (n % 6 == 0)
            printf("%lld", 2 * n);
        else if (n % 6 == 1 || n % 6 == 2)
            printf("%lld", 12 * (n / 6) + 4 * (n % 6));
        else if (n % 6 == 3 || n % 6 == 4)
            printf("%lld", 12 * (n / 6) + 4 * 2 + 2 * ((n % 6) - 2));
        else
            printf("%lld", 12 * (n / 6) + 4 * 2 + 2 * 2);
    }
    else
        printf("%lld", (n * m + 1) / 2);
    return 0;
}
```

## C - Good Friends

A typical entry in the <span class="slang" data-zh="正难则反" data-gloss="zhèng nán zé fǎn, “if forward is hard, go in reverse”. A problem-solving maxim: when counting something directly is hard, count its complement instead.">“hard forwards, so go backwards”</span> series. At first I thought this problem was fairly easy, but I still can't really handle digit DP, so <span class="slang" data-zh="全部炸裂" data-gloss="quánbù zhàliè, “all burst apart”. Slang for failing completely; here, the whole attempt fell apart.">everything blew up</span> (tomorrow I need to go practice <span class="slang" data-zh="板子" data-gloss="bǎnzi, “board”. A prepared template implementation of a standard algorithm.">the template</span>). Let the state $dp[i][j]$ count the numbers of length $i$ with $j$ zeros. Just keep a seven from appearing. See the intended solution's code for the details:

```cpp
// C.cpp
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

ll predigits[20], dp[20][4], T, digits[20];

ll solve(ll pos)
{
    if (pos < 1000)
        return 0;
    int tot = 0, x = 0;
    for (; pos; pos /= 10)
        digits[tot++] = pos % 10;
    reverse(digits, digits + tot);
    memset(dp, 0, sizeof(dp));
    dp[1][0] = digits[0] - 1;
    for (int i = 1; i < tot; i++)
    {
        dp[i + 1][0] = dp[i][0] * 9, dp[i + 1][1] = dp[i][0] + dp[i][1] * 9;
        dp[i + 1][2] = dp[i][1] + dp[i][2] * 9, dp[i + 1][3] = dp[i][2] + dp[i][3] * 10;
        dp[i + 1][x] += digits[i] - 1;
        dp[i + 1][x + ((x < 2 && digits[i]) || (x == 2 && digits[i] > 7))]++;
        if (((x < 2 && !digits[i]) || (x == 2 && digits[i] == 7)))
            x++;
    }
    return predigits[tot - 1] + dp[tot][3];
}

int main()
{
    for (ll i = 0, val = 1; i <= 18; i++, val *= 10)
        predigits[i] = solve(val - 1);
    ll ans = 0;
    scanf("%lld", &T);
    while (T--)
    {
        ll lft, rig;
        scanf("%lld%lld", &lft, &rig);
        ans ^= (solve(rig + 1) - solve(lft));
    }
    printf("%lld", ans);
    return 0;
}
```

I think the problems in these few OI weekly contests are not of high quality.
