题目 › usaco-1515

Hoof Paper Scissors Minus One

USACO 2025 US Open · 铜组 · 2025-03 · L1 基础 · Python 3.11 · 时限 6 秒 · 测试点等分

查看原题跳到结果

题面

来源:USACO 官网。模型收到的是同一份题面的文字。

**Note: The time limit for this problem is 3s, 1.5x the default.**

In a game of Hoof Paper Scissors, Bessie and Elsie can put out one of $N$ ($1 \leq N \leq 3000$) different hoof symbols labeled $1\dots N$, each corresponding to a different material. There is a complicated chart of how the different materials interact with one another, and based on that chart, either:

  • One symbol wins and the other loses.
  • The symbols draw against each other.

Hoof Paper Scissors Minus One works similarly, except Bessie and Elsie can each put out two symbols, one with each hoof. After observing all four symbols that they have all put out, they each choose one of their two symbols to play. The outcome is decided based on normal Hoof Paper Scissor conventions.

Given the $M$ ($1 \leq M \leq 3000$) symbol combinations that Elsie plans to make across each game, Bessie wants to know how many different symbol combinations would result in a guaranteed win against Elsie. A symbol combination is defined as an ordered pair $(L,R)$ where $L$ is the symbol the cow plays with her left hoof and $R$ is the symbol the cow plays with her right hoof. Can you compute this for each game?

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains two space-separated integers $N$ and $M$ representing the number of hoof symbols and the number of games that Bessie and Elsie play.

Out of the following $N$ lines of input, the $i$th line consists of $i$ characters $a_{i,1}a_{i,2}\ldots a_{i,i}$ where each $a_{i,j} \in \{\texttt D,\texttt W,\texttt L\}$. If $a_{i,j} = \texttt D$, then symbol $i$ draws against symbol $j$. If $a_{i,j} = \texttt W$, then symbol $i$ wins against symbol $j$. If $a_{i,j} = \texttt L$, then symbol $i$ loses against symbol $j$. It is guaranteed that $a_{i,i} = \texttt D$.

The next $M$ lines contain two space separated integers $s_1$ and $s_2$ where $1 \leq s_1,s_2 \leq N$. This represents Elsie's symbol combination for that game.

OUTPUT FORMAT (print output to the terminal / stdout):

Output $M$ lines where the $i$-th line contains the number of symbol combinations guaranteeing that Bessie can beat Elsie in the $i$-th game.

SAMPLE INPUT:

3 3
D
WD
LWD
1 2
2 3
1 1

SAMPLE OUTPUT:

0
0
5
In this example, this corresponds to the original Hoof Paper Scissors and we can let Hoof=1, Paper=2, and Scissors=3. Paper beats Hoof, Hoof beats Scissors, and Scissors beats Paper. There is no way for Bessie to guarantee a win against the combinations of Hoof+Paper or Paper+Scissors. However, if Elsie plays Hoof+Hoof, Bessie can counteract with any of the following combinations.

  • Paper+Paper
  • Paper+Scissors
  • Paper+Hoof
  • Hoof+Paper
  • Scissors+Paper

If Bessie plays any of these combinations, she can guarantee that she wins by putting forward Paper.

SCORING:

  • Inputs 2-6: $N,M\le 100$
  • Inputs 7-12: No additional constraints.

Problem credits: Suhas Nagar

结果

Kimi K3.1 ProKimi

auto(max)

1/1

解出的采样 ↑

  • 100采样 1 · 解出
  • 4.1k平均输出 token(含思考) ↓
  • 30.3输出速度 tokens/s ↑
  • 136 秒延迟 ↓
  • 0.19×CPU 时间 / 官方解 ↓
  • 同阶时间复杂度(相对官方解)
  • 4Pylint 问题 ↓
  • 8.33Pylint 得分 ↑
  • 7圈复杂度 ↓
  • 76.2可维护性指数 ↑

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

1/1

解出的采样 ↑

  • 100采样 1 · 解出
  • 4.3k平均输出 token(含思考) ↓
  • 200.8输出速度 tokens/s ↑
  • 22 秒延迟 ↓
  • 0.23×CPU 时间 / 官方解 ↓
  • 不可测时间复杂度(相对官方解)
  • 3Pylint 问题 ↓
  • 8.97Pylint 得分 ↑
  • 8圈复杂度 ↓
  • 72.5可维护性指数 ↑

MiniMax M3.1 FlashMiniMax

auto(max)

1/1

解出的采样 ↑

  • 100采样 1 · 解出
  • 13.2k平均输出 token(含思考) ↓
  • 175.2输出速度 tokens/s ↑
  • 76 秒延迟 ↓
  • 0.15×CPU 时间 / 官方解 ↓
  • 更优时间复杂度(相对官方解)
  • 5Pylint 问题 ↓
  • 8.78Pylint 得分 ↑
  • 10圈复杂度 ↓
  • 64.7可维护性指数 ↑

↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。

代码

Kimi K3.1 Pro · 采样 1 · 37 行
import sys


def main():
    input = sys.stdin.buffer.readline
    n, m = map(int, input().split())

    # wins[j] is a bitmask of all symbols that beat symbol j.
    wins = [0] * n
    bits = [1 << i for i in range(n)]

    for i in range(n):
        row = input().strip()
        for j, result in enumerate(row):
            if result == 87:  # 'W': symbol i+1 beats symbol j+1
                wins[j] |= bits[i]
            elif result == 76:  # 'L': symbol j+1 beats symbol i+1
                wins[i] |= bits[j]

    answers = []
    total = n * n

    for _ in range(m):
        a, b = map(int, input().split())
        both = wins[a - 1] & wins[b - 1]
        k = both.bit_count()

        # A pair guarantees a win iff at least one of its two symbols
        # beats both of Elsie's possible symbols.
        bad = (n - k) * (n - k)
        answers.append(str(total - bad))

    sys.stdout.write("\n".join(answers))


if __name__ == "__main__":
    main()