# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
89407 | nicksona | Nice sequence (IZhO18_sequence) | C++14 | 2064 ms | 66112 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n,m;
int t;
bool OK=true;
int M=0;
vector <int> v[400001];
int mas[400001];
int fix[400001],nmas[1000001];
void go (int u,int col){
if (!OK) return ;
fix[u]=col;
for (int i=0;i<v[u].size();i++){
int node=v[u][i];
if (fix[node]==col){
OK=false;
return ;
}
if (!OK) return ;
if (fix[node]==0) go(node,col);
}
}
inline bool check (int sz){
for (int i=0;i<=sz;i++){
if (i+n<=sz){
v[i].pb(i+n);
}
if (i+m<=sz){
v[i+m].pb(i);
}
}
OK=true;
for (int i=0;i<=sz;i++){
if (fix[i]==0){
go(i,i+1);
}
}
for (int i=0;i<=sz;i++){
fix[i]=0;
v[i].clear();
}
return OK;
}
void top_sort (int u){
fix[u]=1;
for (int i=0;i<v[u].size();i++){
int node=v[u][i];
if (fix[node]==0) top_sort(node);
}
mas[u]=++M;
}
inline void solve (int sz){
for (int i=0;i<=sz;i++){
if (i+n<=sz){
v[i].pb(i+n);
}
if (i+m<=sz){
v[i+m].pb(i);
}
}
OK=true;
for (int i=0;i<=sz;i++){
if (fix[i]==0){
top_sort(i);
}
}
for (int i=0;i<=sz;i++){
nmas[i]=mas[i]-mas[i-1];
}
for (int i=0;i<=sz;i++){
fix[i]=0;
v[i].clear();
}
}
main () {
ios::sync_with_stdio(false);
cin>>t;
while (t--){
cin>>n>>m;
int k=0,ans=0;
ans=m-__gcd(n,m)+n;
ans--;
M=0;
if (ans>0) solve(ans);
cout<<ans<<endl;
for (int i=1;i<=ans;i++){
cout<<nmas[i]<<" ";
}
cout<<endl;
}
return 0;
}
/*
1
2 4
_ _ _ _
| \ | | (_) | |
| \| | _ ___ | | __ ___ ___ _ __ __ _
| . ` | | | / __| | |/ / / __| / _ \ | '_ \ / _` |
| |\ | | | | (__ | < \__ \ | (_) | | | | | | (_| |
|_| \_| |_| \___| |_|\_\ |___/ \___/ |_| |_| \__,_|
*/
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |