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