#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "hexagon.h"
const ll MOD = 1e9 + 7;
namespace TEST2 {
ll binpow(ll a, ll b) {
if (b == 0) return 1;
if (b & 1) return a*binpow(a, b-1) % MOD;
ll ret = binpow(a, b/2);
return ret*ret % MOD;
}
ll inv(ll x) {
return binpow(x, MOD-2);
}
ll sum(ll n) {
return n*(n+1) % MOD * inv(2) % MOD;
}
ll sumsq(ll n) {
return n * (2*n+1) % MOD * (n+1) % MOD * inv(6) % MOD;
}
int solve(int n, int A, int B, VI D, VI L) {
ll x = L[0]+1;
ll mas1 = sum(x) * A % MOD;
ll mas2 = (sumsq(x) + MOD-sum(x))%MOD * B % MOD;
return (mas1 + mas2) % MOD;
}
}
namespace TEST3 {
int table[5000][5000];
int dist[5000][5000];
VPI harevan(int i, int j) {
VPI ret;
ret.pb({i-1, j});
ret.pb({i, j+1});
ret.pb({i+1, j+1});
ret.pb({i+1, j});
ret.pb({i, j-1});
ret.pb({i-1, j-1});
return ret;
}
void dfs(int i, int j) {
table[i][j] = 3;
for (auto[vi, vj] : harevan(i, j)) if (table[vi][vj] == 2) {
dfs(vi, vj);
}
}
int solve(int n, int A, int B, VI D, VI L) {
int ui = 2500, uj = 2500;
rep(i, n) {
int dir = D[i]-1;
rep(j, L[i]) {
auto[vi, vj] = harevan(ui, uj)[dir];
table[ui][uj] = 1;
ui = vi;
uj = vj;
}
}
int lmi, lmj = 1e9;
replr(i, 1, 4998) replr(j, 1, 4998) if (table[i][j] == 1) {
for (auto[vi, vj] : harevan(i, j)) {
if (table[vi][vj] == 1) continue;
if (vj < lmj) {
lmi = vi;
lmj = vj;
}
table[vi][vj] = 2;
}
}
dfs(lmi, lmj);
replr(i, 1, 4998) replr(j, 1, 4998) if (table[i][j] < 3) table[i][j] = 0;
replr(i, 0, 4999) replr(j, 0, 4999) dist[i][j] = 2e9;
queue<PII> q;
q.push({2500, 2500});
dist[2500][2500] = 0;
VI ans{0};
while (q.size()) {
auto[ui, uj] = q.front();
q.pop();
for (auto[vi, vj] : harevan(ui, uj)) if (table[vi][vj] == 0 && dist[vi][vj] == 2e9) {
dist[vi][vj] = dist[ui][uj]+1;
ans.pb(dist[vi][vj]);
q.push({vi, vj});
}
}
ll ret = 0;
for (int x : ans) {
ll cur = (A + 1ll * x * B) % MOD;
ret += cur;
ret %= MOD;
}
return ret;
}
}
namespace TEST5 {
template<class T>
struct POINT {
T x, y;
};
template<class T>
POINT<T> perp(POINT<T> a) {
return {-a.y, a.x};
}
template<class T>
POINT<T> operator+(POINT<T> a, POINT<T> b) {
return {a.x + b.x, a.y + b.y};
}
template<class T>
POINT<T> operator-(POINT<T> a, POINT<T> b) {
return {a.x - b.x, a.y - b.y};
}
template<class T>
T operator*(POINT<T> a, POINT<T> b) {
return a.x*b.x + a.y*b.y;
}
template<class T>
T operator^(POINT<T> a, POINT<T> b) {
return perp(a) * b;
}
template<class T>
T ccw(POINT<T> a, POINT<T> b, POINT<T> c) {
return (b-a)^(c-a);
}
int solve(int n, int AK, int BK, VI D, VI L) {
ll B = 0;
for (int x : L) B += x;
vector<POINT<ll>> polygon;
polygon.pb({0, 0});
rep(i, n) {
auto[x, y] = polygon.back();
int l = L[i];
if (D[i] == 1) x -= l;
else if (D[i] == 2) y += l;
else if (D[i] == 3) x += l, y += l;
else if (D[i] == 4) x += l;
else if (D[i] == 5) y -= l;
else if (D[i] == 6) x -= l, y -= l;
polygon.pb({x, y});
}
/* for (auto[x, y] : polygon) cout << x << " " << y << endl; */
ll S = 0;
rep(i, n) {
S += ccw(polygon[0], polygon[i], polygon[i+1]);
}
S = abs(S);
ll I = (S-B+2)/2;
/* cout << "B: " << B << endl; */
/* cout << "I: " << I << endl; */
return (I+B)%MOD * AK % MOD;
}
}
int draw_territory(int n, int A, int B, VI D, VI L) {
if (n == 3) return TEST2::solve(n, A, B, D, L);
if (B == 0) return TEST5::solve(n, A, B, D, L);
return TEST3::solve(n, A, B, D, L);
}
Compilation message
hexagon.cpp: In function 'void TEST3::dfs(int, int)':
hexagon.cpp:74:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
74 | for (auto[vi, vj] : harevan(i, j)) if (table[vi][vj] == 2) {
| ^
hexagon.cpp: In function 'int TEST3::solve(int, int, int, VI, VI)':
hexagon.cpp:83:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
83 | auto[vi, vj] = harevan(ui, uj)[dir];
| ^
hexagon.cpp:91:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
91 | for (auto[vi, vj] : harevan(i, j)) {
| ^
hexagon.cpp:108:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
108 | auto[ui, uj] = q.front();
| ^
hexagon.cpp:110:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
110 | for (auto[vi, vj] : harevan(ui, uj)) if (table[vi][vj] == 0 && dist[vi][vj] == 2e9) {
| ^
hexagon.cpp: In function 'int TEST5::solve(int, int, int, VI, VI)':
hexagon.cpp:165:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
165 | auto[x, y] = polygon.back();
| ^
hexagon.cpp: In function 'int TEST3::solve(int, int, int, VI, VI)':
hexagon.cpp:100:6: warning: 'lmi' may be used uninitialized in this function [-Wmaybe-uninitialized]
100 | dfs(lmi, lmj);
| ~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
1 ms |
428 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
195880 KB |
Output is correct |
2 |
Correct |
79 ms |
196556 KB |
Output is correct |
3 |
Correct |
78 ms |
196252 KB |
Output is correct |
4 |
Correct |
82 ms |
196172 KB |
Output is correct |
5 |
Correct |
76 ms |
196296 KB |
Output is correct |
6 |
Correct |
73 ms |
196184 KB |
Output is correct |
7 |
Correct |
72 ms |
196112 KB |
Output is correct |
8 |
Correct |
70 ms |
196008 KB |
Output is correct |
9 |
Correct |
72 ms |
196432 KB |
Output is correct |
10 |
Correct |
71 ms |
196092 KB |
Output is correct |
11 |
Correct |
73 ms |
196148 KB |
Output is correct |
12 |
Correct |
83 ms |
197388 KB |
Output is correct |
13 |
Correct |
81 ms |
196884 KB |
Output is correct |
14 |
Correct |
84 ms |
197392 KB |
Output is correct |
15 |
Correct |
70 ms |
196176 KB |
Output is correct |
16 |
Correct |
70 ms |
196116 KB |
Output is correct |
17 |
Correct |
74 ms |
195924 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
964 KB |
Output is correct |
7 |
Correct |
5 ms |
1944 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
9 ms |
2772 KB |
Output is correct |
12 |
Correct |
7 ms |
2772 KB |
Output is correct |
13 |
Correct |
7 ms |
2656 KB |
Output is correct |
14 |
Correct |
8 ms |
3028 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
500 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
5 ms |
1752 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
7 ms |
2768 KB |
Output is correct |
14 |
Correct |
9 ms |
2968 KB |
Output is correct |
15 |
Correct |
7 ms |
2772 KB |
Output is correct |
16 |
Correct |
7 ms |
3028 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
13 ms |
5072 KB |
Output is correct |
21 |
Correct |
2 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
500 KB |
Output is correct |
23 |
Correct |
17 ms |
5744 KB |
Output is correct |
24 |
Correct |
26 ms |
9920 KB |
Output is correct |
25 |
Correct |
27 ms |
10992 KB |
Output is correct |
26 |
Correct |
18 ms |
5260 KB |
Output is correct |
27 |
Correct |
10 ms |
3540 KB |
Output is correct |
28 |
Correct |
7 ms |
2772 KB |
Output is correct |
29 |
Correct |
30 ms |
11208 KB |
Output is correct |
30 |
Correct |
30 ms |
10944 KB |
Output is correct |
31 |
Correct |
30 ms |
11580 KB |
Output is correct |
32 |
Correct |
29 ms |
10936 KB |
Output is correct |
33 |
Correct |
22 ms |
5324 KB |
Output is correct |
34 |
Correct |
7 ms |
2772 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
344 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
195832 KB |
Output is correct |
2 |
Correct |
77 ms |
196512 KB |
Output is correct |
3 |
Correct |
87 ms |
196436 KB |
Output is correct |
4 |
Correct |
75 ms |
196176 KB |
Output is correct |
5 |
Correct |
70 ms |
196276 KB |
Output is correct |
6 |
Correct |
72 ms |
196312 KB |
Output is correct |
7 |
Correct |
74 ms |
196280 KB |
Output is correct |
8 |
Correct |
74 ms |
195996 KB |
Output is correct |
9 |
Correct |
74 ms |
196000 KB |
Output is correct |
10 |
Correct |
73 ms |
196100 KB |
Output is correct |
11 |
Correct |
74 ms |
196172 KB |
Output is correct |
12 |
Correct |
98 ms |
197392 KB |
Output is correct |
13 |
Correct |
83 ms |
196968 KB |
Output is correct |
14 |
Correct |
83 ms |
197456 KB |
Output is correct |
15 |
Correct |
69 ms |
196128 KB |
Output is correct |
16 |
Correct |
70 ms |
196120 KB |
Output is correct |
17 |
Correct |
71 ms |
195984 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
3 ms |
1056 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
968 KB |
Output is correct |
24 |
Correct |
7 ms |
1752 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
7 ms |
2880 KB |
Output is correct |
29 |
Correct |
7 ms |
2772 KB |
Output is correct |
30 |
Correct |
7 ms |
2836 KB |
Output is correct |
31 |
Correct |
11 ms |
2988 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Runtime error |
47 ms |
100436 KB |
Execution killed with signal 11 |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
396 KB |
Output is correct |
5 |
Runtime error |
46 ms |
100604 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
196044 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
79 ms |
196580 KB |
Output is correct |
7 |
Correct |
72 ms |
196684 KB |
Output is correct |
8 |
Correct |
71 ms |
196180 KB |
Output is correct |
9 |
Correct |
69 ms |
196180 KB |
Output is correct |
10 |
Correct |
70 ms |
196308 KB |
Output is correct |
11 |
Correct |
71 ms |
196192 KB |
Output is correct |
12 |
Correct |
75 ms |
195976 KB |
Output is correct |
13 |
Correct |
86 ms |
196028 KB |
Output is correct |
14 |
Correct |
73 ms |
196088 KB |
Output is correct |
15 |
Correct |
71 ms |
196196 KB |
Output is correct |
16 |
Correct |
82 ms |
197392 KB |
Output is correct |
17 |
Correct |
101 ms |
197188 KB |
Output is correct |
18 |
Correct |
94 ms |
197388 KB |
Output is correct |
19 |
Correct |
69 ms |
196180 KB |
Output is correct |
20 |
Correct |
71 ms |
195884 KB |
Output is correct |
21 |
Correct |
69 ms |
196020 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
2 ms |
860 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
964 KB |
Output is correct |
28 |
Correct |
5 ms |
1752 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
7 ms |
2940 KB |
Output is correct |
33 |
Correct |
10 ms |
2772 KB |
Output is correct |
34 |
Correct |
7 ms |
2664 KB |
Output is correct |
35 |
Correct |
8 ms |
3024 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
19 ms |
4828 KB |
Output is correct |
40 |
Correct |
2 ms |
1112 KB |
Output is correct |
41 |
Correct |
1 ms |
604 KB |
Output is correct |
42 |
Correct |
17 ms |
5876 KB |
Output is correct |
43 |
Correct |
26 ms |
10700 KB |
Output is correct |
44 |
Correct |
31 ms |
11724 KB |
Output is correct |
45 |
Correct |
14 ms |
5328 KB |
Output is correct |
46 |
Correct |
14 ms |
3532 KB |
Output is correct |
47 |
Correct |
7 ms |
2772 KB |
Output is correct |
48 |
Correct |
30 ms |
11468 KB |
Output is correct |
49 |
Correct |
30 ms |
10796 KB |
Output is correct |
50 |
Correct |
43 ms |
11972 KB |
Output is correct |
51 |
Correct |
38 ms |
11604 KB |
Output is correct |
52 |
Correct |
14 ms |
5328 KB |
Output is correct |
53 |
Correct |
7 ms |
2772 KB |
Output is correct |
54 |
Runtime error |
48 ms |
100624 KB |
Execution killed with signal 11 |
55 |
Halted |
0 ms |
0 KB |
- |