Submission #1085284

#TimeUsernameProblemLanguageResultExecution timeMemory
1085284zxciganNice sequence (IZhO18_sequence)C++17
100 / 100
813 ms77300 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5 * 4 + 222 + 2; vector<int> g[N]; void top (int v, vector<bool>&used, vector<int>&ans) { used[v] = 1; for (auto to : g[v]) { if (!used[to]) { top (to, used, ans); } } ans.push_back(v); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // LOCAL int Q; cin >> Q; int n = Q; vector<int> a (n + 1), b (n + 1); for (int i = 1; i <= n; ++i) { cin >> a[i] >> b[i]; int l = a[i] + b[i] - __gcd (a[i], b[i]) - 1; swap (a[i], b[i]); for (int j = 0; j <= l; ++j) { if (j - a[i] >= 0) { g[j - a[i]].push_back (j); } if (j - b[i] >= 0) { g[j].push_back (j - b[i]); } } vector<int> ans; vector<bool> used (l + 1, false); for (int j = 0; j <= l; ++j) { if (!used[j]) { top (j, used, ans); } } for (int j = 0; j <= l; ++j) g[j].clear(); reverse (begin (ans), end (ans)); vector<int> d (l + 1); for (int j = 0; j <= l; ++j) { d[ans[j]] = j; } cout << l << '\n'; for (int j = 1; j <= l; ++j) { cout << d[j] - d[j - 1] << ' '; } cout << '\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...