제출 #136466

#제출 시각아이디문제언어결과실행 시간메모리
136466sebinkimConnect (CEOI06_connect)C++14
80 / 100
31 ms17016 KiB
#include <bits/stdc++.h>

using namespace std;

int D[1010][9090];
char S[33][99];
int n, m;

int main()
{
	int i, j, x, y, t;
	
	scanf("%d%d\n", &n, &m);
	
	for(i=0; i<n; i++){
		fgets(S[i], 88, stdin);
	}
	
	n /= 2; m /= 2;
	
	for(i=0; i<=n*m; i++){
		for(j=0; j<(1<<n+1); j++){
			D[i][j] = 1e9;
		}
	}
	
	D[0][0] = 0;
	
	for(i=0; i<n*m; i++){
		x = i % n << 1 | 1; y = i / n << 1 | 1;
		for(j=0; j<(1<<n+1); j++){
			if(S[x][y] == 'X'){
				if((j & 3) == 3) continue;
				else if(j & 3){
					t = j >> 1 & ~1;
					D[i + 1][t] = min(D[i + 1][t], D[i][j] + 1);
				}
				else{
					if(S[x + 1][y] != '-'){
						t = j >> 1 | 1;
						D[i + 1][t] = min(D[i + 1][t], D[i][j] + 1);
					}
					if(S[x][y + 1] != '|'){
						t = j >> 1 & ~1 | 1 << n;
						D[i + 1][t] = min(D[i + 1][t], D[i][j] + 1);
					}
				}
			}
			else{
				if((j & 3) == 3){
					t = j >> 1 & ~1;
					D[i + 1][t] = min(D[i + 1][t], D[i][j] + 2);
				}
				else if(j & 3){
					if(S[x + 1][y] != '-'){
						t = j >> 1 | 1;
						D[i + 1][t] = min(D[i + 1][t], D[i][j] + 2);
					}
					if(S[x][y + 1] != '|'){
						t = j >> 1 & ~1 | 1 << n;
						D[i + 1][t] = min(D[i + 1][t], D[i][j] + 2);
					}
				}
				else{
					t = j >> 1 & ~1;
					D[i + 1][t] = min(D[i + 1][t], D[i][j]);
					if(S[x + 1][y] != '-' && S[x][y + 1] != '|'){
						t = j >> 1 | 1 | 1 << n;
						D[i + 1][t] = min(D[i + 1][t], D[i][j] + 2);
					}
				}
			}
		}
	}
	
	printf("%d\n", D[n * m][0]);
	
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

connect.cpp: In function 'int main()':
connect.cpp:22:19: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   for(j=0; j<(1<<n+1); j++){
                  ~^~
connect.cpp:31:19: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   for(j=0; j<(1<<n+1); j++){
                  ~^~
connect.cpp:44:18: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
       t = j >> 1 & ~1 | 1 << n;
           ~~~~~~~^~~~
connect.cpp:60:18: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
       t = j >> 1 & ~1 | 1 << n;
           ~~~~~~~^~~~
connect.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d\n", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~~
connect.cpp:16:8: warning: ignoring return value of 'char* fgets(char*, int, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   fgets(S[i], 88, stdin);
   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...