답안 #692270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
692270 2023-02-01T09:15:26 Z Dan4Life 육각형 영역 (APIO21_hexagon) C++17
9 / 100
1244 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+10;
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){
    if(!inrange(i,j) or vis[i][j]) return;
    vis[i][j]=1;
    for(int k = 0; k < 6; k++)
        recur(i+dx[k],j+dy[k]);
}
/*
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(i,maxn-1), recur(maxn-1,i);
    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 1 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 1 ms 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 304 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 304 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 0 ms 212 KB Output is correct
8 Correct 1 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 308 KB Output is correct
12 Correct 0 ms 300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 195 ms 209724 KB Output is correct
2 Incorrect 176 ms 207068 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 27 ms 43780 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 32 ms 43684 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 209792 KB Output is correct
2 Incorrect 189 ms 207020 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Runtime error 1244 ms 1048576 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 206 ms 209792 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Incorrect 196 ms 206928 KB Output isn't correct
7 Halted 0 ms 0 KB -