Submission #707648

#TimeUsernameProblemLanguageResultExecution timeMemory
707648600MihneaGame (APIO22_game)C++17
60 / 100
4078 ms46196 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 rad; int getbucket(int x) { return x / rad; } int n, k; vector<vector<int>> g, ig; vector<int> mn, mn2,isprec; bool is; void addedge(int from, int to) { isprec[from] |= isprec[to]; g[from].push_back(to); ig[to].push_back(from); } void init(int nn, int kk) { is = 0; n = nn; k = kk; rad = sqrt(n) + 2; g.clear(); g.resize(n); ig.clear(); ig.resize(n); mn.clear(); mn.resize(n, +INF); mn2.clear(); mn2.resize(n, +INF); isprec.clear(); isprec.resize(n, 0); } void upd(int a, int value, int esteprec) { if (is) { return; } assert(esteprec == 0 || esteprec == 1); if (esteprec == 1) { if (value < mn[a]) { mn[a] = value; if (a < k && mn[a] <= a) { is = 1; return; } for (auto& b : ig[a]) { upd(b, mn[a], 1); } } return; } assert(esteprec == 0); if (value < mn2[a]) { mn2[a] = value; for (auto& b : ig[a]) { upd(b, mn2[a], 0); } if (a < k) { if (mn2[a] < getbucket(a)) { is = 1; return; } if (mn2[a] == getbucket(a)) { isprec[a] = 1; for (auto& b : g[a]) { upd(a, b, 1); } } } } } int add_teleporter(int from, int to) { addedge(from, to); if (to < k) { upd(from, to, 1); upd(from, getbucket(to), 0); } else { upd(from, mn[to], 1); upd(from, mn2[to], 0); } if (is) { return 1; } 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...