이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,fma")
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
typedef tree <pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int inf = 2e9;
const int N = 3e3 + 15;
int n, m, a[N][N], dp[N][N][3];
int ans[N * N];
inline int check(int a, int b, int c) {
return a == 1 && b == 2 && c == 3;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
char c;
cin >> c;
if(c == 'R')
a[i][j] = 1;
else if(c == 'G')
a[i][j] = 2;
else
a[i][j] = 3;
}
}
for(int i = 1; i <= n; ++i) {
for(int j = m; j; --j) {
for(int k = 0; k < 3; ++k)
dp[i][j][0] = max(dp[i][j][0], dp[i-1][j+1][k]);
dp[i][j][1] = check(a[i-1][j], a[i][j], a[i+1][j]) + max(dp[i-1][j+1][0], dp[i-1][j+1][1]);
dp[i][j][2] = check(a[i][j-1], a[i][j], a[i][j+1]) + max(dp[i-1][j+1][0], dp[i-1][j+1][2]);
for(int k = 0; k < 3; ++k)
ans[i+j] = max(ans[i+j], dp[i][j][k]);
}
}
int x = 0;
for(int i = 0; i <= n + m; ++i)
x += ans[i];
cout << x;
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... |