이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
const int N = 1e6 + 11;
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
ll n, m, pos;
ll a[N], was[N], ans[N];
vector < ll > ord, g[N];
bool cyc;
void dfs(ll v){
was[v] = 1;
for(ll u : g[v])
if(!was[u])
dfs(u);
ord.push_back(v);
}
bool f(ll sz){
cyc = 0, ord.clear();
fill(was, was + sz + 1, 0);
for(ll i = 0; i <= sz; i++){
g[i].clear();
if(i - n >= 0) g[i].push_back(i - n);
if(i + m <= sz) g[i].push_back(i + m);
}
for(ll i = 0; i <= sz; i++)
if(!was[i])
dfs(i);
reverse(ord.begin(), ord.end());
fill(was, was + sz + 1, 0);
for(ll v : ord){
was[v] = 1;
for(ll u : g[v]){
if(was[u]){
return 0;
}
}
}
return 1;
}
void solve(){
cin >> n >> m;
ll l = n + m - 1 - gcd(n, m);
fill(ans, ans + l + 1, 0), f(l);
for(ll i = 0; i <= l; i++) ans[ord[i]] = i + 1;
ll p = ans[0];
cout << l << '\n';
for(ll i = 1; i <= l; i++) cout << ans[i] - p << ' ', p += ans[i] - p;
cout << '\n';
}
signed main(){
ll cs;
cin >> cs;
while(cs--){
solve();
}
}
# | 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... |