Submission #969883

#TimeUsernameProblemLanguageResultExecution timeMemory
969883RandomUserPictionary (COCI18_pictionary)C++17
126 / 140
170 ms65536 KiB
#include <bits/stdc++.h> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() //#define int long long using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; const double eps = 1e-9; struct DSU { int n, comp; vector<int> par, size; void config(int _n) { n = _n + 1; comp = _n; par.resize(n+1); size.resize(n+1, 1); for(int i=1; i<=n; i++) par[i] = i; } int get(int u) { if(u == par[u]) return u; return par[u] = get(par[u]); } bool uni(int u, int v) { u = get(u), v = get(v); if(u == v) return false; if(size[u] < size[v]) swap(u, v); size[u] += size[v]; par[v] = u; comp--; return true; } int getComp() { return comp; } int getSize(int u) { return size[get(u)]; } bool sameSet(int u, int v) { return get(u) == get(v); } }; int32_t main() { int n, m, q; cin >> n >> m >> q; vector<pii> qus(q); for(pii &x : qus) cin >> x.first >> x.second; vector<int> L(q, 1), R(q, m), ANS(q, m); bool changed = 1; stack<int> to_check[m+1]; while(changed) { changed = 0; for(int i=0; i<q; i++) { if(L[i] <= R[i]) { to_check[(L[i] + R[i]) / 2].push(i); changed = 1; } } DSU dsu; dsu.config(n); int curr = m; for(int i=1; i<=m; i++) { for(int j=curr; j<=n; j+=curr) if(j+curr <= n) dsu.uni(j, j+curr); while(!to_check[i].empty()) { int id = to_check[i].top(); to_check[i].pop(); if(dsu.sameSet(qus[id].first, qus[id].second)) ANS[id] = i, R[id] = i - 1; else L[id] = i + 1; } curr--; } } for(int &x : ANS) cout << x << '\n'; 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...