Submission #238659

#TimeUsernameProblemLanguageResultExecution timeMemory
238659VimmerPictionary (COCI18_pictionary)C++14
56 / 140
1592 ms2864 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-O3") #pragma GCC optimize("Ofast") //#pragma GCC optimize("fast-math") //#pragma GCC optimize("no-stack-protector") #define F first #define S second #define sz(x) int(x.size()) #define pb push_back #define N 100001 #define M ll(1e9 + 7) #define inf 1e9 + 1e9 using namespace std; //using namespace __gnu_pbds; typedef long double ld; typedef long long ll; typedef short int si; typedef array <int, 2> a2; //typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; int pr[N], rk[N]; int fnd(int x) {if (pr[x] != x) pr[x] = fnd(pr[x]); return pr[x];} void link(int a, int b) { if (rk[b] > rk[a]) swap(a, b); pr[b] = a; rk[a] += rk[b]; } int main() { //freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout); ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, q; cin >> n >> m >> q; for (int i = 1; i <= n; i++) {rk[i] = 1; pr[i] = i;} vector <pair <int, int> > g(q); for (int i = 0; i < q; i++) cin >> g[i].F >> g[i].S; int ans[q], kr = 0; memset(ans, 0, sizeof(ans)); for (int x = m; x >= 2 && kr < q; x--) { if (m / x == 1) for (int j = 1; j <= n / x; j++) for (int u = j + 1; u <= n / x; u++) { int a = fnd(j * x), b = fnd(u * x); if (a != b) link(a, b); } else for (int j = 2; j <= n / x; j++) { int a = fnd(j * x), b = fnd(x); if (a != b) link(a, b); } for (int i = 0; i < q; i++) if (ans[i] == 0 && fnd(g[i].F) == fnd(g[i].S)) {kr++; ans[i] = m - x + 1;} } for (int i = 0; i < q; i++) if (ans[i] == 0) ans[i] = m; for (int i = 0; i < q; i++) cout << ans[i] << endl; }
#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...