Submission #237483

#TimeUsernameProblemLanguageResultExecution timeMemory
237483_7_7_Nice sequence (IZhO18_sequence)C++14
76 / 100
2082 ms39736 KiB
#include <bits/stdc++.h> //#define int long long //#pragma GCC optimize("Ofast") //#pragma comment(linker, "/stack:200000000") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4") #define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout); #define forev(i, b, a) for(int i = (b); i >= (a); --i) #define forn(i, a, b) for(int i = (a); i <= (b); ++i) #define all(x) x.begin(), x.end() #define sz(s) (int)s.size() #define pb push_back #define ppb pop_back #define mp make_pair #define s second #define f first using namespace std; typedef pair < long long, long long > pll; typedef pair < int, int > pii; typedef unsigned long long ull; typedef vector < pii > vpii; typedef vector < int > vi; typedef long double ldb; typedef long long ll; typedef double db; const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555; const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9); const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 4e5 + 11; const db eps = 1e-12, pi = 3.14159265359; const ll INF = 1e18; int T, n, m, timer, t[N], c[N]; bool cycle; vi g[N]; void dfs (int v) { c[v] = 1; for (auto to : g[v]) { if (!c[to]) dfs(to); if (c[to] == 1) cycle = 1; } t[v] = ++timer; c[v] = 2; } bool check (int k) { for (int i = 0; i <= k; ++i) g[i].clear(); for (int i = 0; i <= k; ++i) { t[i] = 0; c[i] = 0; if (i - n >= 0) g[i - n].pb(i); if (i - m >= 0) g[i].pb(i - m); } timer = 0; cycle = 0; for (int i = 0; i <= k; ++i) if (!c[i]) dfs(i); return cycle ^ 1; } main () { cin >> T; while (T--) { cin >> n >> m; int l = 1, r = n + m, res = 0; while (l <= r) { int mid = (l + r) >> 1; if (check(mid)) { l = mid + 1; res = mid; } else r = mid - 1; } check(res); printf("%d\n", res); for (int i = 1; i <= res; ++i) printf("%d ", t[i] - t[i - 1]); printf("\n"); } }

Compilation message (stderr)

sequence.cpp: In function 'bool check(int)':
sequence.cpp:60:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (int i = 0; i <= k; ++i) 
     ^~~
sequence.cpp:64:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  for (int i = 0; i <= k; ++i) {
  ^~~
sequence.cpp: At global scope:
sequence.cpp:86:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
#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...