Submission #513594

#TimeUsernameProblemLanguageResultExecution timeMemory
513594Killer2501Nice sequence (IZhO18_sequence)C++14
100 / 100
1345 ms71112 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ull unsigned long long #define pb push_back #define pll pair<ll, ll> #define pii pair<int, int> #define fi first #define se second using namespace std; const int N = 5e5+5; const int M = (1<<17); const ll inf = 1e15; const ll mod = 1e15+7; int n, t, k, m, d[N], in[N], out[N]; ll ans, tong, a[N], b[N], c[N]; string s[N]; struct node { int x[2]; set<int> vi; node(){} node( int _x, int _y) { x[0] = _x; x[1] = _y; } }; vector<node> q; vector<int> adj[N], kq; void dfs(int u) { a[u] = ++t; if(u+m <= k && a[u+m] == 0)dfs(u+m); if(u-n >= 0 && a[u-n] == 0)dfs(u-n); } bool check(int mid) { k = mid; for(int i = 0; i <= k; i ++)adj[i].clear(); fill_n(a, k+1, 0); t = 0; for(int i = 0; i <= k; i ++) { if(i+m <= k) { adj[i].pb(i+m); ++a[i+m]; } if(i >= n) { adj[i].pb(i-n); ++a[i-n]; } } queue<int> q; for(int i = 0; i <= k; i ++)if(a[i] == 0)q.push(i); while(!q.empty()) { int u = q.front(); q.pop(); a[u] = ++t; for(int v: adj[u]) { --a[v]; if(a[v] == 0)q.push(v); } } if(t == k+1)return true; return false; } void sol() { cin >> n >> m; ans = n+m-__gcd(m,n)-1; check(ans); cout << ans << '\n'; for(int i = 1; i <= ans; i ++)cout << a[i]-a[i-1] <<" "; cout << '\n'; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); #define task "test" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int ntest = 1; cin >> ntest; while(ntest -- > 0) sol(); }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:90:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:91:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...