답안 #980621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
980621 2024-05-12T09:25:36 Z vjudge1 육각형 영역 (APIO21_hexagon) C++17
20 / 100
351 ms 64596 KB
#include <bits/stdc++.h>
#include "hexagon.h"

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;

void norm(int &x) {
    if (x >= MOD) x -= MOD;
    if (x < 0) x += MOD;
}

struct point {
    int x;
    int y;
    point() {}
    point(int x, int y) : x(x), y(y) {} 
};
pair<int, int> directions[6] = {
    {-1, -1}, {-1, 0}, {0, +1}, {+1, +1}, {+1, 0}, {0, -1}
};

point move(point a, int dir) {
    return point(a.x + directions[dir].first, 
                a.y + directions[dir].second);
}

int sumL = 0;

namespace Third {
const int N = 2020;
int grid[2 * N][2 * N] = {};

point start = {N, N};
int cnt = 0;
int sumD = 0;
bool inside(point a) {
    return (a.x >= 0 && a.x < 2 * N && a.y >= 0 && a.y < 2 * N);
}

void coloring(point a, int color) {
    grid[a.x][a.y] = color;
    queue<point> q;
    q.push(a);
    while (!q.empty()) {
        point v = q.front();
        q.pop();
        for (int i = 0; i < 6; i++) {
            point to = move(v, i);
            if (inside(to) && !grid[to.x][to.y]) {
                grid[to.x][to.y] = color;
                q.push(to);
            }

        }
    }
}
void bfs() {
    queue<pair<point, int>> q;
    q.push({start, 0});
    grid[start.x][start.y] = 3;

    while (!q.empty()) {
        point v = q.front().first;
        int d = q.front().second;
        q.pop();
        cnt++;
        sumD += d; norm(sumD);  
        for (int i = 0; i < 6; i++) {
            point to = move(v, i);
            if (!inside(to)) continue;
            if (grid[to.x][to.y] == 1 || grid[to.x][to.y] == 2) {
                grid[to.x][to.y] = 3;
                q.push({to, d + 1});
            }
        }
    }
}
};



long long binpow(long long a, long long n, long long M) {
    long long res = 1;
    for(;n;n >>= 1) {
        if(n & 1) res = (res * a) % M;
        a = (a * a) % M;
    }
    return res;
}
int draw_territory(int n, int A, int B,
                   vector<int> D, vector<int> L) {
    
    for (int c : L) sumL += c;
    
    if (sumL <= 2000) {
        using namespace Third;
        point cur = start;

        grid[cur.x][cur.y] = 2;
        int kk = 0;
        for (int i = 0; i < n; i++) {
            D[i]--;
            while (L[i]--) {
                cur = move(cur, D[i]);
                grid[cur.x][cur.y] = 2;
            }
        }
        coloring(point(0, 0), 4);
        point p(0, 0);

        for (int i = 0; i < 2 * N; i++) {
            for (int j = 0; j < 2 * N; j++) {
                if (!grid[i][j]) {
                    coloring(point(i, j), 1);
                }
            }
        }

        bfs();
        return (1ll * cnt * A % MOD + 1ll * sumD * B % MOD) % MOD;
    }

    if (n == 3) {
        
        ll ln = L[0] + 1;
        ll c = ln * (ln + 1) / 2 % MOD;
        ll d = ln * (ln + 1) % MOD * (2 * ln + 1) % MOD * binpow(6, MOD - 2, MOD) - c;
        c %= MOD, d %= MOD;
        norm(c);
        norm(d);

        return (c * A + d * B) % MOD;
    }
    return 0;
}

Compilation message

hexagon.cpp: In function 'int draw_territory(int, int, int, std::vector<int>, std::vector<int>)':
hexagon.cpp:102:13: warning: unused variable 'kk' [-Wunused-variable]
  102 |         int kk = 0;
      |             ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 284 ms 64220 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 348 KB Output is correct
4 Correct 0 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 298 ms 64308 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 272 ms 64336 KB Output is correct
11 Correct 270 ms 64340 KB Output is correct
12 Correct 304 ms 64336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 285 ms 64168 KB Output is correct
2 Correct 279 ms 64224 KB Output is correct
3 Correct 302 ms 64340 KB Output is correct
4 Correct 297 ms 64148 KB Output is correct
5 Correct 294 ms 64332 KB Output is correct
6 Correct 296 ms 64256 KB Output is correct
7 Correct 293 ms 64364 KB Output is correct
8 Correct 302 ms 64432 KB Output is correct
9 Correct 310 ms 64116 KB Output is correct
10 Correct 293 ms 64244 KB Output is correct
11 Correct 295 ms 64268 KB Output is correct
12 Correct 291 ms 64188 KB Output is correct
13 Correct 288 ms 64360 KB Output is correct
14 Correct 292 ms 64136 KB Output is correct
15 Correct 285 ms 64236 KB Output is correct
16 Correct 295 ms 64324 KB Output is correct
17 Correct 351 ms 64144 KB Output is correct
18 Correct 291 ms 64292 KB Output is correct
19 Correct 278 ms 64216 KB Output is correct
20 Correct 298 ms 64332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 600 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 289 ms 64552 KB Output is correct
2 Correct 294 ms 64408 KB Output is correct
3 Correct 287 ms 64128 KB Output is correct
4 Correct 281 ms 64228 KB Output is correct
5 Correct 279 ms 64336 KB Output is correct
6 Correct 287 ms 64308 KB Output is correct
7 Correct 287 ms 64296 KB Output is correct
8 Correct 297 ms 64268 KB Output is correct
9 Correct 288 ms 64220 KB Output is correct
10 Correct 295 ms 64460 KB Output is correct
11 Correct 294 ms 64200 KB Output is correct
12 Correct 285 ms 64340 KB Output is correct
13 Correct 278 ms 64264 KB Output is correct
14 Correct 317 ms 64184 KB Output is correct
15 Correct 287 ms 64212 KB Output is correct
16 Correct 289 ms 64252 KB Output is correct
17 Correct 297 ms 64464 KB Output is correct
18 Incorrect 0 ms 348 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 1 ms 360 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 308 ms 64336 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 279 ms 64336 KB Output is correct
7 Correct 297 ms 64304 KB Output is correct
8 Correct 287 ms 64340 KB Output is correct
9 Correct 294 ms 64340 KB Output is correct
10 Correct 283 ms 64140 KB Output is correct
11 Correct 294 ms 64340 KB Output is correct
12 Correct 295 ms 64372 KB Output is correct
13 Correct 289 ms 64340 KB Output is correct
14 Correct 308 ms 64344 KB Output is correct
15 Correct 286 ms 64156 KB Output is correct
16 Correct 286 ms 64340 KB Output is correct
17 Correct 279 ms 64316 KB Output is correct
18 Correct 296 ms 64372 KB Output is correct
19 Correct 286 ms 64160 KB Output is correct
20 Correct 288 ms 64340 KB Output is correct
21 Correct 290 ms 64596 KB Output is correct
22 Incorrect 0 ms 344 KB Output isn't correct
23 Halted 0 ms 0 KB -