답안 #55956

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
55956 2018-07-09T08:19:26 Z youngyojun Sandwich (JOI16_sandwich) C++11
0 / 100
3 ms 672 KB
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;

const int MAXH = 405;
const int MAXW = 405;

int dp[2][MAXH][MAXW];

bool chk[2][MAXH][MAXW], isp[2][MAXH][MAXW];
int CNT;

char A[MAXH][MAXW];

int H, W;

void f(int t, int y, int x) {
	if(chk[t][y][x]) return;
	chk[t][y][x] = true; CNT++;

	int ax = (t ? x+1 : x-1), by = ((!!t == ('N' == A[y][x])) ? y-1 : y+1);

	f(t, y, ax); f(t, by, x);
	isp[t][y][x] = (isp[t][y][ax] && isp[t][by][x]);
}

void init() {
	for(int i = 0; i < 2; i++) for(int j = 0; j <= H; j++) {
		fill(chk[i][j], chk[i][j]+W+1, false);
		fill(isp[i][j], isp[i][j]+W+1, false);
	}
	for(int t = 0; t < 2; t++) {
		for(int i = 0; i <= H+1; i++)
			chk[t][i][0] = chk[t][i][W+1] = isp[t][i][0] = isp[t][i][W+1] = true;
		for(int i = 0; i <= W+1; i++)
			chk[t][0][i] = chk[t][H+1][i] = isp[t][0][i] = isp[t][H+1][i] = true;
	}
	CNT = 0;
}

int main() {
	scanf("%d%d", &H, &W);
	for(int i = 1; i <= H; i++) scanf(" %s", A[i]+1);

	for(int y = 1; y <= H; y++) {
		init();
		for(int x = 1; x <= W; x++) {
			f(0, y, x);
			dp[0][y][x] = isp[0][y][x] ? CNT : INF;
		}
		init();
		for(int x = W; x; x--) {
			f(1, y, x);
			dp[1][y][x] = isp[1][y][x] ? CNT : INF;
		}
	}

	for(int i = 1; i <= H; i++) {
		for(int j = 1; j <= W; j++) {
			int t = min(dp[0][i][j], dp[1][i][j]);
			printf("%d ", INF <= t ? -1 : t*2);
		}
		puts("");
	}
	return 0;
}

Compilation message

sandwich.cpp: In function 'int main()':
sandwich.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &H, &W);
  ~~~~~^~~~~~~~~~~~~~~~
sandwich.cpp:56:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= H; i++) scanf(" %s", A[i]+1);
                              ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 360 KB Output is correct
3 Incorrect 3 ms 672 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 360 KB Output is correct
3 Incorrect 3 ms 672 KB Output isn't correct
4 Halted 0 ms 0 KB -