Submission #727200

#TimeUsernameProblemLanguageResultExecution timeMemory
727200SanguineChameleonHexagonal Territory (APIO21_hexagon)C++17
20 / 100
692 ms67904 KiB
#include "hexagon.h" #include <bits/stdc++.h> using namespace std; #ifdef KAMIRULEZ const bool local = true; const int subtask = 4; #else const bool local = false; const int subtask = -1; #endif const long long mod = 1e9 + 7; const long long one_half = (mod + 1) / 2; const long long one_third = (mod + 1) / 3; const int dx[7] = {0, 0, 1, 1, 0, -1, -1}; const int dy[7] = {0, 1, 1, 0, -1, -1, 0}; int draw_territory(int N, int A, int B, vector<int> D, vector<int> L) { if (N == 3 && (!local || subtask == 1 || subtask == 2)) { int len = L[0] + 1; long long A_sum = 1LL * len * (len + 1) % mod * one_half % mod; long long B_sum = 1LL * len * (len - 1) % mod * one_half % mod + (len - 1) * len % mod * (len * 2 - 1) % mod * one_half % mod * one_third % mod; return (A_sum * A + B_sum * B) % mod; } long long L_sum = 0; for (int i = 0; i < N; i++) { L_sum += L[i]; } if (L_sum <= 2000 && (!local || subtask == 3)) { vector<vector<bool>> border(4069, vector<bool>(4069, false)); vector<vector<int>> dist(4069, vector<int>(4069, -1)); int cx = 0; int cy = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < L[i]; j++) { cx += dx[D[i]]; cy += dy[D[i]]; border[cx + 2023][cy + 2023] = true; } } deque<pair<int, int>> q = {{0, 0}}; dist[0][0] = -2; while (!q.empty()) { cx = q.front().first; cy = q.front().second; q.pop_front(); for (int d = 1; d <= 6; d++) { int nx = cx + dx[d]; int ny = cy + dy[d]; if (0 <= nx && nx < 4069 && 0 <= ny && ny < 4069 && !border[nx][ny] && dist[nx][ny] == -1) { dist[nx][ny] = -2; q.push_back({nx, ny}); } } } q.push_back({2023, 2023}); dist[2023][2023] = 0; long long res = 0; while (!q.empty()) { cx = q.front().first; cy = q.front().second; res += 1LL * B * dist[cx][cy] + A; res %= mod; q.pop_front(); for (int d = 1; d <= 6; d++) { int nx = cx + dx[d]; int ny = cy + dy[d]; if (0 <= nx && nx < 4069 && 0 <= ny && ny < 4069 && dist[nx][ny] == -1) { dist[nx][ny] = dist[cx][cy] + 1; q.push_back({nx, ny}); } } } return res; } return 0; }
#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...