답안 #979228

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
979228 2024-05-10T12:00:34 Z 8pete8 육각형 영역 (APIO21_hexagon) C++17
9 / 100
59 ms 128604 KB
#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
}
int inv(ll x){
  int ex=mod-2;
  ll ans=1;
  x%=mod;
  while(ex){
    if(ex&1)ans=(ans*x)%mod;
    x=(x*x)%mod;
    ex>>=1;
  }
  return ans;
}
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){
    ll x=l[0];
    for(auto i:l)if(x!=i)assert(0);
    x++;
    ll sum=0,sum2=0;
    //i^2-i
    //meth
    sum=((x)*((x+1)%mod*(2*x+1)%mod)%mod)%mod;
    sum=(sum*inv(6LL))%mod;
    sum2=((x)*(x+1))%mod;
    sum2=(sum2*(inv(2LL)))%mod;
    sum=(sum-sum2+mod)%mod;
    sum=(sum*b)%mod;
    sum=(sum+sum2*a)%mod;
    return sum;
  }
  if(x>2000)return 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]>>l[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 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 128360 KB Output is correct
2 Incorrect 58 ms 128604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 428 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 Incorrect 1 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 128500 KB Output is correct
2 Incorrect 59 ms 128192 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 1 ms 344 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 128336 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Incorrect 57 ms 128216 KB Output isn't correct
7 Halted 0 ms 0 KB -