This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Sylwia Sapkowska
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << "'" << x << "'";}
void __print(const char *x) {cerr << '"' << x << '"';}
void __print(const string &x) {cerr << '"' << x << '"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
typedef pair<int, int> T;
void solve(){
int n, m; cin >> n >> m;
vector a(n+1, vector<char>(m+1));
for (int i = 1; i<=n; i++){
for (int j = 1; j<=m; j++){
cin >> a[i][j];
}
}
auto ok = [&](int i, int j, char c){
return (i >= 1 && j >= 1 && i <= n && j <= m && a[i][j] == c);
};
//0 - obojetne jaki kierunek (oba)
//1 - w prawo
//2 - w gore
int ans = 0;
vector dp(n+m+1, vector<vector<int>>(n+3, vector<int>(3)));
for (int diag = 2; diag <= n+m; diag++){
int curr = 0;
debug(diag);
for (int i = n; i>=1; i--){
int j = diag-i;
if (j < 1 || j > m) continue;
dp[diag][i][1] = max(dp[diag][i+1][1], dp[diag][i+2][0]);
dp[diag][i][2] = max(dp[diag][i+1][2], dp[diag][i+2][0]);
if (ok(i, j, 'G') && ok(i-1, j, 'R') && ok(i+1, j, 'W')){
// dp[diag][i][2] = max(dp[diag][i+1][2] + 1, dp[diag][i+2][0] + 1);
dp[diag][i][2]++;
}
if (ok(i, j, 'G') && ok(i, j-1, 'R') && ok(i, j+1, 'W')){
dp[diag][i][1]++;
}
dp[diag][i][0] = max(dp[diag][i][1], dp[diag][i][2]);
debug(i, j, dp[diag][i][1], dp[diag][i][2]);
curr = max(curr, dp[diag][i][0]);
}
ans += curr;
}
cout << ans << "\n";
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while (t--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |