답안 #55968

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
55968 2018-07-09T08:40:19 Z youngyojun Sandwich (JOI16_sandwich) C++11
100 / 100
4126 ms 16856 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];

bitset<(MAXH<<12)> chk, isp;
int CNT;

char A[MAXH][MAXW];

int H, W;

int g(char c, int dr) {
	if('N' == c) return !!(dr < 2);
	if('Z' == c) return !!(dr && dr < 3);
	return 0;
}

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

	int ax = (t ? x+1 : x-1), by = ((!!t == ('N' == A[y][x])) ? y-1 : y+1);
	int at = !g(A[y][ax], x < ax ? 3 : 1), bt = !g(A[by][x], y < by ? 0 : 2);

	f(at, y, ax); f(bt, by, x);
	isp[(y<<10)+x] = (isp[(y<<10)+ax] && isp[(by<<10)+x]);
}

void init() {
	chk.reset(); isp.reset();
	for(int i = 0; i <= H+1; i++)
		chk[i<<10] = chk[(i<<10)+W+1] = isp[i<<10] = isp[(i<<10)+W+1] = true;
	for(int i = 0; i <= W+1; i++)
		chk[i] = chk[((H+1)<<10)+i] = isp[i] = isp[((H+1)<<10)+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[(y<<10)+x] ? CNT : INF;
		}
		init();
		for(int x = W; x; x--) {
			f(1, y, x);
			dp[1][y][x] = isp[(y<<10)+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:57: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:58: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 3 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 5 ms 1068 KB Output is correct
4 Correct 2 ms 1068 KB Output is correct
5 Correct 5 ms 1144 KB Output is correct
6 Correct 15 ms 1144 KB Output is correct
7 Correct 7 ms 1144 KB Output is correct
8 Correct 10 ms 1200 KB Output is correct
9 Correct 10 ms 1200 KB Output is correct
10 Correct 11 ms 1200 KB Output is correct
11 Correct 10 ms 1208 KB Output is correct
12 Correct 6 ms 1208 KB Output is correct
13 Correct 10 ms 1208 KB Output is correct
14 Correct 9 ms 1208 KB Output is correct
15 Correct 10 ms 1208 KB Output is correct
16 Correct 8 ms 1208 KB Output is correct
17 Correct 9 ms 1208 KB Output is correct
18 Correct 9 ms 1208 KB Output is correct
19 Correct 7 ms 1372 KB Output is correct
20 Correct 8 ms 1372 KB Output is correct
21 Correct 10 ms 1372 KB Output is correct
22 Correct 7 ms 1372 KB Output is correct
23 Correct 7 ms 1372 KB Output is correct
24 Correct 9 ms 1372 KB Output is correct
25 Correct 9 ms 1372 KB Output is correct
26 Correct 10 ms 1372 KB Output is correct
27 Correct 9 ms 1468 KB Output is correct
28 Correct 9 ms 1468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 5 ms 1068 KB Output is correct
4 Correct 2 ms 1068 KB Output is correct
5 Correct 5 ms 1144 KB Output is correct
6 Correct 15 ms 1144 KB Output is correct
7 Correct 7 ms 1144 KB Output is correct
8 Correct 10 ms 1200 KB Output is correct
9 Correct 10 ms 1200 KB Output is correct
10 Correct 11 ms 1200 KB Output is correct
11 Correct 10 ms 1208 KB Output is correct
12 Correct 6 ms 1208 KB Output is correct
13 Correct 10 ms 1208 KB Output is correct
14 Correct 9 ms 1208 KB Output is correct
15 Correct 10 ms 1208 KB Output is correct
16 Correct 8 ms 1208 KB Output is correct
17 Correct 9 ms 1208 KB Output is correct
18 Correct 9 ms 1208 KB Output is correct
19 Correct 7 ms 1372 KB Output is correct
20 Correct 8 ms 1372 KB Output is correct
21 Correct 10 ms 1372 KB Output is correct
22 Correct 7 ms 1372 KB Output is correct
23 Correct 7 ms 1372 KB Output is correct
24 Correct 9 ms 1372 KB Output is correct
25 Correct 9 ms 1372 KB Output is correct
26 Correct 10 ms 1372 KB Output is correct
27 Correct 9 ms 1468 KB Output is correct
28 Correct 9 ms 1468 KB Output is correct
29 Correct 2 ms 1468 KB Output is correct
30 Correct 28 ms 2528 KB Output is correct
31 Correct 4126 ms 9788 KB Output is correct
32 Correct 3979 ms 9940 KB Output is correct
33 Correct 912 ms 9940 KB Output is correct
34 Correct 1314 ms 9940 KB Output is correct
35 Correct 1004 ms 9940 KB Output is correct
36 Correct 54 ms 9940 KB Output is correct
37 Correct 1387 ms 9940 KB Output is correct
38 Correct 1665 ms 9940 KB Output is correct
39 Correct 1490 ms 9940 KB Output is correct
40 Correct 2017 ms 9940 KB Output is correct
41 Correct 758 ms 9940 KB Output is correct
42 Correct 1693 ms 9940 KB Output is correct
43 Correct 1712 ms 9940 KB Output is correct
44 Correct 1770 ms 9940 KB Output is correct
45 Correct 1404 ms 9940 KB Output is correct
46 Correct 836 ms 9940 KB Output is correct
47 Correct 1120 ms 9940 KB Output is correct
48 Correct 707 ms 9940 KB Output is correct
49 Correct 987 ms 9940 KB Output is correct
50 Correct 1059 ms 9940 KB Output is correct
51 Correct 943 ms 9940 KB Output is correct
52 Correct 1084 ms 9940 KB Output is correct
53 Correct 1041 ms 9940 KB Output is correct
54 Correct 1058 ms 9940 KB Output is correct
55 Correct 1143 ms 9940 KB Output is correct
56 Correct 993 ms 9940 KB Output is correct
57 Correct 814 ms 9940 KB Output is correct
58 Correct 2064 ms 9940 KB Output is correct
59 Correct 2111 ms 9940 KB Output is correct
60 Correct 1373 ms 9940 KB Output is correct
61 Correct 2303 ms 10736 KB Output is correct
62 Correct 1810 ms 16856 KB Output is correct
63 Correct 1891 ms 16856 KB Output is correct