답안 #53756

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
53756 2018-07-01T06:45:10 Z ainta(#1540) Sandwich (JOI16_sandwich) C++11
35 / 100
44 ms 27848 KB
#include<cstdio>
#include<algorithm>
#include<vector>
#include<bitset>
using namespace std;
int n, m, Q[501000], Deg[501000], head, tail, Res[501000];
char p[410][410];
vector<int>E[501000], F[501000];
bitset<5010>BB[5010];
int Num(int x, int y, int ck) {
	if (x<1 || x>n || y<1 || y>m)return 0;
	int cc = 0;
	if (p[x][y] == 'N') {
		if (ck == 0 || ck == 3)cc = 1;
		else cc = 2;
	}
	else {
		if (ck == 0 || ck == 2)cc = 1;
		else cc = 2;
	}
	return ((x - 1)*m + (y - 1))*2 +cc;
}
void Add_Edge(int a, int b) {
	if (!a || !b)return;
	E[a].push_back(b);
	Deg[a]++;
	F[b].push_back(a);
}
int main() {
	int i, j;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= n; i++) {
		scanf("%s", p[i] + 1);
	}
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= m; j++) {
			Add_Edge(Num(i, j, 0), Num(i - 1, j, 0));
			Add_Edge(Num(i, j, 1), Num(i + 1, j, 1));
			Add_Edge(Num(i, j, 2), Num(i, j - 1, 2));
			Add_Edge(Num(i, j, 3), Num(i, j + 1, 3));
		}
	}
	if (n > 50 || m > 50)return 0;
	for (i = 1; i <= n*m * 2; i++) {
		BB[i][i] = 1;
		if (!Deg[i])Q[++tail] = i;
	}
	while (head < tail) {
		int x = Q[++head];
		for (auto &t : F[x]) {
			Deg[t]--;
			if (!Deg[t])Q[++tail] = t;
		}
	}
	for (i = 1; i <= tail;i++) {
		int x = Q[i];
		if (Deg[x])continue;
		for (auto &t : E[x]) {
			BB[x] |= BB[t];
		}
	}
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= m; j++) {
			int t1 = ((i - 1)*m + (j - 1))*2 + 1;
			int t2 = t1 + 1;
			int res = 1e9;
			if (!Deg[t2])res = min(res, (int)BB[t2].count());
			if (!Deg[t1])res = min(res, (int)BB[t1].count());
			if (res > 8e8)res = -1;
			else res *= 2;
			printf("%d ", res);
		}
		puts("");
	}
}

Compilation message

sandwich.cpp: In function 'int main()':
sandwich.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
sandwich.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", p[i] + 1);
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23800 KB Output is correct
2 Correct 20 ms 24036 KB Output is correct
3 Correct 20 ms 24036 KB Output is correct
4 Correct 20 ms 24112 KB Output is correct
5 Correct 21 ms 24192 KB Output is correct
6 Correct 25 ms 27376 KB Output is correct
7 Correct 27 ms 27376 KB Output is correct
8 Correct 31 ms 27584 KB Output is correct
9 Correct 29 ms 27584 KB Output is correct
10 Correct 26 ms 27648 KB Output is correct
11 Correct 27 ms 27648 KB Output is correct
12 Correct 26 ms 27648 KB Output is correct
13 Correct 27 ms 27708 KB Output is correct
14 Correct 32 ms 27708 KB Output is correct
15 Correct 27 ms 27708 KB Output is correct
16 Correct 27 ms 27804 KB Output is correct
17 Correct 27 ms 27804 KB Output is correct
18 Correct 28 ms 27816 KB Output is correct
19 Correct 27 ms 27816 KB Output is correct
20 Correct 26 ms 27816 KB Output is correct
21 Correct 25 ms 27816 KB Output is correct
22 Correct 26 ms 27816 KB Output is correct
23 Correct 26 ms 27816 KB Output is correct
24 Correct 26 ms 27816 KB Output is correct
25 Correct 44 ms 27816 KB Output is correct
26 Correct 31 ms 27820 KB Output is correct
27 Correct 26 ms 27848 KB Output is correct
28 Correct 27 ms 27848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23800 KB Output is correct
2 Correct 20 ms 24036 KB Output is correct
3 Correct 20 ms 24036 KB Output is correct
4 Correct 20 ms 24112 KB Output is correct
5 Correct 21 ms 24192 KB Output is correct
6 Correct 25 ms 27376 KB Output is correct
7 Correct 27 ms 27376 KB Output is correct
8 Correct 31 ms 27584 KB Output is correct
9 Correct 29 ms 27584 KB Output is correct
10 Correct 26 ms 27648 KB Output is correct
11 Correct 27 ms 27648 KB Output is correct
12 Correct 26 ms 27648 KB Output is correct
13 Correct 27 ms 27708 KB Output is correct
14 Correct 32 ms 27708 KB Output is correct
15 Correct 27 ms 27708 KB Output is correct
16 Correct 27 ms 27804 KB Output is correct
17 Correct 27 ms 27804 KB Output is correct
18 Correct 28 ms 27816 KB Output is correct
19 Correct 27 ms 27816 KB Output is correct
20 Correct 26 ms 27816 KB Output is correct
21 Correct 25 ms 27816 KB Output is correct
22 Correct 26 ms 27816 KB Output is correct
23 Correct 26 ms 27816 KB Output is correct
24 Correct 26 ms 27816 KB Output is correct
25 Correct 44 ms 27816 KB Output is correct
26 Correct 31 ms 27820 KB Output is correct
27 Correct 26 ms 27848 KB Output is correct
28 Correct 27 ms 27848 KB Output is correct
29 Incorrect 21 ms 27848 KB Output isn't correct
30 Halted 0 ms 0 KB -