#include <bits/stdc++.h>
using namespace std;
using uint = uint32_t;
constexpr uint mod = 1'000'000'007;
struct Modint{
uint num = 0;
Modint(){}
template<class T> Modint(T x): num(x % mod){}
operator int() const { return num; }
void operator+=(Modint x){
num += x.num;
if(num >= mod) num -= mod;
}
void operator-=(Modint x){
if(num < x.num) num += mod;
num -= x.num;
}
Modint operator+(Modint x) const {
Modint ans = *this;
ans += x;
return ans;
}
Modint operator-(Modint x) const {
Modint ans = *this;
ans -= x;
return ans;
}
Modint operator*(Modint x) const {
return uint((uint64_t)num * x.num % mod);
}
};
const int dx[6] = {0, 1, 1, 0, -1, -1}, dy[6] = {1, 1, 0, -1, -1, 0};
int draw_territory2(int N, int A, int B, vector<int> D, vector<int> L){
assert(L[0] == L[1] && L[1] == L[2]);
Modint n = L[0];
return (n * Modint(2 * 333333336) * Modint(B) + Modint(A)) * Modint(uint64_t(2 + n) * (1 + n) / 2);
}
int draw_territory5(int N, Modint A, Modint B, vector<int> D, vector<int> L){
const Modint sqrt3 = 82062379;
const Modint dx[6] = {0, sqrt3, sqrt3, 0, mod - sqrt3, mod - sqrt3}, dy[6] = {1, (mod + 1) / 2, mod - (mod + 1) / 2, -1, mod - (mod + 1) / 2, (mod + 1) / 2};
Modint ans = 0;
Modint x = 0, y = 0;
for(int i = 0; i < N; i++){
}
return ans * Modint(A);
}
int draw_territory6(int N, Modint A, Modint B, vector<int> D, vector<int> L){
vector<pair<int, int>> path, inside, outside;
int x = 0, y = 0;
for(int i = 0; i < N; i++){
const int d = --D[i], d1 = (d + 5) % 6, d2 = (d + 1) % 6;
while(L[i]--){
inside.emplace_back(x + dx[d1], y + dy[d1]);
outside.emplace_back(x + dx[d2], y + dy[d2]);
path.emplace_back(x += dx[d], y += dy[d]);
}
}
unordered_set point(path.begin(), path.end(), 1000000, [](pair<int, int> a){ return (uint64_t)a.first << 32 ^ a.second; });
auto rem = [&](auto& a){
a.erase(remove_if(a.begin(), a.end(), [&](auto x){ return !point.insert(x).second; }), a.end());
};
rem(inside);
rem(outside);
point.insert(inside.begin(), inside.end());
point.insert(outside.begin(), outside.end());
auto search1 = [&, i = 0]() mutable -> bool {
if(i == inside.size()) return 1;
auto [x, y] = inside[i];
for(int d = 0; d < 6; d++){
const int x2 = x + dx[d], y2 = y + dy[d];
if(point.emplace(x2, y2).second) inside.emplace_back(x2, y2);
}
i++;
return 0;
};
auto search2 = [&, i = 0]() mutable -> bool {
if(i == outside.size()) return 1;
auto [x, y] = outside[i];
for(int d = 0; d < 6; d++){
const int x2 = x + dx[d], y2 = y + dy[d];
if(point.emplace(x2, y2).second) outside.emplace_back(x2, y2);
}
i++;
return 0;
};
while(1){
if(search1()) break;
if(search2()){
swap(inside, outside);
break;
}
}
for(auto i : outside) point.erase(i);
Modint ans = 0;
queue<tuple<int, int, int>> q;
q.emplace(0, 0, 0);
point.erase({0, 0});
while(q.size()){
auto [x, y, c] = q.front();
ans += (uint64_t) B * c + A;
q.pop();
for(int d = 0; d < 6; d++){
const int x2 = x + dx[d], y2 = y + dy[d];
if(point.count({x2, y2})){
q.emplace(x2, y2, c + 1);
point.erase({x2, y2});
}
}
}
return ans;
}
int draw_territory(int N, int A, int B, vector<int> D, vector<int> L){
if(N == 3) return draw_territory2(N, A, B, D, L);
return draw_territory6(N, A, B, D, L);
}
Compilation message
hexagon.cpp: In function 'int draw_territory5(int, Modint, Modint, std::vector<int>, std::vector<int>)':
hexagon.cpp:42:18: warning: unused variable 'dx' [-Wunused-variable]
42 | const Modint dx[6] = {0, sqrt3, sqrt3, 0, mod - sqrt3, mod - sqrt3}, dy[6] = {1, (mod + 1) / 2, mod - (mod + 1) / 2, -1, mod - (mod + 1) / 2, (mod + 1) / 2};
| ^~
hexagon.cpp:42:74: warning: unused variable 'dy' [-Wunused-variable]
42 | const Modint dx[6] = {0, sqrt3, sqrt3, 0, mod - sqrt3, mod - sqrt3}, dy[6] = {1, (mod + 1) / 2, mod - (mod + 1) / 2, -1, mod - (mod + 1) / 2, (mod + 1) / 2};
| ^~
hexagon.cpp:44:12: warning: variable 'x' set but not used [-Wunused-but-set-variable]
44 | Modint x = 0, y = 0;
| ^
hexagon.cpp:44:19: warning: variable 'y' set but not used [-Wunused-but-set-variable]
44 | Modint x = 0, y = 0;
| ^
hexagon.cpp: In lambda function:
hexagon.cpp:70:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | if(i == inside.size()) return 1;
| ~~^~~~~~~~~~~~~~~~
hexagon.cpp: In lambda function:
hexagon.cpp:80:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | if(i == outside.size()) return 1;
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
216 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8524 KB |
Output is correct |
2 |
Correct |
46 ms |
12592 KB |
Output is correct |
3 |
Correct |
21 ms |
10056 KB |
Output is correct |
4 |
Correct |
12 ms |
9036 KB |
Output is correct |
5 |
Correct |
8 ms |
8780 KB |
Output is correct |
6 |
Correct |
7 ms |
8780 KB |
Output is correct |
7 |
Correct |
14 ms |
9544 KB |
Output is correct |
8 |
Correct |
7 ms |
8652 KB |
Output is correct |
9 |
Correct |
6 ms |
8652 KB |
Output is correct |
10 |
Correct |
7 ms |
8780 KB |
Output is correct |
11 |
Correct |
9 ms |
8908 KB |
Output is correct |
12 |
Correct |
119 ms |
19816 KB |
Output is correct |
13 |
Correct |
117 ms |
18700 KB |
Output is correct |
14 |
Correct |
142 ms |
20004 KB |
Output is correct |
15 |
Correct |
7 ms |
8652 KB |
Output is correct |
16 |
Correct |
7 ms |
8652 KB |
Output is correct |
17 |
Correct |
6 ms |
8652 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2083 ms |
274144 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Execution timed out |
2094 ms |
202028 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8524 KB |
Output is correct |
2 |
Correct |
46 ms |
12584 KB |
Output is correct |
3 |
Correct |
20 ms |
10032 KB |
Output is correct |
4 |
Correct |
12 ms |
9036 KB |
Output is correct |
5 |
Correct |
8 ms |
8780 KB |
Output is correct |
6 |
Correct |
7 ms |
8780 KB |
Output is correct |
7 |
Correct |
15 ms |
9548 KB |
Output is correct |
8 |
Correct |
7 ms |
8780 KB |
Output is correct |
9 |
Correct |
6 ms |
8652 KB |
Output is correct |
10 |
Correct |
8 ms |
8780 KB |
Output is correct |
11 |
Correct |
9 ms |
8908 KB |
Output is correct |
12 |
Correct |
117 ms |
19844 KB |
Output is correct |
13 |
Correct |
117 ms |
18708 KB |
Output is correct |
14 |
Correct |
136 ms |
20072 KB |
Output is correct |
15 |
Correct |
6 ms |
8652 KB |
Output is correct |
16 |
Correct |
6 ms |
8652 KB |
Output is correct |
17 |
Correct |
6 ms |
8652 KB |
Output is correct |
18 |
Execution timed out |
2089 ms |
274084 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Runtime error |
1357 ms |
1048580 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8524 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
47 ms |
12648 KB |
Output is correct |
7 |
Correct |
20 ms |
10088 KB |
Output is correct |
8 |
Correct |
10 ms |
9036 KB |
Output is correct |
9 |
Correct |
7 ms |
8780 KB |
Output is correct |
10 |
Correct |
7 ms |
8780 KB |
Output is correct |
11 |
Correct |
18 ms |
9548 KB |
Output is correct |
12 |
Correct |
7 ms |
8696 KB |
Output is correct |
13 |
Correct |
6 ms |
8652 KB |
Output is correct |
14 |
Correct |
7 ms |
8780 KB |
Output is correct |
15 |
Correct |
9 ms |
8908 KB |
Output is correct |
16 |
Correct |
117 ms |
19752 KB |
Output is correct |
17 |
Correct |
130 ms |
18732 KB |
Output is correct |
18 |
Correct |
156 ms |
19984 KB |
Output is correct |
19 |
Correct |
8 ms |
8652 KB |
Output is correct |
20 |
Correct |
7 ms |
8652 KB |
Output is correct |
21 |
Correct |
6 ms |
8652 KB |
Output is correct |
22 |
Execution timed out |
2098 ms |
274176 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |