CSES - Putka Open 2020 – 4/5 - Results
Submission details
Task:Peli
Sender:ArktinenKarpalo
Submission time:2020-11-06 19:18:35 +0200
Language:C++ (C++17)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED35
#2ACCEPTED65
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.05 s2details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:48:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0; i<s.size(); i++) {
                ~^~~~~~~~~
input/code.cpp:62:29: warning: 'p2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   cout << lol(p1, p2, 4) << "\n";
                             ^~~~

Code

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define M 1000000007
 
using namespace std;

int d[111][111][11];
int n;

int lol(int p1, int p2, int pt) {
	if(p1 == p2 || p1 == -1 || p2 == n)
		return 1;
	if(d[p1][p2][pt] == 1)
		return 1;
	else if(d[p1][p2][pt] == 2)
		return 2;
	else if(d[p1][p2][pt] == -1)
		return 2;
	d[p1][p2][pt] = -1;
	bool res = false;
	if(pt != 0 && lol(p1+1, p2, 1) == 2)
		res = true;
	if(pt != 1 && lol(p1-1, p2, 0) == 2)
		res = true;
	if(pt != 2 && lol(p1, p2+1, 3) == 2)
		res = true;
	if(pt != 3 && lol(p1, p2-1, 2) == 2)
		res = true;
	if(res)
		d[p1][p2][pt] = 1;
	else
		d[p1][p2][pt] = 2;
	return d[p1][p2][pt];
}
 
int main() {
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio();
	int t;
	cin >> t;
	for(int g=0; g<t; g++) {
		string s = "";
		cin >> s;
		int p1 = -1;
		int p2;
		for(int i=0; i<s.size(); i++) {
			if(s[i] == 'P') {
				if(p1 == -1)
					p1 = i;
				else
					p2 = i;
			}
		}
		n = s.size();
		for(int i=0; i<n; i++)
		for(int ii=0; ii<n; ii++)
			for(int j=0; j<=4; j++) {
			d[i][ii][j] = 0;
			}
		cout << lol(p1, p2, 4) << "\n";
	}
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

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: ACCEPTED

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

correct output
2
1
2
1
1
...

user output
2
1
2
1
1
...
Truncated