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

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:27:12: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int a, b;
            ^
input/code.cpp:27:9: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int a, b;
         ^

Code

#include <bits/stdc++.h>
using namespace std;
int n;
bool dp[100][100][2][2];
bool dps[100][100][2][2];
bool f(int a, int b, int c, int d) {
  if (dps[a][b][c][d]) return dp[a][b][c][d];
  dps[a][b][c][d] = 1;
  bool tor = 0;
  if (a != n-1 && a+1 != b && !(c == 0 && d == 0) && !f(a+1, b, 0, 1)) tor = 1;
  if (a != 0 && a-1 != b && !(c == 0 && d == 1) && !f(a-1, b, 0, 0)) tor = 1;
  if (b != n-1 && b+1 != a && !(c == 1 && d == 0) && !f(a, b+1, 1, 1)) tor = 1;
  if (b != n-1 && b-1 != a && !(c == 1 && d == 1) && !f(a, b-1, 1, 0)) tor = 1;
  dp[a][b][c][d] = tor;
  return tor;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  for (int Ti = 0; Ti < T; ++Ti) {
    string s;
    cin >> s;
    n = s.size();
    bool af = 0;
    int a, b;
    for (int i = 0; i < n; ++i) {
      if (s[i] == 'P') {
        if (!af) a = i;
        else b = i;
        af = 1;
      }
    }
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j)
    for (int c = 0; c < 2; ++c) for (int d = 0; d < 2; ++d) dps[i][j][c][d] = 0;
    if (f(a, b, 0, 1) || f(a, b, 0, 0)) cout << "1\n";
    else cout << "2\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
1
1
2
...
Truncated

Test 2

Group: 2

Verdict:

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

correct output
2
1
2
1
1
...

user output
2
1
2
1
1
...
Truncated