이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define pb push_back
#define endi puts("");
const int N = 5e5+12,INF=1e9+7;
int sz,vis[N],pref[N],m,n;
vector <int> v;
void dfs(int x){
vis[x]=1;
if (x-m >= 0 && !vis[x-m]){
dfs(x-m);
}
if (x+n<=sz && !vis[x+n]){
dfs(x+n);
}
v.pb(x);
}
bool is(int x){
sz = x;
v.clear();
int i;
for (i=0;i<=sz;++i)
vis[i]=0;
for (i=0;i<=sz;++i)
if (!vis[i])dfs(i);
for (i=0;i<v.size();++i){
pref[v[i]]=i;
}
for (i=0;i<=sz;++i){
if (i-m >= 0 && pref[i] <= pref[i-m])ret 0;
if (i+n <= sz && pref[i] <= pref[i+n])ret 0;
}
ret 1;
}
main(){
ios_base::sync_with_stdio(NULL);
int t;
cin>>t;
while (t--){
int i,j;
cin>>n>>m;
int l=0,r=n+m;
while (l<r){
int m = (l+r+1)>>1;
if (is(m)){
l=m;
}
else r = m-1;
}
is(l);
cout <<l<<"\n";
for (i=1;i<=l;++i){
cout <<pref[i]-pref[i-1]<<" ";
}
endi
}
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'bool is(int)':
sequence.cpp:37:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (i=0;i<v.size();++i){
| ~^~~~~~~~~
sequence.cpp: At global scope:
sequence.cpp:47:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
47 | main(){
| ^
sequence.cpp: In function 'int main()':
sequence.cpp:52:15: warning: unused variable 'j' [-Wunused-variable]
52 | int i,j;
| ^
# | 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... |