This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 10;
vector<vector<bool>> vis;
string s[MX];
int N, M;
map<vector<vector<bool>> , int > memo;
int f() {
if(memo.count(vis)) return memo[vis];
int res = 0;
for(int i = 0; i < N; i++) {
for(int j = 0; j + 2 < M; j++) {
if(!vis[i][j] && !vis[i][j + 1] && !vis[i][j + 2]
&& s[i][j] == 'R' && s[i][j + 1] == 'G' && s[i][j + 2] == 'W') {
vis[i][j] = vis[i][j + 1] = vis[i][j + 2] = 1;
res = max(res, f() + 1);
vis[i][j] = vis[i][j + 1] = vis[i][j + 2] = 0;
}
}
}
for(int j = 0; j < M; j++) {
for(int i = 0; i + 2 < N; i++) {
if(!vis[i][j] && !vis[i + 1][j] && !vis[i + 2][j]
&& s[i][j] == 'R' && s[i + 1][j] == 'G' && s[i + 2][j] == 'W') {
vis[i][j] = vis[i + 1][j] = vis[i + 2][j] = 1;
res = max(res, f() + 1);
vis[i][j] = vis[i + 1][j] = vis[i + 2][j] = 0;
}
}
}
return memo[vis] = res;
}
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> N >> M;
vis = vector<vector<bool>> (N, vector<bool>(M));
for(int i = 0; i < N; i++) cin >> s[i];
cout << f() << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |