#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) {
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 + 2;
ll M = p - b + 2;
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 = 0; 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;
while(!bfs.empty()) {
tie(x, y) = bfs.front();
bfs.pop();
// cout << "HERE " << x << ' ' << y << '\n' ;
res = (res + (dp[x][y]-2) * B + A) % MOD;
for (int i = 0; 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 || dp[aa][bb] > 1 ) continue;
dp[aa][bb] = dp[x][y]+1;
bfs.push({aa, bb});
}
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
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 |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
761 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Runtime error |
449 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Runtime error |
415 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |