Submission #26306

# Submission time Handle Problem Language Result Execution time Memory
26306 2017-06-29T06:12:19 Z 서규호(#1103) Raspad (COI17_raspad) C++14
0 / 100
83 ms 62956 KB
#include <bits/stdc++.h>

#define lld long long
#define pp pair<int,int>
#define pb push_back
#define MOD 1000000007
#define left lleft
#define right rright
#define Inf 2000000000
#define Linf 1000000000000000000LL
#define next nnext
#define minus mminus

using namespace std;

int N,M,nn; lld ans,sum;
int a[100002][52];
int where[100002][52],when[100002][52];
char s[100];

void update(int node,int l,int r,lld s,lld e,lld value){
	sum += (e-s+1)*value;
}

int main(){
	scanf("%d %d",&N,&M);
	for(nn=1; nn<N; nn*=2);
	for(int i=1; i<=N; i++){
		scanf("%s",s);
		for(int j=1; j<=M; j++) a[i][j] = s[j-1]-'0';
	}
	for(int i=1; i<=N; i++){
		vector<pp> tmp;
		bool flag = false;
		for(int j=1; j<=M+1; j++){
			if(!flag && a[i][j] == 1){
				flag = true;
				tmp.pb({j,0});
			}
			if(flag && a[i][j] == 0){
				flag = false;
				tmp.back().second = j-1;
			}
		}
		update(1,1,nn,i,i,tmp.size());
		vector<pp> memo;
		for(int j=0; j<tmp.size(); j++){
			int s,e;
			s = tmp[j].first; e = tmp[j].second;
			vector<int> t;
			for(int k=s; k<=e; k++){
				where[i][k] = j;
				if(a[i-1][k] == 1){
					if(t.size() == 0) t.pb(where[i-1][k]);
					else if(t.back() != where[i-1][k]) t.pb(where[i-1][k]);
				}
			}
			if(t.size() == 0){
				update(1,1,nn,1,i-1,1);
				memo.pb({-1,-1});
			}else{
				memo.pb({t[0],t.back()});
			}
			for(int k=0; k<(int)t.size()-1; k++){
                update(1,1,nn,when[i-1][t[k]]+1,i-1,-1);
			}
		}
		for(int j=0; j<(int)tmp.size()-1; j++){
			if(memo[j].first == -1 || memo[j+1].first == -1){
				when[i][j] = 0;
				continue;
			}
			if(memo[j].second >= memo[j+1].first){
				when[i][j] = i-1;
			}
			for(int k=memo[j].second; k<memo[j+1].first; k++){
				when[i][j] = max(when[i][j],when[i-1][k]);
			}
		}
		ans += sum;
	}
	printf("%lld\n",ans);

	return 0;
}

Compilation message

raspad.cpp: In function 'int main()':
raspad.cpp:47:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0; j<tmp.size(); j++){
                 ^
raspad.cpp:26:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&N,&M);
                      ^
raspad.cpp:29:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",s);
                ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 62956 KB Output is correct
2 Incorrect 0 ms 62956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 62956 KB Output is correct
2 Incorrect 0 ms 62956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 62956 KB Output is correct
2 Incorrect 83 ms 62956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 62956 KB Output is correct
2 Incorrect 0 ms 62956 KB Output isn't correct
3 Halted 0 ms 0 KB -