# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
201345 | abil | Dango Maker (JOI18_dango_maker) | C++14 | 6 ms | 504 KiB |
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>
#define fr first
#define sc second
#define pb push_back
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
//#define int long long
using namespace std;
const int N = (3e3 + 12);
const int mod = (1e9 + 7);
const int inf = (1e9 + 7);
int dp[N][N], cnt[N][N];
char a[N][N];
main(){
int n, m;
scanf("%d%d", &n, &m);
for(int i = 1;i <= n; i++){
for(int j = 1;j <= m; j++){
scanf(" %c", &a[i][j]);
}
}
for(int i = 1;i <= n; i++){
for(int j = 1;j <= m; j++){
int x = 0, y = 0;
if(j >= 3){
if(a[i][j] == 'W' && a[i][j - 1] == 'G' && a[i][j - 2] == 'R'){
y++;
}
}
if(i >= 3){
if(a[i][j] == 'W' && a[i - 1][j] == 'G' && a[i - 2][j] == 'R'){
x++;
}
}
if((dp[i - 1][j] + x + dp[i][j - 1] - dp[i - 1][j - 1]) >= (dp[i][j - 1] + y + dp[i - 1][j] - dp[i - 1][j - 1])){
dp[i][j] = (dp[i - 1][j] + x + dp[i][j - 1]) - dp[i - 1][j - 1];
if(x){
cnt[i][j]--;
cnt[i - 1][j]--;
cnt[i - 2][j]--;
}
}
else{
dp[i][j] = (dp[i][j - 1] + y + dp[i - 1][j]) - dp[i - 1][j - 1];
if(y){
cnt[i][j]--;
cnt[i][j - 1]--;
cnt[i][j - 2]--;
}
}
}
}
for(int i = 1;i <= n; i++){
for(int j = 1;j <= m; j++){
if(cnt[i][j] < 0){
dp[n][m] += cnt[i][j] + 1;
}
}
}
cout << dp[n][m];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |