답안 #692272

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
692272 2023-02-01T09:25:30 Z Dan4Life 육각형 영역 (APIO21_hexagon) C++17
9 / 100
1213 ms 1048576 KB
#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++)
        recur(0,i), recur(i,0),recur(maxn-1,i),recur(i,maxn-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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 0 ms 316 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 297932 KB Output is correct
2 Incorrect 213 ms 294308 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 35 ms 47460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Runtime error 32 ms 47408 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 214 ms 298048 KB Output is correct
2 Incorrect 218 ms 294200 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 0 ms 316 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 1213 ms 1048576 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 225 ms 298016 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 294304 KB Output isn't correct
7 Halted 0 ms 0 KB -