답안 #795862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795862 2023-07-27T18:13:31 Z GusterGoose27 육각형 영역 (APIO21_hexagon) C++17
36 / 100
29 ms 3416 KB
#include "hexagon.h"

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int MOD = 1e9+7;

class rad {
public:
    ll a, b; // a + bsqrt(3)
    rad() {}
    rad(ll a, ll b) : a(a), b(b) {}
};

typedef pair<rad, rad> prr;

rad operator+(rad a, rad b) {
    return rad(a.a+b.a, a.b+b.b);
}

rad operator*(rad a, rad b) {
    return rad(a.a*b.a+3*a.b*b.b, a.a*b.b+a.b*b.a);
}

// ll operator/(rad a, rad b) {
//     assert(a.a/b.a == a.b/b.b); // probably good enough even though flooring
//     return a.a/b.a;
// }

rad operator-(rad a, rad b) {
    return rad(a.a-b.a, a.b-b.b);
}

rad operator*(prr a, prr b) { // cross product
    return a.first*b.second-a.second*b.first;
}

prr operator+(prr a, prr b) {
    return prr(a.first+b.first, a.second+b.second);
}

prr operator*(prr a, int b) {
    return prr(a.first*rad(b, 0), a.second*rad(b, 0));
}

prr conv[6] = {prr(rad(0, 0), rad(2, 0)), prr(rad(0, 1), rad(1, 0)), prr(rad(0, 1), rad(-1, 0)), 
    prr(rad(0, 0), rad(-2, 0)), prr(rad(0, -1), rad(-1, 0)), prr(rad(0, -1), rad(1, 0)), };

int draw_territory(int n, int A, int B, vector<int> D, vector<int> L) {
    // the distance between hex centers is 2 => base is 2/sqrt(3)
    // => area is 6/sqrt(3) = 2sqrt(3)
    vector<int> vals({L[0], L[0]+1, 2*L[0]+4});
    ll ans = 1;
    bool a = 0;
    bool b = 0;
    for (int v: vals) {
        int num = v;
        if (!a && num % 2 == 0) {
            num /= 2;
            a = 1;
        }
        if (!b && num % 3 == 0) {
            num /= 3;
            b = 1;
        }
        ans = (ans*num)%MOD;
    }
    // assert(B == 0);
    prr cur(rad(0, 0), rad(0, 0));
    rad sum(0, 0);
    ll perim = 0;
    for (int i = 0; i < n; i++) {
        perim += L[i];
        D[i]--;
        prr nxt = cur+conv[D[i]]*L[i];
        sum = sum+(cur*nxt);
        cur = nxt;
    }
    assert(sum.a == 0);
    if (sum.b < 0) sum.b = -sum.b;
    sum = sum+rad(perim, 0)*rad(0, 2);
    ll num_elems = 1+sum.b/4;
    num_elems %= MOD;
    return ((A*num_elems)%MOD+(B*ans)%MOD)%MOD;
}
# 결과 실행 시간 메모리 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 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 304 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 4 ms 724 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 8 ms 1108 KB Output is correct
12 Correct 6 ms 980 KB Output is correct
13 Correct 6 ms 932 KB Output is correct
14 Correct 6 ms 1108 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 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 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 6 ms 1108 KB Output is correct
14 Correct 6 ms 1084 KB Output is correct
15 Correct 6 ms 980 KB Output is correct
16 Correct 7 ms 1100 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 10 ms 1444 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 14 ms 1916 KB Output is correct
24 Correct 22 ms 2936 KB Output is correct
25 Correct 29 ms 3132 KB Output is correct
26 Correct 12 ms 1652 KB Output is correct
27 Correct 8 ms 1236 KB Output is correct
28 Correct 6 ms 852 KB Output is correct
29 Correct 25 ms 3412 KB Output is correct
30 Correct 25 ms 3416 KB Output is correct
31 Correct 26 ms 3412 KB Output is correct
32 Correct 24 ms 3404 KB Output is correct
33 Correct 12 ms 1764 KB Output is correct
34 Correct 7 ms 944 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
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 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 292 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -