Submission #562230

# Submission time Handle Problem Language Result Execution time Memory
562230 2022-05-14T07:42:16 Z Koosha_mv Raspad (COI17_raspad) C++14
100 / 100
2324 ms 14868 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=1e5+99,M=52;

int n,m,a[N],col[M],Max1[M],Max2[M],dp[2][M][M];
ll ans;
string S[N];
vector<pair<int,int>> vec[2];

int32_t main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin>>n>>m;
	f(i,1,n+1) cin>>S[i],S[i]=' '+S[i];
	f(id,1,n+1){
		//cout<<"COL = "<<id<<endl;
		string s=S[id];
		int t=id&1;
		iota(col,col+M,0);
		vec[t].clear();
		f(i,1,m+1) f(j,i+1,m+1) dp[t][i][j]=0;
		f(i,1,m+1){
			if(s[i]=='0') continue ;
			if(s[i-1]=='1'){
				col[i]=col[i-1];
				for(int j=i-1;s[j]=='1';j--){
					dp[t][j][i]=id;
					vec[t].pb({j,i});
				}
			}
		}
		for(auto p : vec[t^1]){
			if(col[p.F]==col[p.S] || s[p.F]=='0' || s[p.S]=='0') continue ;
			vector<int> v0,v1;
 			f(i,1,m+1) if(col[i]==col[p.F]) v0.pb(i);
			f(i,1,m+1) if(col[i]==col[p.S]) v1.pb(i);
			for(auto u : v0){
				for(auto v : v1){
					int x=u,y=v;
					col[y]=col[p.F];
					if(x>y) swap(x,y);
					vec[t].pb({x,y});
					dp[t][x][y]=dp[t^1][p.F][p.S];
				}
			}
		}
		f(i,1,m+1) Max1[i]=0,Max2[i]=0,dp[t][i][i]=id;
		f(i,1,m+1){
			f(j,i,m+1){
				if(s[i]=='0' || s[j]=='0') continue ;
				if(i!=j) maxm(Max1[j],dp[t][i][j]);
				if(id<n && S[id+1][i]=='1') maxm(Max2[j],dp[t][i][j]);
				if(id<n && S[id+1][j]=='1') maxm(Max2[i],dp[t][i][j]);
			}
		}
		f(i,1,m+1){
			if(s[i]=='0') continue ;
			maxm(Max2[i],Max1[i]);
			ans+=id-Max1[i];
			ans+=1ll*(id-Max2[i])*(n-id);
		}
		/*f(i,1,m+1){
			f(j,i+1,m+1){
				if(s[i]=='1' && s[j]=='1'){
					cout<<i<<" "<<j<<" -> "<<dp[t][i][j]<<endl;
				}
			}
		}
		eror(ans);*/
	}
	cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 4 ms 3472 KB Output is correct
3 Correct 3 ms 3464 KB Output is correct
4 Correct 3 ms 3412 KB Output is correct
5 Correct 3 ms 3420 KB Output is correct
6 Correct 3 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 4 ms 3472 KB Output is correct
3 Correct 3 ms 3464 KB Output is correct
4 Correct 3 ms 3412 KB Output is correct
5 Correct 3 ms 3420 KB Output is correct
6 Correct 3 ms 3412 KB Output is correct
7 Correct 6 ms 3528 KB Output is correct
8 Correct 2 ms 3412 KB Output is correct
9 Correct 17 ms 3608 KB Output is correct
10 Correct 8 ms 3540 KB Output is correct
11 Correct 9 ms 3540 KB Output is correct
12 Correct 10 ms 3588 KB Output is correct
13 Correct 9 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 4088 KB Output is correct
2 Correct 131 ms 9720 KB Output is correct
3 Correct 229 ms 9728 KB Output is correct
4 Correct 56 ms 9008 KB Output is correct
5 Correct 35 ms 5268 KB Output is correct
6 Correct 141 ms 9728 KB Output is correct
7 Correct 144 ms 9724 KB Output is correct
8 Correct 96 ms 8472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 4 ms 3472 KB Output is correct
3 Correct 3 ms 3464 KB Output is correct
4 Correct 3 ms 3412 KB Output is correct
5 Correct 3 ms 3420 KB Output is correct
6 Correct 3 ms 3412 KB Output is correct
7 Correct 6 ms 3528 KB Output is correct
8 Correct 2 ms 3412 KB Output is correct
9 Correct 17 ms 3608 KB Output is correct
10 Correct 8 ms 3540 KB Output is correct
11 Correct 9 ms 3540 KB Output is correct
12 Correct 10 ms 3588 KB Output is correct
13 Correct 9 ms 3540 KB Output is correct
14 Correct 91 ms 4088 KB Output is correct
15 Correct 131 ms 9720 KB Output is correct
16 Correct 229 ms 9728 KB Output is correct
17 Correct 56 ms 9008 KB Output is correct
18 Correct 35 ms 5268 KB Output is correct
19 Correct 141 ms 9728 KB Output is correct
20 Correct 144 ms 9724 KB Output is correct
21 Correct 96 ms 8472 KB Output is correct
22 Correct 399 ms 11700 KB Output is correct
23 Correct 1746 ms 14752 KB Output is correct
24 Correct 2324 ms 14788 KB Output is correct
25 Correct 552 ms 14868 KB Output is correct
26 Correct 762 ms 14716 KB Output is correct
27 Correct 464 ms 13748 KB Output is correct
28 Correct 1022 ms 13892 KB Output is correct
29 Correct 732 ms 14728 KB Output is correct
30 Correct 312 ms 14728 KB Output is correct
31 Correct 1878 ms 14740 KB Output is correct
32 Correct 988 ms 14736 KB Output is correct
33 Correct 626 ms 13508 KB Output is correct
34 Correct 900 ms 13608 KB Output is correct