#include "hexagon.h"
#include <bits/stdc++.h>
using namespace std;
#define lint long long
#define arr array
#define vct vector
#define hmap unordered_map
#define hset unordered_set
#define pll pair<lint, lint>
#define fir first
#define sec second
const lint MD = 1e9 + 7, N_NDS = 1e6 + 5;
lint n, a, b;
vct<lint> drc, lng;
lint md(lint x) { return (x + MD) % MD; }
pll mv(pll pt, lint drc, lint lng) {
pll dlt;
if (drc == 1) dlt = {0, 1};
if (drc == 2) dlt = {1, 1};
if (drc == 3) dlt = {1, 0};
if (drc == 4) dlt = {0, -1};
if (drc == 5) dlt = {-1, -1};
if (drc == 6) dlt = {-1, 0};
return {pt.fir + dlt.fir * lng, pt.sec + dlt.sec * lng};
}
vct<pll> gt_pts() {
pll pt = {0, 0};
vct<pll> ans;
for (int i = 0; i < n; i++) {
for (int j = 0; j < lng[i]; j++) {
pt = mv(pt, drc[i], 1);
ans.push_back(pt);
}
}
return ans;
}
vct<pll> nghbrs(pll pt) {
vct<pll> ans;
for (int i = 1; i <= 6; i++) ans.push_back(mv(pt, i, 1));
return ans;
}
set<pll> pt_nds, pth_nds, vs;
void dfs(pll pt) {
vs.insert(pt);
for (pll nw_pt : nghbrs(pt))
if (pt_nds.count(nw_pt) && !vs.count(nw_pt) && !pth_nds.count(nw_pt)) dfs(nw_pt);
}
hmap<lint, vct<pll>> clmns;
int n_nds;
arr<lint, N_NDS> x;
arr<pll, N_NDS> y;
lint prcmp() {
vct<pll> pts = gt_pts();
for (pll pt : pts) {
pt_nds.insert(pt), pth_nds.insert(pt);
for (pll nw_pt : nghbrs(pt)) pt_nds.insert(nw_pt);
}
// Node with minimum x coordinate should be on outside
pll mn_x;
for (pll pt : pt_nds) mn_x = min(mn_x, pt);
dfs(mn_x);
for (pll pt : pts) clmns[pt.fir].push_back(pt);
for (pair<lint, vct<pll>> clmn : clmns) {
sort(clmn.sec.begin(), clmn.sec.end());
for (pll pt : clmn.sec) {
if (vs.count({pt.fir, pt.sec - 1})) n_nds++, x[n_nds] = clmn.fir, y[n_nds] = {pt.sec, 0};
if (vs.count({pt.fir, pt.sec + 1})) y[n_nds].sec = pt.sec;
}
}
// for (int u = 1; u <= n_nds; u++) {
// cout << u << ": " << x[u] << " " << y[u].fir << " " << y[u].sec << endl;
// }
lint ans = 0;
for (int u = 1; u <= n_nds; u++) ans += y[u].sec - y[u].fir + 1;
return ans;
}
int draw_territory(int _n, int _a, int _b, vct<int> _drc, vct<int> _lng) {
n = _n, a = _a, b = _b;
for (int i = 0; i < n; i++) drc.push_back(_drc[i]), lng.push_back(_lng[i]);
lint ar = prcmp();
return md(a * ar);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
868 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
902 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
743 ms |
120036 KB |
Output is correct |
2 |
Correct |
326 ms |
73316 KB |
Output is correct |
3 |
Correct |
372 ms |
96048 KB |
Output is correct |
4 |
Correct |
303 ms |
76348 KB |
Output is correct |
5 |
Correct |
466 ms |
105404 KB |
Output is correct |
6 |
Correct |
539 ms |
121920 KB |
Output is correct |
7 |
Correct |
213 ms |
47356 KB |
Output is correct |
8 |
Correct |
488 ms |
74168 KB |
Output is correct |
9 |
Correct |
666 ms |
92856 KB |
Output is correct |
10 |
Correct |
671 ms |
94488 KB |
Output is correct |
11 |
Correct |
483 ms |
96308 KB |
Output is correct |
12 |
Correct |
498 ms |
93884 KB |
Output is correct |
13 |
Correct |
445 ms |
96820 KB |
Output is correct |
14 |
Correct |
507 ms |
72248 KB |
Output is correct |
15 |
Correct |
282 ms |
46188 KB |
Output is correct |
16 |
Correct |
385 ms |
48624 KB |
Output is correct |
17 |
Correct |
666 ms |
125048 KB |
Output is correct |
18 |
Correct |
634 ms |
124716 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
894 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
900 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |