Submission #692274

#TimeUsernameProblemLanguageResultExecution timeMemory
692274Dan4LifeHexagonal Territory (APIO21_hexagon)C++17
9 / 100
1162 ms1048576 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...