#include "hexagon.h"
#include<bits/stdc++.h>
#define ll long long int
#define f0r(i,n) for(int i = 0;i<n;i++)
#define pb push_back
using namespace std;
const ll mod = 1e9 + 7;
ll binexp(ll a, ll b){
ll r = 1;
f0r(i, 32){
if(b & (1<<i)){
r *= a;
r %= mod;
}
a *= a;
a %= mod;
}
return r;
}
void move(ll &x, ll &y, int d, int l){
if(d == 1){
y+=l;
}
else if(d == 2){
x+=l;
y+=l;
}
else if(d == 3){
x+=l;
}
else if(d == 4)y-=l;
else if(d == 5){
x-=l;
y-=l;
}
else x-=l;
}
int draw_territory(int N, int A, int B, std::vector<int> D, std::vector<int> L) {
if(B == 0){
vector<pair<ll, ll>>polygon;
polygon.pb({0,0});
ll boundary = 0;
ll x = 0;
ll y= 0;
f0r(i,N){
boundary += L[i];
boundary %= mod;
move(x, y, D[i], L[i]);
polygon.pb(make_pair(x,y));
}
//polygon.pb({0,0});
ll area = 0;
f0r(i,N){
pair<ll,ll>a = polygon[i];
pair<ll,ll>b = polygon[i+1];
area += a.first * b.second - b.first * a.second;
}
area = abs(area);
//area/=2;
ll inside = ((area - boundary)/2 + 1) % mod;
return (boundary + inside) * A % mod;
}
else{
ll n = L[0] + 1;
ll sz = n * (n + 1)/2;
sz %= mod;
n--;
ll sdist = 0;
sdist += n * (n+1) % mod;
sdist *= (2*n+1) % mod;
sdist %= mod;
sdist *= binexp(6, mod-2);
sdist %= mod;
ll b = n * (n+1) % mod;
b *= binexp(2, mod - 2);
b %= mod;
sdist += b;
sdist %= mod;
ll ans = (sz * A % mod) + (sdist * B % mod);
return ans % mod;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
436 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
352 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
352 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
1 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
4 ms |
1684 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
6 ms |
2336 KB |
Output is correct |
12 |
Correct |
6 ms |
2520 KB |
Output is correct |
13 |
Correct |
6 ms |
2512 KB |
Output is correct |
14 |
Correct |
7 ms |
2516 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
352 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
352 KB |
Output is correct |
19 |
Correct |
0 ms |
352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
352 KB |
Output is correct |
4 |
Correct |
1 ms |
864 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
352 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
864 KB |
Output is correct |
9 |
Correct |
4 ms |
1504 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
6 ms |
2520 KB |
Output is correct |
14 |
Correct |
6 ms |
2516 KB |
Output is correct |
15 |
Correct |
6 ms |
2512 KB |
Output is correct |
16 |
Correct |
6 ms |
2516 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
10 ms |
4240 KB |
Output is correct |
21 |
Correct |
2 ms |
860 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
19 ms |
5072 KB |
Output is correct |
24 |
Correct |
21 ms |
8416 KB |
Output is correct |
25 |
Correct |
22 ms |
8652 KB |
Output is correct |
26 |
Correct |
12 ms |
4556 KB |
Output is correct |
27 |
Correct |
8 ms |
3024 KB |
Output is correct |
28 |
Correct |
5 ms |
2364 KB |
Output is correct |
29 |
Correct |
25 ms |
8908 KB |
Output is correct |
30 |
Correct |
26 ms |
8896 KB |
Output is correct |
31 |
Correct |
24 ms |
8900 KB |
Output is correct |
32 |
Correct |
24 ms |
8652 KB |
Output is correct |
33 |
Correct |
12 ms |
4560 KB |
Output is correct |
34 |
Correct |
6 ms |
2516 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
352 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |