이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 4e5 + 11;
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 db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;
int T, n, m, timer, t[N], p[N];
bool cycle, rev;
vi g[N];
int get (int v) {
return v == p[v] ? v : p[v] = get(p[v]);
}
void merge (int v, int u) {
v = get(v);
u = get(u);
if (rand() & 1)
swap(v, u);
p[u] = v;
}
void dfs (int v) {
for (auto to : g[v])
if (!t[to])
dfs(to);
t[v] = ++timer;
}
inline bool check (int k) {
for (int i = 0; i <= k; ++i)
g[i].clear();
for (int i = 0; i <= k; ++i) {
t[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 && !cycle; ++i)
if (!t[i])
dfs(i);
return cycle ^ 1;
}
main () {
cin >> T;
while (T--) {
cin >> n >> m;
rev = 0;
if (n < m) {
swap(n, m);
rev = 1;
}
for (int i = 0; i < m; ++i)
p[i] = i;
int res = 0;
while (1) {
++res;
if (res >= n) {
if (get(res % m) == get((res - n) % m))
break;
merge(res % m, (res - n) % m);
}
}
--res;
if (rev)
swap(n, m);
check(res);
printf("%d\n", res);
for (int i = 1; i <= res; ++i)
printf("%d ", t[i] - t[i - 1]);
printf("\n");
}
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'bool check(int)':
sequence.cpp:69:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (int i = 0; i <= k; ++i)
^~~
sequence.cpp:73: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:94:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |