Submission #609490

# Submission time Handle Problem Language Result Execution time Memory
609490 2022-07-27T16:19:36 Z urosk Dango Maker (JOI18_dango_maker) C++14
100 / 100
400 ms 98352 KB
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll int
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);

using namespace std;
using namespace __gnu_pbds;
/*
ll add(ll x,ll y){
    x+=y;
    if(x<0){
        x%=mod;
        x+=mod;
    }else{
        if(x>=mod) x%=mod;
    }
    return x;
}
ll mul(ll a,ll b){
	ll ans = (a*b)%mod;
	if(ans<0) ans+=mod;
	return ans;
}
*/
typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
    return uniform_int_distribution<ll>(l,r)(rng);
}
#define maxn 6005
ll n,m;
ll a[maxn][maxn];
ll dp[maxn][2][2];
bool moe[maxn][maxn][2];
bool okright(ll i,ll j){
    if(j+2>m) return 0;
    return (a[i][j]==1)&&(a[i][j+1]==2)&&(a[i][j+2]==3);
}
bool okdown(ll i,ll j){
    if(i+2>n) return 0;
    return (a[i][j]==1)&&(a[i+1][j]==2)&&(a[i+2][j]==3);
}
ll ans = 0;
int main(){
	daj_mi_malo_vremena
    cin >> n >> m;
    for(ll i = 1;i<=n;i++){
        string s; cin >> s;
        for(ll j = 1;j<=m;j++){
            if(s[j-1]=='R') a[i][j] = 1;
            if(s[j-1]=='G') a[i][j] = 2;
            if(s[j-1]=='W') a[i][j] = 3;
        }
    }
    for(ll i = 1;i<=n;i++){
        for(ll j = 1;j<=m;j++){
            moe[i+j][i][0] = okright(i,j);
            moe[i+j][i][1] = okdown(i,j);
        }
    }
    for(ll z = 2;z<=n+m;z++){
        for(ll i = 0;i<=n;i++) for(ll x = 0;x<=1;x++) for(ll y = 0;y<=1;y++) dp[i][x][y] = -llinf;
        dp[0][0][0] = 0;
        for(ll i = 1;i<=n;i++){
            for(ll x = 0;x<=1;x++){
                for(ll y = 0;y<=1;y++){
                    dp[i][0][x] = max(dp[i][0][x],dp[i-1][x][y]);
                    if(moe[z][i][0]&&x==0&&y==0) dp[i][0][x] = max(dp[i][0][x],dp[i-1][x][y]+1);
                    if(moe[z][i][1]) dp[i][1][x] = max(dp[i][1][x],dp[i-1][x][y]+1);
                }
            }
        }
        ll cur = 0;
        for(ll x = 0;x<=1;x++) for(ll y = 0;y<=1;y++) cur = max(cur,dp[n][x][y]);
        ans+=cur;
    }
    cout<<ans<<endl;
	return 0;
}
/*
5 5
RGRGW
GRRGW
WGGWR
RWRGW
RGWGW
4 4
RGWR
GRRG
WGGW
WWWR
3 4
RGWR
GRGG
RGWW
*/

Compilation message

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:77:92: warning: overflow in conversion from 'long long int' to 'int' changes value from '-100000000000000000' to '-1569325056' [-Woverflow]
   77 |         for(ll i = 0;i<=n;i++) for(ll x = 0;x<=1;x++) for(ll y = 0;y<=1;y++) dp[i][x][y] = -llinf;
      |                                                                                            ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 328 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 328 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 456 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 1 ms 468 KB Output is correct
52 Correct 1 ms 468 KB Output is correct
53 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 328 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 456 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 1 ms 468 KB Output is correct
52 Correct 1 ms 468 KB Output is correct
53 Correct 1 ms 464 KB Output is correct
54 Correct 6 ms 12372 KB Output is correct
55 Correct 110 ms 24580 KB Output is correct
56 Correct 6 ms 12444 KB Output is correct
57 Correct 43 ms 16616 KB Output is correct
58 Correct 43 ms 18432 KB Output is correct
59 Correct 377 ms 89460 KB Output is correct
60 Correct 392 ms 98104 KB Output is correct
61 Correct 374 ms 98196 KB Output is correct
62 Correct 5 ms 11604 KB Output is correct
63 Correct 400 ms 95600 KB Output is correct
64 Correct 305 ms 98192 KB Output is correct
65 Correct 305 ms 98196 KB Output is correct
66 Correct 289 ms 98352 KB Output is correct
67 Correct 276 ms 98196 KB Output is correct
68 Correct 293 ms 98192 KB Output is correct
69 Correct 305 ms 98108 KB Output is correct
70 Correct 36 ms 19248 KB Output is correct
71 Correct 37 ms 19288 KB Output is correct
72 Correct 35 ms 19224 KB Output is correct
73 Correct 36 ms 19184 KB Output is correct
74 Correct 36 ms 19276 KB Output is correct
75 Correct 39 ms 19256 KB Output is correct
76 Correct 35 ms 19176 KB Output is correct
77 Correct 34 ms 19284 KB Output is correct
78 Correct 35 ms 19280 KB Output is correct
79 Correct 33 ms 19284 KB Output is correct
80 Correct 44 ms 19284 KB Output is correct
81 Correct 37 ms 19220 KB Output is correct
82 Correct 35 ms 19200 KB Output is correct
83 Correct 53 ms 19176 KB Output is correct
84 Correct 36 ms 19292 KB Output is correct
85 Correct 37 ms 19284 KB Output is correct
86 Correct 37 ms 19252 KB Output is correct
87 Correct 40 ms 19284 KB Output is correct
88 Correct 36 ms 19284 KB Output is correct
89 Correct 46 ms 19292 KB Output is correct
90 Correct 36 ms 19288 KB Output is correct