이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "/home/trucmai/.vim/tools.h"
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define debug(x...)
#endif
void open(){
if(fopen("i.inp","r")){
freopen("i.inp","r",stdin);
freopen("o.out","w",stdout);
}
}
#define ll long long
#define all(a) (a).begin(), (a).end()
#define vi vector<ll>
#define pi pair<ll,ll>
#define pii pair<ll,pair<ll,ll>>
#define fi first
#define se second
#define gcd __gcd
#define mset(a,v) memset(a, v, sizeof(a))
#define endl '\n'
#define spc " "
const int MN = 3e3 + 5,LOG = 27;
const ll MOD = 1e9 + 7,INF = 1e9;
ll n,m,dp[MN][MN][3],dango[MN][MN][3];
char a[MN][MN];
void solve(){
cin>>n>>m;
for(ll i = 1;i <= n;++i)
for(ll j = 1;j <= m;++j)
cin>>a[i][j];
for(ll i = 1;i <= n;++i)
for(ll j = 1;j <= m;++j){
if(a[i-1][j] == 'R' && a[i][j] == 'G' && a[i+1][j] == 'W') dango[i][j][1] = 1;
if(a[i][j-1] == 'R' && a[i][j] == 'G' && a[i][j+1] == 'W') dango[i][j][2] = 1;
}
for(ll i = 1;i <= n;++i){
for(ll j = 1;j <= m;++j){
dp[i][j][0] += max({dp[i-1][j+1][0],dp[i-1][j+1][1],dp[i-1][j+1][2]});
dp[i][j][1] += max({dp[i-1][j+1][0],dp[i-1][j+1][1]}) + dango[i][j][1];
dp[i][j][2] += max({dp[i-1][j+1][0],dp[i-1][j+1][2]}) + dango[i][j][2];
}
}
ll res = 0;
for(ll i = 1;i <= n;++i)
res += max({dp[i][1][0],dp[i][1][1],dp[i][1][2]});
for(ll i = 2;i <= m;++i)
res += max({dp[n][i][0],dp[n][i][1],dp[n][i][2]});
cout<<res<<endl;
}
signed main(){
cin.tie(0) -> sync_with_stdio(0);
open();
ll t = 1; //cin>>t;
while(t--) solve();
#ifdef LOCAL
cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
컴파일 시 표준 에러 (stderr) 메시지
dango_maker.cpp: In function 'void open()':
dango_maker.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | freopen("i.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
dango_maker.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | freopen("o.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |