#include "hexagon.h"
#include <vector>
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
#include <cstdlib>
#include <cstdint>
using namespace std;
#define ll long long
#define f first
//#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
const int inf=1e9,minf=-1e9,mod=1e9+7;
map<pii,bool>mp;
pii go(int x){
//diagonal =row
if(x==1)return {-1,0};//go up by 1 row
if(x==2)return {0,1};//go right 1 col
if(x==3)return {1,1};//go down by 1 row and right 1 col
if(x==4)return {1,0};//go down by 1 row
if(x==5)return {0,-1};//go left by 1 col
if(x==6)return {-1,-1};//go up by one and go left
}
void add(pii &x,pii a){x={x.f+a.f,x.s+a.s};}
int draw_territory(int n, int a, int b,std::vector<int> d, std::vector<int> l) {
ll x=0;
for(auto i:l)x+=i;
if(n==3){
int x=l[0],nx=d[0];
for(auto i:l)if(x!=i)assert(0);
for(auto i:d){
if(i!=nx)assert(0);
nx=(i+2)%6;
if(nx==0)nx=6;
}
ll sum=0;
for(int i=1;i<=n;i++)sum=(sum+(b*((i-1)*(i)))%mod+(a*i)%mod)%mod;
return sum;
}
if(x>2000)assert(0);
pii cur={0,0};
vector<pii>path;
path.pb(cur);
int mnx=inf,mny=inf;
for(int i=0;i<n;i++){
pii di=go(d[i]);
for(int j=0;j<l[i];j++)add(cur,di),path.pb(cur);
}
for(auto i:path)mnx=min(mnx,i.f),mny=min(mny,i.s);
if(mnx<0)mnx=-mnx;
else mnx=0;
if(mny<0)mny=-mny;
else mny=0;
for(auto &i:path)i.f+=mnx+1,i.s+=mny+1;
vector<vector<int>>grid(4004,vector<int>(4004,0)),dist(4004,vector<int>(4004,inf));
vector<vector<bool>>vis(4004,vector<bool>(4004,0));
int mxx=0,mxy=0;
for(auto i:path)grid[i.f][i.s]=1,mxx=max(mxx,i.f),mxy=max(mxy,i.s);
queue<pii>q;
q.push({0,0});
while(!q.empty()){
pii cc=q.front();
q.pop();
for(int i=1;i<=6;i++){
pii nx=cc;
add(nx,go(i));
if(nx.f<0||nx.s<0||nx.f>mxx||nx.s>mxy)continue;
if(grid[nx.f][nx.s]||vis[nx.f][nx.s])continue;
vis[nx.f][nx.s]=1;
q.push({nx.f,nx.s});
}
}
q.push({mnx+1,mny+1});
dist[mnx+1][mny+1]=0;
ll ans=0;
while(!q.empty()){
pii cc=q.front();
q.pop();
if(vis[cc.f][cc.s])continue;
vis[cc.f][cc.s]=1;
ans=(ans+(a+(b*dist[cc.f][cc.s])%mod)%mod)%mod;
for(int i=1;i<=6;i++){
pii nx=cc;
add(nx,go(i));
if(nx.f<0||nx.s<0||nx.f>mxx||nx.s>mxy)continue;
if(vis[nx.f][nx.s]||dist[nx.f][nx.s]<dist[cc.f][cc.s]+1)continue;
dist[nx.f][nx.s]=dist[cc.f][cc.s]+1;
q.push({nx.f,nx.s});
}
}
return ans;
}/*
int32_t main(){
int n,a,b;cin>>n>>a>>b;
vector<int>d(n),l(n);
for(int i=0;i<n;i++)cin>>d[i];
for(int i=0;i<n;i++)cin>>l[i];
cout<<draw_territory(n,a,b,d,l);
return 0;
}*/
/*
17 2 3
1 2 3 4 5 4 3 2 1 6 2 3 4 5 6 6 1
1 2 2 1 1 1 1 2 3 2 3 1 6 3 3 2 1
*/
Compilation message
hexagon.cpp: In function 'std::pair<int, int> go(int)':
hexagon.cpp:49:1: warning: control reaches end of non-void function [-Wreturn-type]
49 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
128224 KB |
Output is correct |
2 |
Incorrect |
91 ms |
128420 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
1004 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
128288 KB |
Output is correct |
2 |
Incorrect |
72 ms |
128284 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
128340 KB |
Output is correct |
2 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |