Submission #692271

# Submission time Handle Problem Language Result Execution time Memory
692271 2023-02-01T09:17:10 Z Dan4Life Hexagonal Territory (APIO21_hexagon) C++17
9 / 100
1208 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, 0, 1, 1, 0, -1};
int dy[] = {0, 1, 1, 0, -1, -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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 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 0 ms 212 KB Output is correct
9 Correct 0 ms 212 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
# Verdict Execution time Memory Grader output
1 Correct 231 ms 228580 KB Output is correct
2 Incorrect 209 ms 210456 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 32 ms 47340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 33 ms 47400 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 216 ms 228540 KB Output is correct
2 Incorrect 211 ms 210404 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 Runtime error 1208 ms 1048576 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 226 ms 228556 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 209 ms 210452 KB Output isn't correct
7 Halted 0 ms 0 KB -