답안 #22678

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22678 2017-04-30T06:27:13 Z dhsrhkdgus(#943, kjp4155, cok1973, dhsrhkdgus) Young Zebra (KRIII5_YZ) C++14
0 / 7
199 ms 120224 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))

#define MAX3(x, y, z) ( (x) > (y)  ? ( (x) > (z) ? (x) : (z)  ) : ( (y) > (z) ? (y) : (z) )  )
#define MIN3(x, y, z) ( (x) < (y)  ? ( (x) < (z) ? (x) : (z)  ) : ( (y) < (z) ? (y) : (z) )  )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 987654321
#define IINF 987654321987654321

int N,M,NN,MM;
int xx[4] = {1,-1,0,0}, yy[4] = {0,0,1,-1};

char p[500][500]; int ans[500][500]; bool vis[2500][2500];
int group[2500][2500];
char s[2500][2500]; int ans2[500][500]; int group2[2500][2500]; 
int g = 0; int gsize[2500*2500]; int g2 = 0; int gsize2[2500*2500];
bool inbound(int y, int x ){
	if( x < 0 || y < 0 || x >= MM || y >= NN ) return false;
	return true;
}
int dfs1(int y, int x){
	int sz = 1; group[y][x] = g;
	vis[y][x] = true;
	rep(k,4){
		int ny = y + yy[k]; int nx = x + xx[k];
		if( !inbound(ny,nx) ) continue;
		if( vis[ny][nx] ) continue;
		if( s[y][x] == s[ny][nx] ) sz += dfs1(ny,nx);
	}
	return sz;
}
int dfs2(int y, int x){
	int sz = 1; group2[y][x] = g2;
	vis[y][x] = true;
	rep(k,4){
		int ny = y + yy[k]; int nx = x + xx[k];
		if( !inbound(ny,nx) ) continue;
		if( vis[ny][nx] ) continue;
		if( s[y][x] == s[ny][nx] ) sz += dfs2(ny,nx);
	}
	return sz;
}
int main(void){
	geti(N,M);
	rep(i,N) scanf("%s",p[i]);
	NN = N*3; MM = M*3;

	rep(i,NN){
		rep(j,MM){
			s[i][j] = p[i%N][j%M];	
		}
	}
	
	rep(i,NN){
		rep(j,MM)if( !vis[i][j] ) {
			g++;
			gsize[g] = dfs1(i,j);
		}
	}
	NN = N*5; MM = M*5;
	rep(i,NN){
		rep(j,MM) s[i][j] = p[i%N][j%M];
	}
	memset(vis,0,sizeof vis);
	rep(i,NN){
		rep(j,MM)if( !vis[i][j] ) {
			g2++;
			gsize2[g2] = dfs2(i,j);
		}
	}

	rep(i,N){
		rep(j,M){
			int y = i + N; int x = j + M; 
			if( gsize[group[y][x]] != gsize2[group2[y+N][x+M]] ){
				printf("-1 ");
			}
			else printf("%d ",gsize[group[y][x]]);
		}
		printf("\n");
	}

}	

Compilation message

YZ.cpp: In function 'int main()':
YZ.cpp:84:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  geti(N,M);
           ^
YZ.cpp:85:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  rep(i,N) scanf("%s",p[i]);
                           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 199 ms 120224 KB Output is correct
2 Incorrect 186 ms 117712 KB Output isn't correct
3 Halted 0 ms 0 KB -