Submission details
Task:Peli
Sender:rottis
Submission time:2026-01-17 13:40:17 +0200
Language:C++ (C++17)
Status:READY
Result:55
Feedback
groupverdictscore
#1ACCEPTED17
#2ACCEPTED38
#30
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3details
#2ACCEPTED0.01 s1, 2, 3details
#3ACCEPTED0.65 s2, 3details
#40.65 s3details
#5ACCEPTED0.66 s2, 3details
#60.65 s3details

Code

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int n;

int ans[2001][2001];

const int SELF = 1;
const int OTHER = 2;

inline int mini(int a, int b) {
    return a < b ? a : b;
}

inline int maxi(int a, int b) {
    return a > b ? a : b;
}

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);

    cin >> n;

    for (int a = 0; a < n; a++) {
        for (int b = a; b < n; b++) {
            if (a == 0 || b == 0) ans[a][b] = SELF;
            else if (a == b) ans[a][b] = SELF;
            else if (a == 1 && b == 2) ans[a][b] = OTHER;
            else {
                // if we can jump to an OTHER position, this is a SELF position
                for (int na = 0; na < a; na++) {
                    int na1 = mini(na, b);
                    int nb1 = maxi(na, b);
                    if (ans[na1][nb1] == OTHER) {
                        ans[a][b] = SELF;
                        goto next;
                    }
                }

                for (int nb = 0; nb < b; nb++) {
                    int na1 = mini(a, nb);
                    int nb1 = maxi(a, nb);
                    if (ans[na1][nb1] == OTHER) {
                        ans[a][b] = SELF;
                        goto next;
                    }
                }

                for (int k = 1; k <= mini(a, b); k++) {
                    if (ans[a-k][b-k] == OTHER) {
                        ans[a][b] = SELF;
                        goto next;
                    }
                }

                ans[a][b] = OTHER;
            }
            next: continue;
        }
    }

    // tilanne 1, 1 on voittava sille kuka pelaa seuraavaksi
    // kaikki tilanteet n, n myös voittavia
    // tilanteet 1, 2 ja 2, 1 ovat häviäviä
    // n, 2 pakottaa voittavan tilanteen (n >= 3) jos tekee tilanteen 1, 2
    // n, 3 pakottaa voittavan tilanteen (n >= 3): 4, 1
    


    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;

        if (b < a) swap(a, b);
        
        cout << (ans[a][b] == SELF ? "first\n" : "second\n");
    }

    return 0;
}

Test details

Test 1 (public)

Group: 1, 2, 3

Verdict: ACCEPTED

input
5
2 2
1 2
3 2
4 3
...

correct output
first
second
first
first
second

user output
first
second
first
first
second

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
100
1 1
1 2
1 3
1 4
...

correct output
first
second
first
first
first
...

user output
first
second
first
first
first
...

Test 3

Group: 2, 3

Verdict: ACCEPTED

input
1000
82 14
91 84
13 97
92 23
...

correct output
first
first
first
first
first
...

user output
first
first
first
first
first
...

Test 4

Group: 3

Verdict:

input
1000
1630 271
1812 1671
254 1938
1827 443
...

correct output
first
first
first
first
first
...

user output
second
second
second
second
second
...

Feedback: Incorrect character on line 1 col 1: expected "first", got "second"

Test 5

Group: 2, 3

Verdict: ACCEPTED

input
1000
36 14
79 81
93 82
32 1
...

correct output
first
first
first
first
first
...

user output
first
first
first
first
first
...

Test 6

Group: 3

Verdict:

input
1000
486 300
899 1455
879 543
40 65
...

correct output
second
second
second
second
second
...

user output
second
second
second
second
second
...

Feedback: Incorrect character on line 9 col 1: expected "first", got "second"