Submission #980433

#TimeUsernameProblemLanguageResultExecution timeMemory
980433vjudge1Hexagonal Territory (APIO21_hexagon)C++17
21 / 100
2100 ms369392 KiB
#include "hexagon.h" #include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long pw(long long x, long long n) { long long res = 1; while (n > 0) { if (n & 1) { res = res * x % mod; } n /= 2; x = x * x % mod; } return res; } int dx[6] = {-1, -1, 0, 1, 1, 0}; int dy[6] = {-1, 0, 1, 1, 0, -1}; int draw_territory(int N, int A, int B, std::vector<int> D, std::vector<int> L) { long long X = 0, Y = 0; if (N == 3) { assert (L[0] == L[1]); assert (L[1] == L[2]); long long x = L[0] + 1; X = x * (x + 1) / 2; Y = x * (x + 1) % mod * (2 * x + 1) % mod * pw(6, mod - 2) - X; } else { vector<pair<int, int>> p; set<pair<int, int>> fucked; int x = 0, y = 0; for (int i = 0; i < N; i++) { int dir = D[i] - 1; for (int j = 0; j < L[i]; j++) { x += dx[dir]; y += dy[dir]; p.push_back({x, y}); for (int h = 0; h < 6; h++) { fucked.insert({x + dx[h], y + dy[h]}); } } } for (auto xi: p) { fucked.erase(xi); } set<pair<int, int>> outers; queue<pair<int, int>> q; q.push(*fucked.begin()); outers.insert(*fucked.begin()); while (!q.empty()) { int x = q.front().first; int y = q.front().second; q.pop(); for (int i = 0; i < 6; i++) { int nx = x + dx[i]; int ny = y + dy[i]; if (fucked.find({nx, ny}) == fucked.end()) { continue; } else if (outers.find({nx, ny}) == outers.end()) { outers.insert({nx, ny}); q.push({nx, ny}); } } } for (auto xi: p) { int x = xi.first; int y = xi.second; if (outers.find({x, y - 1}) != outers.end()) { X -= y - 1; } if (outers.find({x, y + 1}) != outers.end()) { X += y; } } } X %= mod; Y %= mod; long long res = X * A % mod + Y * B % mod; res = (res % mod + mod) % mod; return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...