Submission #22724

# Submission time Handle Problem Language Result Execution time Memory
22724 2017-04-30T06:57:31 Z 퍼플달고싶다(#990, smu201111192, pce913, cokcjswo) Young Zebra (KRIII5_YZ) C++
0 / 7
126 ms 25408 KB
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define SIZE 31600000
#define BC 50
#define BS 5000
#define MOD 1000000007LL
#define MAXV 555
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<vector<long long> > mat;

int n,m;
char str[444][444];
bool bd[1222][1222];
bool visited[1222][1222];
int sz[1222][1222];
pair<int, int> p[1222][1222];
int dy[4] = {-1,0,1,0}, dx[4] = {0,1,0,-1};

pair<int, int> find(pair<int, int> u) {
	if(p[u.fi][u.se] == u)	return u;
	return p[u.fi][u.se] = find(p[u.fi][u.se]);
}

void merge(pair<int, int> u, pair<int, int> v) {
	u = find(u), v = find(v);
	if(u == v)	return;
	p[u.fi][u.se] = v;
	sz[v.fi][v.se] += sz[u.fi][u.se];
}

bool ok(int y, int x) {return y>=0 && y<3*n && x>=0 && x<3*m;}

void bfs(int y, int x) {
	queue<pair<int, int > > q;
	q.push({y,x});
	visited[y][x] = 1;
	while(!q.empty()) {
		int hy = q.front().fi, hx = q.front().se;
		// printf("here %d %d\n",hy,hx);
		q.pop();
		for(int i=0;i<4;i++) {
			int ny = hy + dy[i], nx = hx + dx[i];
			if(ok(ny,nx) && visited[ny][nx] == 0 && (bd[y][x] == bd[ny][nx])) {
				merge({y,x}, {ny,nx}), q.push({ny,nx}), visited[ny][nx] = 1;
			}
		}
	}
}

int main () {
	for(int i=0;i<1222;i++)	for(int j=0;j<1222;j++)	p[i][j] = {i,j}, sz[i][j] = 1;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)	scanf("%s",str[i]);
	// printf("END\n");
	for(int yc=0;yc<3;yc++) {
		for(int xc=0;xc<3;xc++) {
			for(int i=0;i<n;i++) {
				for(int j=0;j<m;j++) {
					bd[yc*n+i][xc*m+j] = str[i][j] == 'B' ? 1 : 0;
				}
			}
		}
	}


	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			int y = n+i, x = m+j;
			if(visited[y][x] == 0)		bfs(y,x);
			pair<int, int> root = find({y,x});
			printf("%d ",sz[root.fi][root.se]);
		}
		printf("\n");
	}

	// for(int i=0;i<100;i++) {
	// 	for(int j=0;j<100;j++)	printf("%d ",sz[i][j]);
	// 	printf("\n");
	// }
}

Compilation message

YZ.cpp: In function 'void bfs(int, int)':
YZ.cpp:42:9: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
  q.push({y,x});
         ^
YZ.cpp:42:14: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
  q.push({y,x});
              ^
YZ.cpp:51:11: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     merge({y,x}, {ny,nx}), q.push({ny,nx}), visited[ny][nx] = 1;
           ^
YZ.cpp:51:18: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     merge({y,x}, {ny,nx}), q.push({ny,nx}), visited[ny][nx] = 1;
                  ^
YZ.cpp:51:35: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     merge({y,x}, {ny,nx}), q.push({ny,nx}), visited[ny][nx] = 1;
                                   ^
YZ.cpp:51:42: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     merge({y,x}, {ny,nx}), q.push({ny,nx}), visited[ny][nx] = 1;
                                          ^
YZ.cpp: In function 'int main()':
YZ.cpp:58:64: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
  for(int i=0;i<1222;i++) for(int j=0;j<1222;j++) p[i][j] = {i,j}, sz[i][j] = 1;
                                                                ^
YZ.cpp:58:58: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
  for(int i=0;i<1222;i++) for(int j=0;j<1222;j++) p[i][j] = {i,j}, sz[i][j] = 1;
                                                          ^
YZ.cpp:77:31: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
    pair<int, int> root = find({y,x});
                               ^
YZ.cpp:59:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
                     ^
YZ.cpp:60:41: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++) scanf("%s",str[i]);
                                         ^
# Verdict Execution time Memory Grader output
1 Partially correct 126 ms 24680 KB Output is partially correct
2 Incorrect 93 ms 25408 KB Output isn't correct
3 Halted 0 ms 0 KB -