제출 #709402

#제출 시각아이디문제언어결과실행 시간메모리
709402600Mihnea게임 (APIO22_game)C++17
100 / 100
2610 ms213412 KiB
#include "game.h" #include <cmath> #include <functional> #include <fstream> #include <iostream> #include <vector> #include <algorithm> #include <string> #include <set> #include <map> #include <list> #include <time.h> #include <math.h> #include <random> #include <deque> #include <queue> #include <unordered_map> #include <unordered_set> #include <iomanip> #include <cassert> #include <bitset> #include <sstream> #include <chrono> #include <cstring> #include <numeric> using namespace std; const int INF = (int)1e9 + 7; int n; int k; vector<int> prec; vector<vector<int>> g, ig; vector<pair<int, int>> range; void init(int nn, int kk) { n = nn; k = kk; g.clear(); ig.clear(); prec.clear(); range.clear(); g.resize(n + 1); ig.resize(n + 1); range.resize(n + 1); prec.resize(n + 1); for (int i = 1; i <= n; i++) { range[i] = { 0, k + 1 }; prec[i] = (1 << 20); //prec[i] = 1; } } int upd(int from, int to); int test(int v) { if (prec[v] == 1) return 0; if (range[v].first / prec[v] == range[v].second / prec[v]) { assert(prec[v] >= 2); assert(prec[v] % 2 == 0); prec[v] /= 2; for (auto& vec : g[v]) { if (upd(v, vec)) return 1; } for (auto& vec : ig[v]) { if (upd(vec, v)) return 1; } } return 0; } int upd(int from, int to) { { int val = (from <= k) ? (from) : range[from].first; if (val/prec[to] > range[to].first/prec[to]) { range[to].first = val; for (auto& vertex : g[to]) { if (upd(to, vertex)) { return 1; } } } } { int val = (to <= k) ? (to) : range[to].second; if (val/prec[from] < range[from].second/prec[from]) { range[from].second = val; for (auto& vertex : ig[from]) { if (upd(vertex, from)) { return 1; } } } } if (test(from)) return 1; if (test(to)) return 1; if (range[from].first >= range[from].second) return 1; if (range[to].first >= range[to].second) return 1; return 0; } int add_teleporter(int from, int to) { from++; to++; assert(1 <= from && from <= n); assert(1 <= to && to <= n); g[from].push_back(to); ig[to].push_back(from); if (from >= to && from <= k) return 1; if (from == to) return 0; return upd(from, to); }
#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...