Submission details
Task:Peli
Sender:Lytsky
Submission time:2026-01-17 16:17:02 +0200
Language:C++ (C++11)
Status:READY
Result:55
Feedback
groupverdictscore
#1ACCEPTED17
#2ACCEPTED38
#30
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3details
#2ACCEPTED0.00 s1, 2, 3details
#3ACCEPTED0.01 s2, 3details
#4--3details
#5ACCEPTED0.01 s2, 3details
#6--3details

Code

#include <bits/stdc++.h>

using namespace std;
int win[2000][2000];

int f(int a, int b) {
	if (win[min(a,b)][max(a,b)] == 1 || win[min(a,b)][max(a,b)] == 2) {
		return win[min(a,b)][max(a,b)];
	} else if (a == 0 || b == 0) {
		return 2;
	} else {
		for (int i = 1; i <= a; i++) {
			if (f(a-i, b) == 1) {
				win[min(a,b)][max(a,b)] = 2;
				//cout << a << "," << b << endl; 
				return 2;
			}
		}
		//cout << a << ", " << b << " " << 1 << endl; 
		for (int i = 1; i <= b; i++) {
			if (f(a, b-i) == 1) {
				win[min(a,b)][max(a,b)] = 2;
				//cout << a << "," << b << endl; 
				return 2;
			}
		}
		//cout << a << ", " << b << " " << 2 << endl; 
		for (int i = 1; i <= min(a,b); i++) {
			if (f(a-i, b-i) == 1) {
				win[min(a,b)][max(a,b)] = 2;
				//cout << a << "," << b << endl; 
				return 2;
			}
		}
		//cout << a << ", " << b << " " << 3 << endl; 
		win[min(a,b)][max(a,b)] = 1;
		return 1;
	}
}

int main() {
	int t, A, B;
	vector<int> answers;
	cin >> t;
	win[0][0] = 1;
	for (int i = 0; i < t; i++) {
		cin >> A >> B;
		answers.push_back(f(A,B));
		//cout << "Mui" << endl; 
	}
	for (auto s : answers) {
		if (s == 1) cout << "second" << endl; 
		else cout << "first" << endl; 
	}
}

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
(empty)

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
(empty)