이 제출은 이전 버전의 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[1000001];
int mas[1000001];
int fix[1000001];
void go (int u,int col,int sz){
if (!OK) return ;
fix[u]=col;
for (int i=0;i<v[u].size();i++){
int node=v[u][i];
if (node>sz) break;
if (fix[node]==col){
OK=false;
return ;
}
if (!OK) return ;
if (fix[node]==0) go(node,col,sz);
}
}
inline bool check (int sz){
OK=true;
for (int i=0;i<=sz;i++){
if (fix[i]==0){
go(i,i+1,sz);
}
}
for (int i=0;i<=sz;i++){
fix[i]=0;
}
return OK;
}
void top_sort (int u,int sz){
fix[u]=1;
for (int i=0;i<v[u].size();i++){
int node=v[u][i];
if (node>sz) break;
if (fix[node]==0) top_sort(node,sz);
}
mas[u]=++M;
}
int nmas[1000001];
inline void solve (int sz){
OK=true;
for (int i=0;i<=sz;i++){
if (fix[i]==0){
top_sort(i,sz);
}
}
for (int i=0;i<=sz;i++){
nmas[i]=mas[i]-mas[i-1];
fix[i]=0;
}
}
main () {
ios::sync_with_stdio(false);
cin>>t;
while (t--){
cin>>n>>m;
int sz=400000;
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);
}
}
for (int i=0;i<=sz;i++){
sort (v[i].begin(),v[i].end());
}
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;
for (int i=0;i<=sz;i++){
v[i].clear();
}
}
return 0;
}
/*
1
2 4
_ _ _ _
| \ | | (_) | |
| \| | _ ___ | | __ ___ ___ _ __ __ _
| . ` | | | / __| | |/ / / __| / _ \ | '_ \ / _` |
| |\ | | | | (__ | < \__ \ | (_) | | | | | | (_| |
|_| \_| |_| \___| |_|\_\ |___/ \___/ |_| |_| \__,_|
*/
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'void go(int, int, int)':
sequence.cpp:15:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<v[u].size();i++){
~^~~~~~~~~~~~
sequence.cpp: In function 'void top_sort(int, int)':
sequence.cpp:45:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<v[u].size();i++){
~^~~~~~~~~~~~
sequence.cpp: At global scope:
sequence.cpp:67:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
sequence.cpp: In function 'int main()':
sequence.cpp:90:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
mid= b + e >> 1;
~~^~~
# | 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... |