#include "hexagon.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair <ll, ll>;
int dx[] = {0, -1, 0, 1, 1, 0, -1};
int dy[] = {0, 0, 1, 1, 0, -1, -1};
ll n, A, B;
const int MOD = 1e9 + 7;
ll power(ll a, ll b, ll p) {
ll res = 1;
while(b > 0) {
if (b & 1) res = res * a % p;
a = a * a % p;
b /= 2;
}
return res;
}
ll inv(ll a, ll p) {
return power(a, p-2, p);
}
int draw_territory(int _n, int _A, int _B, std::vector<int> d, std::vector<int> l) {
// #define int long long
n = _n;
A = _A;
B = _B;
if (n == 3) {
ll x = l[0]+1, y = l[0];
ll res = (
( (x+1) * (x) / 2 % MOD * A % MOD) +
(B *
(
(y * (y+1) / 2) % MOD +
y * (y + 1) % MOD * (2*y + 1) % MOD * inv(6, MOD) %MOD
) % MOD
) % MOD
)%MOD;
return (res % MOD + MOD) % MOD;
}
ll x, y, a, b, c, p;
x = y = a = b = c = p = 0;
for (int i = 0; i < n; i++) {
x += dx[d[i]] * l[i];
y += dy[d[i]] * l[i];
a = min(a, x);
b = min(b, y);
c = max(c, x);
p = max(p, y);
}
x = -a+1;
y = -b+1;
ll N = c - a + 1+5;
ll M = p - b + 1+5;
int dp[N][M]; memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) {
for (int j = 0; j < l[i]; j++) {
x += dx[d[i]];
y += dy[d[i]];
dp[x][y] = 1;
}
}
x = 0, y = 0;
queue <PII> bfs; bfs.push({x, y});
dp[x][y] = -1;
while(!bfs.empty()) {
tie(x, y) = bfs.front();
bfs.pop();
for (int i = 1; i <= 6; i++) {
int aa = x + dx[i];
int bb = y + dy[i];
if (aa < 0 || bb < 0 || aa >= N || bb >= M || dp[aa][bb] != 0) continue;
dp[aa][bb] = -1;
bfs.push({aa, bb});
}
}
bfs.push({-a+1, -b+1});
dp[-a+1][-b+1] = 2;
ll res = 0;
int cnt = 0;
while(!bfs.empty()) {
tie(x, y) = bfs.front();
bfs.pop();
res = (res + (dp[x][y]-2) * B % MOD + A) % MOD;
for (int i = 1; i <= 6; i++) {
int aa = x + dx[i];
int bb = y + dy[i];
if (aa < 0 || bb < 0 || aa >= N || bb >= M || (dp[aa][bb] > 1 || dp[aa][bb] < 0) ) continue;
dp[aa][bb] = dp[x][y]+1;
bfs.push({aa, bb});
}
}
return (res%MOD+MOD)%MOD;
}
Compilation message
hexagon.cpp: In function 'int draw_territory(int, int, int, std::vector<int>, std::vector<int>)':
hexagon.cpp:82:9: warning: unused variable 'cnt' [-Wunused-variable]
82 | int cnt = 0;
| ^~~
# |
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 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 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 |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
724 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
812 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
8 ms |
1200 KB |
Output is correct |
13 |
Correct |
7 ms |
1236 KB |
Output is correct |
14 |
Correct |
7 ms |
1336 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
412 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
405 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
724 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
5 ms |
852 KB |
Output is correct |
6 |
Correct |
2 ms |
428 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
9 ms |
1300 KB |
Output is correct |
13 |
Correct |
8 ms |
1336 KB |
Output is correct |
14 |
Correct |
11 ms |
1344 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Runtime error |
398 ms |
1048576 KB |
Execution killed with signal 9 |
19 |
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 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Runtime error |
431 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
724 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
852 KB |
Output is correct |
10 |
Correct |
2 ms |
436 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
8 ms |
1236 KB |
Output is correct |
17 |
Correct |
8 ms |
1328 KB |
Output is correct |
18 |
Correct |
7 ms |
1236 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
300 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Runtime error |
405 ms |
1048576 KB |
Execution killed with signal 9 |
23 |
Halted |
0 ms |
0 KB |
- |