#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "hexagon.h"
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
struct Vector {
long long x, y;
Vector operator - (const Vector& other) const {
return {x - other.x, y - other.y};
}
long long operator * (const Vector& other) const {
return x * other.y - y * other.x;
}
} P[N];
int dx[6] = {0, 1, 1, 0, -1, -1};
int dy[6] = {1, 1, 0, -1, -1, 0};
int power(int a, int n) {
int ans = 1;
for (; n; n >>= 1, a = 1LL * a * a % mod) {
if (n & 1) {
ans = 1LL * ans * a % mod;
}
}
return ans;
}
int draw_territory(int N, int A, int B, vector<int> D, vector<int> L) {
vector <Vector> P = {{0, 0}};
long long x = 0, y = 0, b = 0;
for (int i = 0; i < D.size(); ++i) {
--D[i];
x = (0LL + x + L[i] * dx[D[i]] + mod) % mod;
y = (0LL + y + L[i] * dy[D[i]] + mod) % mod;
b = (b + L[i]) % mod;
P.push_back({x, y});
}
long long S = 0;
for (int i = 1; i < P.size(); ++i) S = (S + P[i - 1] * P[i]) % mod;
S = abs(S);
long long i = ((1LL * (S - b + 2 + mod) * power(2, mod - 2)) + b) % mod;
return i * A % mod;
}
//
//int main() {
// int N, A, B;
// assert(3 == scanf("%d %d %d", &N, &A, &B));
// std::vector<int> D(N), L(N);
// for (int i = 0; i < N; ++i) {
// assert(2 == scanf("%d %d", &D[i], &L[i]));
// }
//
// int result = draw_territory(N, A, B, D, L);
// printf("%d\n", result);
// return 0;
//}
Compilation message
hexagon.cpp: In function 'int draw_territory(int, int, int, std::vector<int>, std::vector<int>)':
hexagon.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int i = 0; i < D.size(); ++i) {
| ~~^~~~~~~~~~
hexagon.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Vector>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for (int i = 1; i < P.size(); ++i) S = (S + P[i - 1] * P[i]) % mod;
| ~~^~~~~~~~~~
# |
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 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
5 |
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 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
3 ms |
832 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Incorrect |
3 ms |
852 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Incorrect |
2 ms |
852 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
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 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |