Submission #737083

#TimeUsernameProblemLanguageResultExecution timeMemory
737083becaidoGame (APIO22_game)C++17
100 / 100
1598 ms144176 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include <bits/stdc++.h> using namespace std; #ifndef WAIMAI #include "game.h" #endif #ifdef WAIMAI #define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE) void dout() {cout << '\n';} template<typename T, typename...U> void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);} #else #define debug(...) 7122 #endif #define ll long long #define Waimai ios::sync_with_stdio(false), cin.tie(0) #define FOR(x,a,b) for (int x = a, I = b; x <= I; x++) #define pb emplace_back #define F first #define S second const int SIZE = 3e5 + 5; int n, k; int l[SIZE], r[SIZE]; vector<int> adj[SIZE], rev[SIZE]; void init(int N, int K) { n = N, k = K; FOR (i, 0, k - 1) l[i] = r[i] = i; FOR (i, k, n - 1) l[i] = -1, r[i] = k; } bool upd(int a, int b) { if (l[a] >= r[b]) return 1; int mid = (l[a] + r[a]) >> 1; if (r[b] <= mid) { r[a] = mid; for (int p : adj[a]) if (upd(a, p)) return 1; for (int p : rev[a]) if (upd(p, a)) return 1; } mid = (l[b] + r[b]) >> 1; if (l[a] > mid) { l[b] = mid + 1; for (int p : adj[b]) if (upd(b, p)) return 1; for (int p : rev[b]) if (upd(p, b)) return 1; } return 0; } int add_teleporter(int a, int b) { if (max(a, b) < k && a >= b) return 1; adj[a].pb(b); rev[b].pb(a); return upd(a, b); } #ifdef WAIMAI namespace { int read_int() { int x; if (scanf("%d", &x) != 1) { fprintf(stderr, "Error while reading input\n"); exit(1); } return x; } } // namespace int main() { int N = read_int(); int M = read_int(); int K = read_int(); std::vector<int> u(M), v(M); for (int i = 0; i < M; ++i) { u[i] = read_int(); v[i] = read_int(); } init(N, K); int i; for (i = 0; i < M; ++i) { int answer = add_teleporter(u[i], v[i]); if (answer != 0 && answer != 1) { i = -1; break; } else if (answer == 1) { break; } } printf("%d\n", i); return 0; } #endif
#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...