#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "hexagon.h"
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
struct Vector {
long long x, y;
Vector operator - (const Vector& other) const {
return {x - other.x, y - other.y};
}
long long operator * (const Vector& other) const {
return x * other.y - y * other.x;
}
} P[N];
int dx[6] = {0, 1, 1, 0, -1, -1};
int dy[6] = {1, 1, 0, -1, -1, 0};
int power(int a, int n) {
int ans = 1;
for (; n; n >>= 1, a = 1LL * a * a % mod)
if (n & 1) ans = 1LL * ans * a % mod;
return ans;
}
const int M = 4010;
int vis[M][M];
int ok[M][M], d[M][M];
int draw_territory(int N, int A, int B, vector<int> D, vector<int> L) {
if (B == 0) {
vector <Vector> P = {{0, 0}};
long long x = 0, y = 0, b = 0;
for (int i = 0; i < N; ++i) {
--D[i];
x += L[i] * dx[D[i]];
y += L[i] * dy[D[i]];
b = (b + L[i]) % mod;
P.push_back({x, y});
}
long long S = 0;
for (int i = 1; i < P.size(); ++i) S += P[i - 1] * P[i];
S = abs(S);
S %= mod;
long long i = ((1LL * (S - b + 2 + mod) * power(2, mod - 2)) + b) % mod;
return i * A % mod;
} else {
int x = 2005, y = 2005;
int delta = 0;
for (int i = 0; i < D.size(); ++i) {
--D[i];
delta += L[i];
for (int j = 0; j < L[i]; ++j) {
x += dx[D[i]];
y += dy[D[i]];
vis[x][y] = 1;
}
}
auto bfs = [&](int x, int y) {
int reach = 0;
queue <pair <int, int>> q;
q.push({x, y});
ok[x][y] = 1;
vector <pair <int, int>> s;
while (q.size()) {
auto [x, y] = q.front();
s.push_back({x, y});
ok[x][y] = 1;
q.pop();
for (int i = 0; i < 6; ++i) {
int u = x + dx[i];
int v = y + dy[i];
if (u < 0 || u >= M || v < 0 || v >= M) {
reach = 1;
continue;
}
if (vis[u][v] || ok[u][v]) continue;
ok[u][v] = 1;
q.push({u, v});
}
}
if (reach) return;
for (auto [x, y]: s) vis[x][y] = 1;
};
for (int i = 0; i < M; ++i)
for (int j = 0; j < M; ++j)
if (vis[i][j] == 0 && ok[i][j] == 0) bfs(i, j);
queue <pair <int, int>> q;
q.push({x, y});
memset(d, -1, sizeof(d));
d[x][y] = 0;
while (q.size()) {
auto [x, y] = q.front();
q.pop();
for (int i = 0; i < 6; ++i) {
int u = x + dx[i];
int v = y + dy[i];
if (vis[u][v] == 0 || d[u][v] != -1) continue;
d[u][v] = d[x][y] + 1;
q.push({u, v});
}
}
int ans = 0;
for (int i = 0; i < M; ++i)
for (int j = 0; j < M; ++j)
if (d[i][j] != -1) ans = (ans + 1LL * B * d[i][j] + A) % mod;
return ans;
}
}
//
//int main() {
// int N, A, B;
// assert(3 == scanf("%d %d %d", &N, &A, &B));
// std::vector<int> D(N), L(N);
// for (int i = 0; i < N; ++i) {
// assert(2 == scanf("%d %d", &D[i], &L[i]));
// }
//
// int result = draw_territory(N, A, B, D, L);
// printf("%d\n", result);
// return 0;
//}
//
//
Compilation message
hexagon.cpp: In function 'int draw_territory(int, int, int, std::vector<int>, std::vector<int>)':
hexagon.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Vector>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i = 1; i < P.size(); ++i) S += P[i - 1] * P[i];
| ~~^~~~~~~~~~
hexagon.cpp:62:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for (int i = 0; i < D.size(); ++i) {
| ~~^~~~~~~~~~
hexagon.cpp: In lambda function:
hexagon.cpp:78:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
78 | auto [x, y] = q.front();
| ^
hexagon.cpp:95:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
95 | for (auto [x, y]: s) vis[x][y] = 1;
| ^
hexagon.cpp: In function 'int draw_territory(int, int, int, std::vector<int>, std::vector<int>)':
hexagon.cpp:105:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
105 | auto [x, y] = q.front();
| ^
# |
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 |
# |
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 |
Runtime error |
134 ms |
82312 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
639 ms |
189472 KB |
Output is correct |
2 |
Correct |
599 ms |
190680 KB |
Output is correct |
3 |
Correct |
585 ms |
190096 KB |
Output is correct |
4 |
Correct |
572 ms |
190268 KB |
Output is correct |
5 |
Correct |
573 ms |
190768 KB |
Output is correct |
6 |
Correct |
626 ms |
190300 KB |
Output is correct |
7 |
Correct |
577 ms |
190296 KB |
Output is correct |
8 |
Correct |
567 ms |
190116 KB |
Output is correct |
9 |
Correct |
603 ms |
189740 KB |
Output is correct |
10 |
Correct |
737 ms |
189700 KB |
Output is correct |
11 |
Correct |
661 ms |
189792 KB |
Output is correct |
12 |
Correct |
655 ms |
190808 KB |
Output is correct |
13 |
Correct |
598 ms |
190812 KB |
Output is correct |
14 |
Correct |
657 ms |
190988 KB |
Output is correct |
15 |
Correct |
594 ms |
189308 KB |
Output is correct |
16 |
Correct |
689 ms |
189724 KB |
Output is correct |
17 |
Correct |
611 ms |
189368 KB |
Output is correct |
18 |
Correct |
595 ms |
191140 KB |
Output is correct |
19 |
Correct |
602 ms |
191140 KB |
Output is correct |
20 |
Correct |
587 ms |
189380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
852 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
568 KB |
Output is correct |
6 |
Correct |
3 ms |
804 KB |
Output is correct |
7 |
Correct |
7 ms |
1488 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
304 KB |
Output is correct |
11 |
Correct |
10 ms |
2252 KB |
Output is correct |
12 |
Correct |
9 ms |
2388 KB |
Output is correct |
13 |
Correct |
9 ms |
2232 KB |
Output is correct |
14 |
Correct |
12 ms |
2400 KB |
Output is correct |
15 |
Correct |
1 ms |
312 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
308 KB |
Output is correct |
19 |
Correct |
1 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
624 KB |
Output is correct |
8 |
Correct |
2 ms |
852 KB |
Output is correct |
9 |
Correct |
7 ms |
1576 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
10 ms |
2356 KB |
Output is correct |
14 |
Correct |
9 ms |
2380 KB |
Output is correct |
15 |
Correct |
8 ms |
2252 KB |
Output is correct |
16 |
Correct |
10 ms |
2360 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
15 ms |
3924 KB |
Output is correct |
21 |
Correct |
2 ms |
852 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
21 ms |
4460 KB |
Output is correct |
24 |
Correct |
33 ms |
7476 KB |
Output is correct |
25 |
Correct |
31 ms |
7544 KB |
Output is correct |
26 |
Correct |
16 ms |
4032 KB |
Output is correct |
27 |
Correct |
11 ms |
2512 KB |
Output is correct |
28 |
Correct |
8 ms |
2252 KB |
Output is correct |
29 |
Correct |
35 ms |
7912 KB |
Output is correct |
30 |
Correct |
34 ms |
7872 KB |
Output is correct |
31 |
Correct |
37 ms |
7868 KB |
Output is correct |
32 |
Correct |
37 ms |
7932 KB |
Output is correct |
33 |
Correct |
19 ms |
4096 KB |
Output is correct |
34 |
Correct |
9 ms |
2348 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
598 ms |
189316 KB |
Output is correct |
2 |
Correct |
610 ms |
190580 KB |
Output is correct |
3 |
Correct |
593 ms |
190080 KB |
Output is correct |
4 |
Correct |
594 ms |
190252 KB |
Output is correct |
5 |
Correct |
602 ms |
190660 KB |
Output is correct |
6 |
Correct |
592 ms |
190176 KB |
Output is correct |
7 |
Correct |
583 ms |
190244 KB |
Output is correct |
8 |
Correct |
590 ms |
190048 KB |
Output is correct |
9 |
Correct |
593 ms |
189596 KB |
Output is correct |
10 |
Correct |
590 ms |
189672 KB |
Output is correct |
11 |
Correct |
585 ms |
189740 KB |
Output is correct |
12 |
Correct |
605 ms |
190868 KB |
Output is correct |
13 |
Correct |
645 ms |
190808 KB |
Output is correct |
14 |
Correct |
616 ms |
191024 KB |
Output is correct |
15 |
Correct |
606 ms |
189396 KB |
Output is correct |
16 |
Correct |
594 ms |
189800 KB |
Output is correct |
17 |
Correct |
662 ms |
189492 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
3 ms |
852 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
308 KB |
Output is correct |
22 |
Correct |
2 ms |
600 KB |
Output is correct |
23 |
Correct |
2 ms |
852 KB |
Output is correct |
24 |
Correct |
6 ms |
1592 KB |
Output is correct |
25 |
Correct |
1 ms |
312 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
9 ms |
2352 KB |
Output is correct |
29 |
Correct |
10 ms |
2428 KB |
Output is correct |
30 |
Correct |
8 ms |
2380 KB |
Output is correct |
31 |
Correct |
10 ms |
2468 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Runtime error |
147 ms |
110528 KB |
Execution killed with signal 11 |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Runtime error |
125 ms |
82372 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
641 ms |
189364 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Runtime error |
124 ms |
82300 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |