Submission #594077

# Submission time Handle Problem Language Result Execution time Memory
594077 2022-07-12T05:02:14 Z 박상훈(#8431) None (JOI16_ho_t4) C++17
38 / 100
1000 ms 16136 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
set<pair<int, int>> visited, made;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, -1, 0, 1}, cc[1234];
char s[100100];

bool ok(int x, int y){
    return visited.find(make_pair(x, y))!=visited.end();
}

int _make(int x, int y){
    if (made.find(make_pair(x, y))!=made.end()) return 0;
    if (ok(x, y) && ok(x+1, y) && ok(x, y+1) && ok(x+1, y+1)){
        made.emplace(x, y);
        return 1;
    }
    return 0;
}

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    scanf("%s", s+1);

    cc['E'] = 0, cc['S'] = 1, cc['W'] = 2, cc['N'] = 3;

    int prv = 1e9, x = 0, y = 0, c = 0;
    ll ans = 0;

    visited.emplace(0, 0);
    while(k){
        int cnt = 0;
        for (int i=1;i<=n;i++){
            x += dx[cc[s[i]]], y += dy[cc[s[i]]];
            visited.emplace(x, y);
            cnt += _make(x, y);
            cnt += _make(x, y-1);
            cnt += _make(x-1, y);
            cnt += _make(x-1, y-1);
        }
        ans += cnt;
        --k;
        ++c;
        if (c>1000) break;
        //if (prv==cnt) break;
        prv = cnt;
        //printf("%d\n", cnt);
    }

    ans += (ll)prv * k;
    printf("%lld\n", ans);
    return 0;
}

Compilation message

2016_ho_t4.cpp: In function 'int main()':
2016_ho_t4.cpp:36:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   36 |             x += dx[cc[s[i]]], y += dy[cc[s[i]]];
      |                        ~~~^
2016_ho_t4.cpp:36:46: warning: array subscript has type 'char' [-Wchar-subscripts]
   36 |             x += dx[cc[s[i]]], y += dy[cc[s[i]]];
      |                                           ~~~^
2016_ho_t4.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
2016_ho_t4.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%s", s+1);
      |     ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 9 ms 528 KB Output is correct
29 Correct 29 ms 1396 KB Output is correct
30 Correct 37 ms 1484 KB Output is correct
31 Correct 61 ms 4508 KB Output is correct
32 Correct 52 ms 1984 KB Output is correct
33 Correct 54 ms 2264 KB Output is correct
34 Correct 54 ms 2400 KB Output is correct
35 Correct 54 ms 2208 KB Output is correct
36 Correct 53 ms 2024 KB Output is correct
37 Correct 54 ms 2196 KB Output is correct
38 Correct 57 ms 2140 KB Output is correct
39 Correct 55 ms 2208 KB Output is correct
40 Correct 52 ms 2048 KB Output is correct
41 Correct 53 ms 1864 KB Output is correct
42 Correct 44 ms 1624 KB Output is correct
43 Correct 59 ms 2460 KB Output is correct
44 Correct 53 ms 2140 KB Output is correct
45 Correct 52 ms 1872 KB Output is correct
46 Correct 56 ms 2724 KB Output is correct
47 Correct 66 ms 2732 KB Output is correct
48 Correct 61 ms 5068 KB Output is correct
49 Correct 63 ms 5004 KB Output is correct
50 Correct 64 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 24 ms 1492 KB Output is correct
27 Correct 5 ms 312 KB Output is correct
28 Correct 28 ms 2120 KB Output is correct
29 Correct 1 ms 304 KB Output is correct
30 Correct 22 ms 1072 KB Output is correct
31 Correct 27 ms 1216 KB Output is correct
32 Correct 47 ms 2464 KB Output is correct
33 Correct 34 ms 2120 KB Output is correct
34 Correct 26 ms 1700 KB Output is correct
35 Correct 32 ms 2320 KB Output is correct
36 Correct 28 ms 1336 KB Output is correct
37 Correct 34 ms 2352 KB Output is correct
38 Correct 28 ms 1400 KB Output is correct
39 Correct 26 ms 1324 KB Output is correct
40 Correct 9 ms 304 KB Output is correct
41 Correct 23 ms 1192 KB Output is correct
42 Correct 8 ms 308 KB Output is correct
43 Correct 38 ms 2136 KB Output is correct
44 Correct 20 ms 980 KB Output is correct
45 Correct 31 ms 1620 KB Output is correct
46 Correct 19 ms 488 KB Output is correct
47 Correct 31 ms 1332 KB Output is correct
48 Correct 57 ms 2460 KB Output is correct
49 Correct 17 ms 488 KB Output is correct
50 Correct 27 ms 2528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 9 ms 528 KB Output is correct
29 Correct 29 ms 1396 KB Output is correct
30 Correct 37 ms 1484 KB Output is correct
31 Correct 61 ms 4508 KB Output is correct
32 Correct 52 ms 1984 KB Output is correct
33 Correct 54 ms 2264 KB Output is correct
34 Correct 54 ms 2400 KB Output is correct
35 Correct 54 ms 2208 KB Output is correct
36 Correct 53 ms 2024 KB Output is correct
37 Correct 54 ms 2196 KB Output is correct
38 Correct 57 ms 2140 KB Output is correct
39 Correct 55 ms 2208 KB Output is correct
40 Correct 52 ms 2048 KB Output is correct
41 Correct 53 ms 1864 KB Output is correct
42 Correct 44 ms 1624 KB Output is correct
43 Correct 59 ms 2460 KB Output is correct
44 Correct 53 ms 2140 KB Output is correct
45 Correct 52 ms 1872 KB Output is correct
46 Correct 56 ms 2724 KB Output is correct
47 Correct 66 ms 2732 KB Output is correct
48 Correct 61 ms 5068 KB Output is correct
49 Correct 63 ms 5004 KB Output is correct
50 Correct 64 ms 5068 KB Output is correct
51 Correct 24 ms 1492 KB Output is correct
52 Correct 5 ms 312 KB Output is correct
53 Correct 28 ms 2120 KB Output is correct
54 Correct 1 ms 304 KB Output is correct
55 Correct 22 ms 1072 KB Output is correct
56 Correct 27 ms 1216 KB Output is correct
57 Correct 47 ms 2464 KB Output is correct
58 Correct 34 ms 2120 KB Output is correct
59 Correct 26 ms 1700 KB Output is correct
60 Correct 32 ms 2320 KB Output is correct
61 Correct 28 ms 1336 KB Output is correct
62 Correct 34 ms 2352 KB Output is correct
63 Correct 28 ms 1400 KB Output is correct
64 Correct 26 ms 1324 KB Output is correct
65 Correct 9 ms 304 KB Output is correct
66 Correct 23 ms 1192 KB Output is correct
67 Correct 8 ms 308 KB Output is correct
68 Correct 38 ms 2136 KB Output is correct
69 Correct 20 ms 980 KB Output is correct
70 Correct 31 ms 1620 KB Output is correct
71 Correct 19 ms 488 KB Output is correct
72 Correct 31 ms 1332 KB Output is correct
73 Correct 57 ms 2460 KB Output is correct
74 Correct 17 ms 488 KB Output is correct
75 Correct 27 ms 2528 KB Output is correct
76 Execution timed out 1089 ms 16136 KB Time limit exceeded
77 Halted 0 ms 0 KB -