题目 › usaco-1548

Hoof, Paper, Scissors Triples

USACO 2026 First · 铂金组 · 2026-01 · L4 顶尖 · C++17 · 时限 2 秒 · 测试点等分

查看原题跳到结果

题面

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

You have probably heard of the game "Rock, Paper, Scissors". The cows like to play a similar game they call "Hoof, Paper, Scissors".

The rules of "Hoof, Paper, Scissors" are simple. Two cows play against each other. They both count to three and then each simultaneously makes a gesture that represents either a hoof, a piece of paper, or a pair of scissors. Hoof beats scissors (since a hoof can smash a pair of scissors), scissors beats paper (since scissors can cut paper), and paper beats hoof (since the hoof can get a papercut). For example, if the first cow makes a "hoof" gesture and the second a "paper" gesture, then the second cow wins. Of course, it is also possible to tie, if both cows make the same gesture.

Now there are $N$ ($3\le N\le 2\cdot 10^5$) cows who want to play hoof paper scissors, and they each independently have a strategy of drawing from some fixed distribution. In particular, the $i$th cow's strategy is to play hoof, paper, or scissors with probabilities $\left(\frac{h_i}{h_i+p_i+s_i}, \frac{p_i}{h_i+p_i+s_i}, \frac{s_i}{h_i+p_i+s_i} \right)$, respectively.

How many distinct triples of cows (A,B,C) are there such that A beats B on average, B beats C on average, and C beats A on average? We consider two triples the same if one equals the other up to a cyclic shift.

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

The first line contains $T$ ($1\le T\le 5\cdot 10^4$), the number of independent tests. Each test is specified in the following format:

The first line contains $N$.

The next $N$ lines each contain three non-negative integers $h_i$, $p_i$, $s_i$ ($0\le h_i,p_i,s_i\le 10^9, h_i+p_i+s_i>0$).

It is guaranteed that the sum of $N$ over all tests does not exceed

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

Output the number of triples.

Note: The large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).

SAMPLE INPUT:

2
4
1 0 0
1 0 0
0 1 0
0 0 1
10
20410069 21445597 257862632
114108992 287498302 113278897
607994331 143503714 631122722
337497016 270153603 320256324
633717786 631078144 493265815
202783212 612643590 560838949
713379081 42803063 58996167
293262767 470686180 220651551
656404313 408797935 345461691
959196297 827681918 591519393

SAMPLE OUTPUT:

2
32

For the first test, there are two triples: $(1, 3, 4)$ and $(2, 3, 4)$.

SCORING:

  • Inputs 2-3: $N\le 10$
  • Inputs 4-9: $N \le 7500$, the sum of $N$ over all tests does not exceed $10^4$
  • Inputs 10-21: No additional constraints.

Problem credits: Richard Qi

结果

Kimi K3.1 ProKimi

max

2/3

解出的采样 ↑

  • 85.7采样 1 · 超时
  • 100采样 2 · 解出
  • 100采样 3 · 解出
  • 18.0k平均输出 token(含思考) ↓
  • 26.4输出速度 tokens/s ↑
  • 568 秒延迟 ↓
  • 2.30×CPU 时间 / 官方解 ↓
  • 更差 1、同阶 2时间复杂度(相对官方解)

Kimi K3.1 Pro(high)Kimi high

high

1/3

解出的采样 ↑

  • 85.7采样 1 · 超时
  • 100采样 2 · 解出
  • 4.8采样 3 · 答案错误
  • 13.7k平均输出 token(含思考) ↓
  • 25.8输出速度 tokens/s ↑
  • 540 秒延迟 ↓
  • 2.81×CPU 时间 / 官方解 ↓
  • 更差 1、同阶 1时间复杂度(相对官方解)

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

3/3

解出的采样 ↑

  • 100采样 1 · 解出
  • 100采样 2 · 解出
  • 100采样 3 · 解出
  • 32.2k平均输出 token(含思考) ↓
  • 134.6输出速度 tokens/s ↑
  • 248 秒延迟 ↓
  • 1.24×CPU 时间 / 官方解 ↓
  • 同阶 3时间复杂度(相对官方解)

MiniMax M3.1 FlashMiniMax

auto(max)

3/3

解出的采样 ↑

  • 100采样 1 · 解出
  • 100采样 2 · 解出
  • 100采样 3 · 解出
  • 37.9k平均输出 token(含思考) ↓
  • 88.2输出速度 tokens/s ↑
  • 422 秒延迟 ↓
  • 1.06×CPU 时间 / 官方解 ↓
  • 同阶 3时间复杂度(相对官方解)

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

代码

Kimi K3.1 Pro · 采样 1 · 119 行
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i128 = __int128_t;

struct Vec {
    ll x, y;
};

static inline i128 cross(const Vec &a, const Vec &b) {
    return (i128)a.x * b.y - (i128)a.y * b.x;
}

static inline i128 dot(const Vec &a, const Vec &b) {
    return (i128)a.x * b.x + (i128)a.y * b.y;
}

static inline int half(const Vec &a) {
    return (a.y > 0 || (a.y == 0 && a.x > 0)) ? 0 : 1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        int N;
        cin >> N;

        vector<Vec> v;
        v.reserve(N);

        for (int i = 0; i < N; i++) {
            ll h, p, s;
            cin >> h >> p >> s;
            Vec a{p - s, h - s};
            if (a.x != 0 || a.y != 0) v.push_back(a);
        }

        int n = (int)v.size();
        if (n < 3) {
            cout << 0 << '\n';
            continue;
        }

        sort(v.begin(), v.end(), [](const Vec &a, const Vec &b) {
            if (half(a) != half(b)) return half(a) < half(b);
            return cross(a, b) > 0;
        });

        vector<Vec> doubled(2 * n);
        for (int i = 0; i < 2 * n; i++) doubled[i] = v[i % n];

        // q[i]: first direction at least pi radians after v[i].
        // r[i]: first direction strictly more than pi radians after v[i].
        vector<int> q(n), r(n);
        int ptr = 1;

        for (int i = 0; i < n; i++) {
            ptr = max(ptr, i + 1);
            int lim = i + n;

            while (ptr < lim) {
                i128 cr = cross(v[i], doubled[ptr]);
                if (cr > 0 || (cr == 0 && dot(v[i], doubled[ptr]) > 0)) {
                    ptr++;
                } else {
                    break;
                }
            }

            q[i] = ptr;
            int z = ptr;
            while (z < lim && cross(v[i], doubled[z]) == 0) z++;
            r[i] = z;
        }

        vector<int> sameEnd(n);
        for (int l = 0; l < n; ) {
            int rr = l + 1;
            while (rr < n && cross(v[l], v[rr]) == 0) rr++;
            for (int i = l; i < rr; i++) sameEnd[i] = rr;
            l = rr;
        }

        vector<int> R(n);
        vector<ll> pref(n + 1, 0);
        for (int i = 0; i < n; i++) {
            R[i] = min(q[i], n);
            pref[i + 1] = pref[i] + R[i];
        }

        ll answer = 0;

        for (int i = 0; i < n; i++) {
            int L = min(r[i], n);
            if (L >= n) continue;

            int lo = sameEnd[i];
            int hi = min(q[i], n);
            if (lo >= hi) continue;

            int start = lower_bound(R.begin() + lo, R.begin() + hi, L + 1)
                        - R.begin();

            if (start < hi) {
                answer += pref[hi] - pref[start]
                          - (ll)(hi - start) * L;
            }
        }

        cout << answer << '\n';
    }

    return 0;
}