QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#565878#9308. World CupshumianWA 0ms3608kbC++232.1kb2024-09-15 22:29:282024-09-15 22:29:30

Judging History

你现在查看的是最新测评结果

  • [2024-09-15 22:29:30]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3608kb
  • [2024-09-15 22:29:28]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;

void solve() {
    vector<vector<int>> groups(8);
    int mark;

    // 输入小组赛数据
    for (int i = 0; i < 8; ++i) {
        vector<int> nums(4);
        for (int j = 0; j < 4; ++j) {
            cin >> nums[j];
            if (i == 0 && j == 0) mark = nums[j]; // 记录中国队的实力
        }
        sort(nums.rbegin(), nums.rend());
        groups[i] = nums;
    }

    // 确定小组前两名
    vector<int> qualified;
    bool chineseTeamQualified = false;

    for (const auto& group : groups) {
        qualified.push_back(group[0]); // 第一名
        qualified.push_back(group[1]); // 第二名
        if (group[0] == mark || group[1] == mark) {
            chineseTeamQualified = true; // 中国队晋级
        }
    }

    if (!chineseTeamQualified) {
        cout << 32 << endl; // 中国队未晋级
        return;
    }

    // 淘汰赛
    vector<int> knockout(16);
    for (int i = 0; i < 8; ++i) {
        knockout[i * 2] = groups[i][0]; // 第一名
        knockout[i * 2 + 1] = groups[i][1]; // 第二名
    }

    int round = 16;

    while (round > 1) {
        vector<int> nextRound;
        bool markInRound = false;

        for (int i = 0; i < knockout.size(); i += 2) {
            int winner = max(knockout[i], knockout[i + 1]);
            if (winner == mark) {
                markInRound = true;
            }
            nextRound.push_back(winner);
        }
        knockout = nextRound;

        if (!markInRound) {
            cout << round << endl; // 输出当前轮次
            return;
        }
        
        round /= 2; // 每轮减半
    }

    // 最后两队比较
    int final1 = knockout[0];
    int final2 = knockout[1];

    if (final1 == mark || final2 == mark) {
        cout << (final1 == mark ? 1 : 2) << endl; // 1: 决赛, 2: 亚军
    } else {
        cout << 4 << endl; // 半决赛
    }
}

signed main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3548kb

input:

1
32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3608kb

input:

32
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
2 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
3 1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
4 1 2 3 5 6 7 8 9 10 11 12 13 14 15 ...

output:

32
32
16
8
8
8
8
4
4
4
4
4
4
4
4
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1

result:

wrong answer 4th numbers differ - expected: '16', found: '8'