CSES - Putka Open 2020 – 4/5 - Results
Submission details
Task:Peli
Sender:jubidubi
Submission time:2020-11-08 18:24:35 +0200
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#10.01 s1, 2details
#20.05 s2details

Code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int N = 100;
int n;
int result[N][N][5];

void rec(int a, int b, int c) {
	if (result[a][b][c]) return;
	result[a][b][c] = 2;
	
	if (a > 0 && c != 1) rec(a-1, b, 0);
	if (a + 1 != b && c != 0) rec(a+1, b, 1);
	if (b < n - 1 && c != 3) rec(a, b+1, 2);
	if (b - 1 != a && c != 2) rec(a, b-1, 3);

	bool win = 0;
	if (a > 0 && c != 1 && result[a-1][b][0] == -1) win =  1;
	if (a+1 != b && c != 0 && result[a+1][b][1] == -1) win = 1;
	if (b < n-1 && c != 3 && result[a][b+1][2] == -1) win = 1;
	if (b-1 != a && c != 2 && result[a][b-1][3] == -1) win = 1;

	if (win) result[a][b][c] = 1;
	else result[a][b][c] = -1;
}

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

	int q;
	cin >> q;

	while (q--) {
		for (int a = 0; a < N; ++a) {
			for (int b = 0; b < N; ++b) {
				for (int c = 0; c < 4; ++c) result[a][b][c] = 0;
			}
		}

		string s;
		cin >> s;

		n = s.length();

		result[0][1][3] = -1;
		result[n-1][n][1] = -1;

		int a = -1;
		int b = -1;
		for (int i = 0; i < n; ++i) {
			if (a == -1 && s[i] == 'P') a = i;
			else if (a != -1 && s[i] == 'P') b = i;
		}
		//for (int i = 0; i < 4; ++i) result[a][b][i] = 2;
		rec(a, b, 4);
		if (result[a][b][4] == -1) cout << "2\n";
		else cout << "1\n";
	}
}

Test details

Test 1

Group: 1, 2

Verdict:

input
100
PP.
P......P.
.PP
..P.P.
...

correct output
2
2
2
1
2
...

user output
2
2
2
1
2
...
Truncated

Test 2

Group: 2

Verdict:

input
100
.................................

correct output
2
1
2
1
1
...

user output
2
1
1
1
1
...
Truncated