제출 #679449

#제출 시각아이디문제언어결과실행 시간메모리
679449anhduc2701Dango Maker (JOI18_dango_maker)C++17
33 / 100
21 ms39292 KiB
/* #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimize("unroll-loops") */ #include<bits/stdc++.h> #define int long long #define all(x) x.begin(), x.end() #define len(x) ll(x.size()) #define eb emplace_back #define PI 3.14159265359 #define fi first #define se second #define mp make_pair #define pb push_back #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) #define BIT(x,i) (1&((x)>>(i))) #define MASK(x) (1LL<<(x)) #define task "tnc" using namespace std; typedef long long ll; const ll INF=1e18; const int maxn=1e6+5; const int mod=1e9+7; const int mo=998244353; using pi=pair<ll,ll>; using vi=vector<ll>; using pii=pair<pair<ll,ll>,ll>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n,m; char a[3005][3005]; int dp[2][3005][3005]; bool check[2][3005][2005]; bool check1(int i,int j){ return a[i][j-2]=='R' && a[i][j-1]=='G' && a[i][j]=='W'; } bool check2(int i,int j){ return a[i-2][j]=='R' && a[i-1][j]=='G' && a[i][j]=='W'; } signed main() { cin.tie(0),cout.tie(0)->sync_with_stdio(0); //freopen(task".inp" , "r" , stdin); //freopen(task".out" , "w" , stdout); cin>>n>>m; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; } } for(int i=1;i<=n;i++){ for(int j=3;j<=m;j++){ check[0][i][j]=check1(i,j); } } for(int i=3;i<=n;i++){ for(int j=1;j<=m;j++){ check[1][i][j]=check2(i,j); } } /* for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ dp[1][i][j]=dp[1][i-1][j+1]+check[1][i][j]; if(i>=3)dp[1][i][j]=max(dp[1][i][j],dp[0][i-3][j+3]+check[1][i][j]); dp[0][i][j]=max(dp[1][i][j],dp[0][i-1][j+1]+check[0][i][j]); } } int ans=0; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if((j==1|| i==n)){ ans+=dp[0][i][j]; } } } */ for(int i = 1; i<= n; i++) { for(int j = 1; j<= m; j++) { dp[1][i][j] = check[1][i][j]+dp[1][i-1][j+1]; if(i-3>=0) dp[1][i][j] = max(dp[1][i][j], dp[0][i-3][j+3]+check[1][i][j]); dp[0][i][j] = max(dp[0][i-1][j+1]+check[0][i][j],dp[1][i][j]); //cout << i << " " << j << " " << dp[0][i][j] << " " << dp[1][i][j] << " " << chk[0][i][j] << " " << chk[1][i][j] << " " << dp[0][i-1][j+1]<< "\n"; } } ll ans = 0; for(int i = 1; i<= n; i++) { for(int j = 1 ; j<= m; j++) { if(j==1||i==n) { ans += dp[0][i][j]; } //cout << i << " " << j << " " << dp[0][i][j] << " " << dp[1][i][j] << " " << chk[0][i][j] << " " << chk[1][i][j] << " " << dp[0][i-1][j+1]<< "\n"; } } cout<<ans<<" "; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...