Submission #451464

#TimeUsernameProblemLanguageResultExecution timeMemory
451464zxcvbnmPictionary (COCI18_pictionary)C++14
14 / 140
1591 ms65540 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int nax = 1005; int n, m, q; struct Edge { int to, w; }; int gcd(int a, int b) { while(b) { a %= b; swap(a, b); } return a; } vector<Edge> adj[nax]; int dist[nax][nax]; bool vis[nax][nax]; void dfs(int v, int p, int mn) { // vis[p][v] = true; for(Edge u : adj[v]) { if (u.w >= mn && dist[p][u.to] < mn) { dist[p][u.to] = max(dist[p][u.to], mn); dfs(u.to, p, mn); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m >> q; for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { int g = gcd(i, j); if (g <= m) { adj[i].push_back({j, g}); // cout << i << " " << j << " " << g << "\n"; } } } for(int k = 1; k <= m; k++) { for(int i = 1; i <= n; i++) { dfs(i, i, k); } } while(q--) { int x, y; cin >> x >> y; cout << m - dist[x][y] + 1 << "\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...