Submission #1239091

#TimeUsernameProblemLanguageResultExecution timeMemory
1239091justThe Potion of Great Power (CEOI20_potion)C++20
0 / 100
3063 ms327680 KiB
#include "bits/stdc++.h" using namespace std; #define vec vector #define all(x) (x).begin(), (x).end() const int inf = 1e9; using pii = pair<int, int>; int n, d, u; vec<int> h, a, b; void init(int N, int D, int H[]) { n = N, d = D; h.resize(n); for (int i = 0; i < n; i++) h[i] = H[i]; } void curseChanges(int U, int A[], int B[]) { u = U; a.resize(U); b.resize(U); for (int i = 0; i < U; i++) a[i] = A[i], b[i] = B[i]; } int question(int x, int y, int v) { set<pii> friends; for (int i = 0; i <= v; i++) { int x = a[i], y = b[i]; if (x > y) swap(x, y); auto it = friends.find({x, y}); if (it != friends.end()) friends.erase(it); else friends.insert({x, y}); } // for (auto [x, y]: friends) cerr << x << ' ' << y << endl; vec<vec<bool>> dist(n, vec<bool>(n, false)); // for (int i = 0; i < n; i++) dist[i][i] = 1; for (auto [x, y]: friends) dist[x][y] = dist[y][x] = 1; // for (int i = 0; i < n; i++) { // for (int j = 0; j < n; j++) cerr << (dist[i][j] ? 1 : 0) << ' '; // cerr << endl; // } int ans = inf; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if ((i != j || (i != x && j != y)) &&dist[x][i] && dist[j][y]) ans = min(ans, abs(h[i] - h[j])); return ans; }
#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...