#include "hexagon.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
using ll = long long;
const int maxn = (int)2e3+100;
const ll MOD = (ll)1e9+7;
int dx[] = {-1,-1,0,1,1,0};
int dy[] = {-1,0,1,1,0,-1};
vector<pair<int,int>> v;
int x = maxn/2, y = maxn/2;
int dis[maxn][maxn];
bool vis[maxn][maxn];
ll poww(ll a, ll b){
if(b==0) return 1ll;
ll x = poww(a,b/2);
x*=x, x%=MOD;
if(b&1)x*=a,x%=MOD;
return x;
}
inline bool inrange(int i, int j){
return i>=0 and i<maxn and j>=0 and j<maxn;
}
void recur(int i, int j){
vis[i][j]=1;
for(int k = 0; k < 6; k++){
int ni = i+dx[k], nj = j+dy[k];
if(inrange(ni,nj) and !vis[ni][nj]) recur(ni,nj);
}
}
/*
17 2 3
1 1
2 2
3 2
4 1
5 1
4 1
3 1
2 2
1 3
6 2
2 3
3 1
4 6
5 3
6 3
6 2
1 1
*/
ll sum(ll i){
ll ans = i;
ans*=(i+1), ans%=MOD;
ans*=poww(2,MOD-2), ans%=MOD;
return ans;
}
ll sq(ll i){
ll ans = i;
ans*=(i+1), ans%=MOD;
ans*=(2*i+1), ans%=MOD;
ans*=poww(6,MOD-2), ans%=MOD;
return ans;
}
int draw_territory(int N, int A, int B, vector<int> D, vector<int> L) {
ll ans = 0;
if(N==3){
ll l = L[0];
return (sum(l+1)*A+((sum(l)+sq(l))%MOD)*B)%MOD;
}
memset(vis,0,sizeof(vis));
memset(dis,0,sizeof(dis));
for(int i = 0; i < N; i++)
for(int j = 0; j < L[i]; j++)
x+=dx[D[i]-1], y+=dy[D[i]-1], v.pb({x,y});
for(auto u : v) vis[u.fi][u.se]=1;
for(int i = 0; i < maxn; i++)
for(int j = 0; j <= 2; j++)
recur(j,i), recur(i,j),recur(maxn-j-1,i),recur(i,maxn-j-1);
for(auto u : v) vis[u.fi][u.se]=0;
queue<pair<int,int>> Q;
Q.push({x,y}); dis[x][y]=0; vis[x][y]=1;
while(!Q.empty()){
int x = Q.front().fi, y = Q.front().se; Q.pop();
ans+=A+dis[x][y]*B, ans%=MOD;
for(int k = 0; k < 6; k++){
int nx = x+dx[k], ny = y+dy[k];
if(inrange(nx,ny) and !vis[nx][ny]){
Q.push({nx,ny}); vis[nx][ny]=1;
dis[nx][ny] = dis[x][y]+1;
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
232 ms |
298008 KB |
Output is correct |
2 |
Incorrect |
221 ms |
294300 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
32 ms |
47448 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Runtime error |
31 ms |
47376 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
211 ms |
298012 KB |
Output is correct |
2 |
Incorrect |
212 ms |
294308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Runtime error |
1162 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
222 ms |
298044 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
219 ms |
294248 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |