답안 #27018

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27018 2017-07-08T13:15:36 Z 검수팍(#1115) Test Data Creation (FXCUP2_testdata) C++
1 / 1
2633 ms 217544 KB
#include<stdio.h>

int N, M, NM, ba[90090], ans[90090], D[90090][611];
int xchk[90090], ychk[90090];

int dy(int x, int y){
	int df=x-y+NM;
	if(x==N*M-1 && y==N*M-1)return ba[x];
	if(D[x][df])return D[x][df];

	int dap=0x7fffffff, gap;
	if(x<y){
		if(!xchk[x]){
			gap = ba[x]+dy(x+1, y);
			if(dap > gap)dap = gap;
		}
		if(x+N < N*M){
			gap = ba[x]+dy(x+N, y);
			if(dap > gap)dap = gap;
		}
	}
	else{
		if(!ychk[y]){
			gap = ba[y]+dy(x, y+1);
			if(x == y)gap -= ba[y];
			if(dap > gap)dap = gap;
		}
		if(y+M < N*M){
			gap = ba[y]+dy(x, y+M);
			if(x == y)gap -= ba[y];
			if(dap > gap)dap = gap;
		}
	}
	return D[x][df]=dap;
}

void rev(int x, int y){
	ans[x]=ans[y]=1;
	if(x==N*M-1 && y==N*M-1)return;

	if(x<y){
		if(!xchk[x] && dy(x,y) == ba[x]+dy(x+1, y))rev(x+1, y);
		else rev(x+N, y);
	}
	else{
		if(!ychk[y] && dy(x,y) == (x==y?0:ba[y]) + dy(x, y+1))rev(x, y+1);
		else rev(x, y+M);
	}
}


int main(){
	scanf("%d%d", &N, &M);
	NM = N<M?M:N;
	for(int i=0; i<N*M; i++)scanf("%d", &ba[i]);
	for(int i=0; i<N*M; i++){
		if(i%N == N-1) xchk[i]=1;
		if(i%M == M-1) ychk[i]=1;
	}
	printf("%d\n", dy(0, 0)); rev(0, 0);
	for(int i=0; i<M; i++){
		for(int j=0; j<N; j++)printf("%d ", ans[i*N+j]);
		puts("");
	}
	return 0;
}

Compilation message

testdata.cpp: In function 'int main()':
testdata.cpp:53:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
                       ^
testdata.cpp:55:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0; i<N*M; i++)scanf("%d", &ba[i]);
                                             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 217544 KB Correct
2 Correct 0 ms 217544 KB Correct
3 Correct 0 ms 217544 KB Correct
4 Correct 6 ms 217544 KB Correct
5 Correct 199 ms 217544 KB Correct
6 Correct 2633 ms 217544 KB Correct
7 Correct 2186 ms 217544 KB Correct
8 Correct 0 ms 217544 KB Correct
9 Correct 0 ms 217544 KB Correct
10 Correct 0 ms 217544 KB Correct
11 Correct 0 ms 217544 KB Correct
12 Correct 3 ms 217544 KB Correct
13 Correct 0 ms 217544 KB Correct
14 Correct 6 ms 217544 KB Correct
15 Correct 26 ms 217544 KB Correct
16 Correct 59 ms 217544 KB Correct
17 Correct 423 ms 217544 KB Correct
18 Correct 1926 ms 217544 KB Correct
19 Correct 13 ms 217544 KB Correct
20 Correct 1036 ms 217544 KB Correct
21 Correct 539 ms 217544 KB Correct
22 Correct 309 ms 217544 KB Correct
23 Correct 476 ms 217544 KB Correct
24 Correct 2613 ms 217544 KB Correct
25 Correct 2079 ms 217544 KB Correct