# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
1105679 |
2024-10-27T10:04:29 Z |
elush |
영역 (JOI16_ho_t4) |
C++14 |
|
221 ms |
41452 KB |
#include <bits/stdc++.h>
#define chkmax(a, b) a = max(a, b)
#define all(v) v.begin(), v.end()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<vi> vvi;
typedef vector<pii> vii;
set<pii> points;
set<pii> squares;
void AddPoint(int x, int y) {
points.insert({x, y});
for (int i = -1; i < 1; i++) {
for (int j = -1; j < 1; j++) {
squares.insert({x + i, y + j});
// if (x + i == -3 && y + j == 1) {
// cout << "";
// }
}
}
}
ll CountSquares(int n, int k, string route) {
int x = 0, y = 0;
AddPoint(x, y);
for (char c : route) {
if (c == 'N') x--;
else if (c == 'E') y++;
else if (c == 'S') x++;
else y--;
AddPoint(x, y);
}
if (!x && !y) {
ll ans = 0;
for (pii p : squares) {
int c = 0;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
c += points.count({p.x + i, p.y + j});
}
}
ans += c == 4;
}
return ans;
}
map<pii, vii> mp;
for (pii p : squares) {
ll startx = x ? (p.x % x + x) % x : p.x;
ll starty = y ? (p.y % y + y) % y : p.y;
ll mov = !x ? (p.y - starty) / y : (p.x - startx) / x;
startx = p.x - mov * x, starty = p.y - mov * y;
mp[{startx, starty}].push_back(p);
}
ll ans = 0;
for (auto &[p, v] : mp) {
vvi last(2, vi(2, -1));
if (x < 0 || !x && y < 0) reverse(all(v));
auto [bx, by] = v[0];
vii ranges;
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < 2; j++) {
for (int l = 0; l < 2; l++) {
if (points.count({v[i].x + j, v[i].y + l})) {
last[j][l] = i;
}
}
}
ll min_i = min({last[0][0], last[0][1], last[1][0], last[1][1]});
if (min_i == -1) continue;
ll tim = x ? (v[i].x - v[min_i].x) / x : (v[i].y - v[min_i].y) / y;
ll l = x ? (v[i].x - bx) / x : (v[i].y - by) / y;
if (tim <= k) ranges.push_back({l, l + k - tim});
}
ll last_r = -1;
for (auto [l, r] : ranges) {
if (l <= last_r && r > last_r) {
ans += r - last_r;
} else if (l > last_r) {
ans += r - l;
}
chkmax(last_r, r);
}
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie();
int n, k;
string route;
cin >> n >> k >> route;
cout << CountSquares(n, k, route);
}
Compilation message
2016_ho_t4.cpp: In function 'll CountSquares(int, int, std::string)':
2016_ho_t4.cpp:60:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
60 | for (auto &[p, v] : mp) {
| ^
2016_ho_t4.cpp:62:25: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
62 | if (x < 0 || !x && y < 0) reverse(all(v));
| ~~~^~~~~~~~
2016_ho_t4.cpp:63:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
63 | auto [bx, by] = v[0];
| ^
2016_ho_t4.cpp:65:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
2016_ho_t4.cpp:80:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
80 | for (auto [l, r] : ranges) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
744 KB |
Output is correct |
28 |
Correct |
6 ms |
848 KB |
Output is correct |
29 |
Correct |
25 ms |
4540 KB |
Output is correct |
30 |
Correct |
30 ms |
4176 KB |
Output is correct |
31 |
Correct |
171 ms |
33848 KB |
Output is correct |
32 |
Correct |
33 ms |
3408 KB |
Output is correct |
33 |
Correct |
49 ms |
7508 KB |
Output is correct |
34 |
Correct |
55 ms |
8264 KB |
Output is correct |
35 |
Correct |
44 ms |
7244 KB |
Output is correct |
36 |
Correct |
41 ms |
5504 KB |
Output is correct |
37 |
Correct |
40 ms |
3944 KB |
Output is correct |
38 |
Correct |
47 ms |
6756 KB |
Output is correct |
39 |
Correct |
45 ms |
7240 KB |
Output is correct |
40 |
Correct |
33 ms |
3408 KB |
Output is correct |
41 |
Correct |
36 ms |
4428 KB |
Output is correct |
42 |
Correct |
34 ms |
4424 KB |
Output is correct |
43 |
Correct |
47 ms |
7240 KB |
Output is correct |
44 |
Correct |
43 ms |
6728 KB |
Output is correct |
45 |
Correct |
37 ms |
5704 KB |
Output is correct |
46 |
Correct |
108 ms |
15196 KB |
Output is correct |
47 |
Correct |
116 ms |
17936 KB |
Output is correct |
48 |
Correct |
150 ms |
23240 KB |
Output is correct |
49 |
Correct |
221 ms |
41452 KB |
Output is correct |
50 |
Correct |
219 ms |
41416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
508 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
508 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
508 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
464 KB |
Output is correct |
49 |
Correct |
1 ms |
504 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
744 KB |
Output is correct |
28 |
Correct |
6 ms |
848 KB |
Output is correct |
29 |
Correct |
25 ms |
4540 KB |
Output is correct |
30 |
Correct |
30 ms |
4176 KB |
Output is correct |
31 |
Correct |
171 ms |
33848 KB |
Output is correct |
32 |
Correct |
33 ms |
3408 KB |
Output is correct |
33 |
Correct |
49 ms |
7508 KB |
Output is correct |
34 |
Correct |
55 ms |
8264 KB |
Output is correct |
35 |
Correct |
44 ms |
7244 KB |
Output is correct |
36 |
Correct |
41 ms |
5504 KB |
Output is correct |
37 |
Correct |
40 ms |
3944 KB |
Output is correct |
38 |
Correct |
47 ms |
6756 KB |
Output is correct |
39 |
Correct |
45 ms |
7240 KB |
Output is correct |
40 |
Correct |
33 ms |
3408 KB |
Output is correct |
41 |
Correct |
36 ms |
4428 KB |
Output is correct |
42 |
Correct |
34 ms |
4424 KB |
Output is correct |
43 |
Correct |
47 ms |
7240 KB |
Output is correct |
44 |
Correct |
43 ms |
6728 KB |
Output is correct |
45 |
Correct |
37 ms |
5704 KB |
Output is correct |
46 |
Correct |
108 ms |
15196 KB |
Output is correct |
47 |
Correct |
116 ms |
17936 KB |
Output is correct |
48 |
Correct |
150 ms |
23240 KB |
Output is correct |
49 |
Correct |
221 ms |
41452 KB |
Output is correct |
50 |
Correct |
219 ms |
41416 KB |
Output is correct |
51 |
Correct |
1 ms |
336 KB |
Output is correct |
52 |
Correct |
2 ms |
336 KB |
Output is correct |
53 |
Correct |
1 ms |
336 KB |
Output is correct |
54 |
Correct |
1 ms |
336 KB |
Output is correct |
55 |
Correct |
1 ms |
336 KB |
Output is correct |
56 |
Correct |
1 ms |
336 KB |
Output is correct |
57 |
Correct |
1 ms |
508 KB |
Output is correct |
58 |
Correct |
1 ms |
336 KB |
Output is correct |
59 |
Correct |
1 ms |
336 KB |
Output is correct |
60 |
Correct |
1 ms |
336 KB |
Output is correct |
61 |
Correct |
1 ms |
336 KB |
Output is correct |
62 |
Correct |
1 ms |
336 KB |
Output is correct |
63 |
Correct |
1 ms |
336 KB |
Output is correct |
64 |
Correct |
1 ms |
508 KB |
Output is correct |
65 |
Correct |
1 ms |
336 KB |
Output is correct |
66 |
Correct |
1 ms |
336 KB |
Output is correct |
67 |
Correct |
1 ms |
336 KB |
Output is correct |
68 |
Correct |
1 ms |
336 KB |
Output is correct |
69 |
Correct |
1 ms |
336 KB |
Output is correct |
70 |
Correct |
1 ms |
508 KB |
Output is correct |
71 |
Correct |
1 ms |
336 KB |
Output is correct |
72 |
Correct |
1 ms |
336 KB |
Output is correct |
73 |
Correct |
1 ms |
464 KB |
Output is correct |
74 |
Correct |
1 ms |
504 KB |
Output is correct |
75 |
Correct |
1 ms |
336 KB |
Output is correct |
76 |
Correct |
4 ms |
848 KB |
Output is correct |
77 |
Correct |
4 ms |
592 KB |
Output is correct |
78 |
Correct |
34 ms |
5968 KB |
Output is correct |
79 |
Correct |
102 ms |
19528 KB |
Output is correct |
80 |
Correct |
40 ms |
4692 KB |
Output is correct |
81 |
Correct |
38 ms |
4220 KB |
Output is correct |
82 |
Correct |
48 ms |
6228 KB |
Output is correct |
83 |
Correct |
35 ms |
3664 KB |
Output is correct |
84 |
Correct |
50 ms |
6984 KB |
Output is correct |
85 |
Correct |
50 ms |
6984 KB |
Output is correct |
86 |
Correct |
164 ms |
26580 KB |
Output is correct |
87 |
Correct |
54 ms |
8520 KB |
Output is correct |
88 |
Correct |
45 ms |
5968 KB |
Output is correct |
89 |
Correct |
46 ms |
6236 KB |
Output is correct |
90 |
Correct |
39 ms |
4176 KB |
Output is correct |
91 |
Correct |
46 ms |
7324 KB |
Output is correct |
92 |
Correct |
47 ms |
7504 KB |
Output is correct |
93 |
Correct |
50 ms |
7784 KB |
Output is correct |
94 |
Correct |
39 ms |
4944 KB |
Output is correct |
95 |
Correct |
43 ms |
5456 KB |
Output is correct |
96 |
Correct |
116 ms |
15180 KB |
Output is correct |
97 |
Correct |
119 ms |
17736 KB |
Output is correct |
98 |
Correct |
180 ms |
24244 KB |
Output is correct |
99 |
Correct |
221 ms |
41288 KB |
Output is correct |
100 |
Correct |
151 ms |
27976 KB |
Output is correct |