답안 #26298

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26298 2017-06-29T05:58:11 Z 서규호(#1103) Raspad (COI17_raspad) C++14
0 / 100
246 ms 1048576 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;
int a[100002][52];
int where[100002][52],when[100002][52];
bool check[100002][52];
char s[100];
lld seg[400002];
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

void update(int node,int l,int r,int s,int e,lld value){
	if(r < s || e < l || s > e) return;
	if(s <= l && r <= e){
		seg[node] += (value*(r-l+1));
		return;
	}
	int mid = (l+r)/2;
	update(node*2,l,mid,s,e,value);
	update(node*2+1,mid+1,r,s,e,value);
	seg[node] = seg[node*2]+seg[node*2+1];
}

int sx,ex;
void dfs(int x,int y){
	check[x][y] = true;
	for(int i=0; i<4; i++){
		if(x+dx[i] < sx || x+dx[i] > ex || y+dy[i] < 1 || y+dy[i] > M) continue;
		if(a[x+dx[i]][y+dy[i]] == 0) continue;
		dfs(x+dx[i],y+dy[i]);
	}
}
void process(int x,int y){
	sx = x; ex = y;
	for(int i=x; i<=y; i++){
		for(int j=1; j<=M; j++){
			if(check[i][j] || a[i][j] == 0) continue;
			dfs(i,j);
			ans++;
		}
	}
	for(int i=x; i<=y; i++) for(int j=1; j<=M; j++) check[i][j] = false;
}

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++){
		for(int j=1; j<=i; j++){
			process(j,i);
		}
	}
	printf("%lld\n",ans);

	return 0;
}

Compilation message

raspad.cpp: In function 'int main()':
raspad.cpp:59: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:62:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",s);
                ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 71160 KB Output is correct
2 Memory limit exceeded 246 ms 1048576 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 71160 KB Output is correct
2 Memory limit exceeded 246 ms 1048576 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Memory limit exceeded 236 ms 1048576 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 71160 KB Output is correct
2 Memory limit exceeded 246 ms 1048576 KB Memory limit exceeded
3 Halted 0 ms 0 KB -