# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
53851 |
2018-07-01T09:43:24 Z |
ainta |
Sandwich (JOI16_sandwich) |
C++17 |
|
6194 ms |
11968 KB |
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int Q[3 << 17], Deg[3 << 17], Res[3 << 17], ord[3 << 17], cnt, vis[3 << 17];
char p[1 << 9][1 << 9];
int F[3 << 17][2], CF[3 << 17];
int n, m;
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;
Deg[a]++;
F[b][CF[b]++] = a;
}
int main() {
int i, j;
//freopen("input.txt", "r", stdin);
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));
}
}
int head = 0, tail = 0;
for (i = 1; i <= n*m * 2; i++) {
if (!Deg[i])Q[++tail] = i;
}
while (head < tail) {
int x = Q[++head];
for (int ii = 0; ii < CF[x];ii++) {
int t = F[x][ii];
Deg[t]--;
if (!Deg[t])Q[++tail] = t;
}
}
for (i = 1; i <= tail; i++)ord[++cnt] = Q[i];
int cur = 0;
for (i = 1; i <= n; i++) {
cur++;
for (j = 1; j <= m; j++) {
int bs = Num(i, j, 3);
int head = 0, tail = 0;
if (vis[bs] != cur && !Deg[bs]) {
vis[bs] = cur, Res[bs] += m - j + 1;
Q[++tail] = bs;
}
while (head < tail) {
int x = Q[++head];
for (int ii = 0; ii < CF[x]; ii++) {
int t = F[x][ii];
if (vis[t] != cur && !Deg[t]) {
vis[t] = cur, Res[t] += m - j + 1;
Q[++tail] = t;
}
}
}
}
cur++;
for (j = m; j >= 1; j--) {
int bs = Num(i, j, 2);
int head = 0, tail = 0;
if (vis[bs] != cur && !Deg[bs]) {
vis[bs] = cur, Res[bs] += j;
Q[++tail] = bs;
}
while (head < tail) {
int x = Q[++head];
for (int ii = 0; ii < CF[x]; ii++) {
int t = F[x][ii];
if (vis[t] != cur && !Deg[t]) {
vis[t] = cur, Res[t] += j;
Q[++tail] = t;
}
}
}
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
int bs = ((i - 1)*m + j - 1) * 2, res = 1e9;
if (!Deg[bs + 1])res = min(res, Res[bs + 1]);
if (!Deg[bs + 2])res = min(res, Res[bs + 2]);
if (res > 8e8)res = -1;
else res *= 2;
printf("%d ", res);
}
printf("\n");
}
}
Compilation message
sandwich.cpp: In function 'int main()':
sandwich.cpp:30: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:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", p[i] + 1);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
2 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
484 KB |
Output is correct |
6 |
Correct |
3 ms |
616 KB |
Output is correct |
7 |
Correct |
6 ms |
648 KB |
Output is correct |
8 |
Correct |
5 ms |
792 KB |
Output is correct |
9 |
Correct |
4 ms |
824 KB |
Output is correct |
10 |
Correct |
5 ms |
824 KB |
Output is correct |
11 |
Correct |
7 ms |
824 KB |
Output is correct |
12 |
Correct |
4 ms |
912 KB |
Output is correct |
13 |
Correct |
6 ms |
912 KB |
Output is correct |
14 |
Correct |
6 ms |
912 KB |
Output is correct |
15 |
Correct |
3 ms |
912 KB |
Output is correct |
16 |
Correct |
4 ms |
912 KB |
Output is correct |
17 |
Correct |
5 ms |
912 KB |
Output is correct |
18 |
Correct |
4 ms |
912 KB |
Output is correct |
19 |
Correct |
5 ms |
912 KB |
Output is correct |
20 |
Correct |
3 ms |
940 KB |
Output is correct |
21 |
Correct |
3 ms |
940 KB |
Output is correct |
22 |
Correct |
3 ms |
940 KB |
Output is correct |
23 |
Correct |
3 ms |
940 KB |
Output is correct |
24 |
Correct |
7 ms |
940 KB |
Output is correct |
25 |
Correct |
8 ms |
940 KB |
Output is correct |
26 |
Correct |
5 ms |
940 KB |
Output is correct |
27 |
Correct |
3 ms |
940 KB |
Output is correct |
28 |
Correct |
5 ms |
940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
2 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
484 KB |
Output is correct |
6 |
Correct |
3 ms |
616 KB |
Output is correct |
7 |
Correct |
6 ms |
648 KB |
Output is correct |
8 |
Correct |
5 ms |
792 KB |
Output is correct |
9 |
Correct |
4 ms |
824 KB |
Output is correct |
10 |
Correct |
5 ms |
824 KB |
Output is correct |
11 |
Correct |
7 ms |
824 KB |
Output is correct |
12 |
Correct |
4 ms |
912 KB |
Output is correct |
13 |
Correct |
6 ms |
912 KB |
Output is correct |
14 |
Correct |
6 ms |
912 KB |
Output is correct |
15 |
Correct |
3 ms |
912 KB |
Output is correct |
16 |
Correct |
4 ms |
912 KB |
Output is correct |
17 |
Correct |
5 ms |
912 KB |
Output is correct |
18 |
Correct |
4 ms |
912 KB |
Output is correct |
19 |
Correct |
5 ms |
912 KB |
Output is correct |
20 |
Correct |
3 ms |
940 KB |
Output is correct |
21 |
Correct |
3 ms |
940 KB |
Output is correct |
22 |
Correct |
3 ms |
940 KB |
Output is correct |
23 |
Correct |
3 ms |
940 KB |
Output is correct |
24 |
Correct |
7 ms |
940 KB |
Output is correct |
25 |
Correct |
8 ms |
940 KB |
Output is correct |
26 |
Correct |
5 ms |
940 KB |
Output is correct |
27 |
Correct |
3 ms |
940 KB |
Output is correct |
28 |
Correct |
5 ms |
940 KB |
Output is correct |
29 |
Correct |
2 ms |
940 KB |
Output is correct |
30 |
Correct |
3 ms |
956 KB |
Output is correct |
31 |
Correct |
32 ms |
6376 KB |
Output is correct |
32 |
Correct |
60 ms |
6404 KB |
Output is correct |
33 |
Correct |
15 ms |
6404 KB |
Output is correct |
34 |
Correct |
3158 ms |
11708 KB |
Output is correct |
35 |
Correct |
1279 ms |
11708 KB |
Output is correct |
36 |
Correct |
20 ms |
11708 KB |
Output is correct |
37 |
Correct |
3853 ms |
11708 KB |
Output is correct |
38 |
Correct |
3680 ms |
11832 KB |
Output is correct |
39 |
Correct |
4228 ms |
11832 KB |
Output is correct |
40 |
Correct |
6194 ms |
11960 KB |
Output is correct |
41 |
Correct |
1356 ms |
11960 KB |
Output is correct |
42 |
Correct |
4322 ms |
11968 KB |
Output is correct |
43 |
Correct |
4396 ms |
11968 KB |
Output is correct |
44 |
Correct |
5437 ms |
11968 KB |
Output is correct |
45 |
Correct |
3273 ms |
11968 KB |
Output is correct |
46 |
Correct |
3499 ms |
11968 KB |
Output is correct |
47 |
Correct |
4346 ms |
11968 KB |
Output is correct |
48 |
Correct |
2342 ms |
11968 KB |
Output is correct |
49 |
Correct |
3015 ms |
11968 KB |
Output is correct |
50 |
Correct |
2993 ms |
11968 KB |
Output is correct |
51 |
Correct |
2837 ms |
11968 KB |
Output is correct |
52 |
Correct |
513 ms |
11968 KB |
Output is correct |
53 |
Correct |
680 ms |
11968 KB |
Output is correct |
54 |
Correct |
468 ms |
11968 KB |
Output is correct |
55 |
Correct |
542 ms |
11968 KB |
Output is correct |
56 |
Correct |
686 ms |
11968 KB |
Output is correct |
57 |
Correct |
374 ms |
11968 KB |
Output is correct |
58 |
Correct |
5604 ms |
11968 KB |
Output is correct |
59 |
Correct |
4290 ms |
11968 KB |
Output is correct |
60 |
Correct |
2247 ms |
11968 KB |
Output is correct |
61 |
Correct |
4043 ms |
11968 KB |
Output is correct |
62 |
Correct |
1502 ms |
11968 KB |
Output is correct |
63 |
Correct |
2341 ms |
11968 KB |
Output is correct |