Submission #55966

# Submission time Handle Problem Language Result Execution time Memory
55966 2018-07-09T08:34:36 Z youngyojun Sandwich (JOI16_sandwich) C++11
35 / 100
8000 ms 21008 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;

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[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);
	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[t][y][x] = (isp[at][y][ax] && isp[bt][by][x]);
}

void init() {
	for(int i = 0; i < 2; i++) for(int j = 0; j <= H+1; j++) {
		fill(chk[i][j], chk[i][j]+W+2, false);
		fill(isp[i][j], isp[i][j]+W+2, 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:62: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:63: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);
                              ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 788 KB Output is correct
4 Correct 3 ms 788 KB Output is correct
5 Correct 3 ms 788 KB Output is correct
6 Correct 16 ms 1172 KB Output is correct
7 Correct 8 ms 1172 KB Output is correct
8 Correct 7 ms 1172 KB Output is correct
9 Correct 5 ms 1172 KB Output is correct
10 Correct 8 ms 1172 KB Output is correct
11 Correct 10 ms 1172 KB Output is correct
12 Correct 5 ms 1172 KB Output is correct
13 Correct 11 ms 1172 KB Output is correct
14 Correct 10 ms 1172 KB Output is correct
15 Correct 5 ms 1172 KB Output is correct
16 Correct 6 ms 1172 KB Output is correct
17 Correct 12 ms 1172 KB Output is correct
18 Correct 7 ms 1172 KB Output is correct
19 Correct 6 ms 1172 KB Output is correct
20 Correct 7 ms 1172 KB Output is correct
21 Correct 9 ms 1172 KB Output is correct
22 Correct 9 ms 1172 KB Output is correct
23 Correct 11 ms 1172 KB Output is correct
24 Correct 13 ms 1172 KB Output is correct
25 Correct 13 ms 1172 KB Output is correct
26 Correct 13 ms 1172 KB Output is correct
27 Correct 7 ms 1172 KB Output is correct
28 Correct 10 ms 1556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 788 KB Output is correct
4 Correct 3 ms 788 KB Output is correct
5 Correct 3 ms 788 KB Output is correct
6 Correct 16 ms 1172 KB Output is correct
7 Correct 8 ms 1172 KB Output is correct
8 Correct 7 ms 1172 KB Output is correct
9 Correct 5 ms 1172 KB Output is correct
10 Correct 8 ms 1172 KB Output is correct
11 Correct 10 ms 1172 KB Output is correct
12 Correct 5 ms 1172 KB Output is correct
13 Correct 11 ms 1172 KB Output is correct
14 Correct 10 ms 1172 KB Output is correct
15 Correct 5 ms 1172 KB Output is correct
16 Correct 6 ms 1172 KB Output is correct
17 Correct 12 ms 1172 KB Output is correct
18 Correct 7 ms 1172 KB Output is correct
19 Correct 6 ms 1172 KB Output is correct
20 Correct 7 ms 1172 KB Output is correct
21 Correct 9 ms 1172 KB Output is correct
22 Correct 9 ms 1172 KB Output is correct
23 Correct 11 ms 1172 KB Output is correct
24 Correct 13 ms 1172 KB Output is correct
25 Correct 13 ms 1172 KB Output is correct
26 Correct 13 ms 1172 KB Output is correct
27 Correct 7 ms 1172 KB Output is correct
28 Correct 10 ms 1556 KB Output is correct
29 Correct 2 ms 1556 KB Output is correct
30 Correct 18 ms 2856 KB Output is correct
31 Execution timed out 8051 ms 21008 KB Time limit exceeded
32 Halted 0 ms 0 KB -