이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
const int N = 2 * 1e6 + 5;
const long long inf = 1000000000;
#define F first
#define S second
#define pb push_back
int n, t, a, b, lastans, k, id, m;
bool used[N];
pair<int, int> pref[N];
vector<int> top, g[N];
void create(int v){
for(int i = 0; i <= v; ++i){
g[i].clear();
used[i] = 0;
}
for(int i = 0; i <= v; ++i){
if(i + n <= v) g[i + n].pb(i);
if(i - m >= 0) g[i - m].pb(i);
}
}
/*
0 -> 3 -> 2 1
2 3 0 1
0 1 2 3
2 3 0 1
*/
bool check(int v){
used[v] = 1;
for(auto to : g[v]){
if(used[to] == 1){
return 1;
}
else if(used[to] == 0){
if(check(to)) return 1;
}
}
used[v] = 2;
return 0;
}
void topsort(int v){
used[v] = 1;
for(auto to : g[v]){
if(used[to] == 0){
topsort(to);
}
}
top.pb(v);
}
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
while(t--){
cin >> n >> m;
int l = 0, r = n + m , mid;
// while(l < r){
//// cout << l << ' ' << r << '\n';
// mid = (l + r) / 2;
// create(mid);
//// for(int i = 0; i <= mid; ++i){
//// cout << i << '\n';
//// for(auto to : g[i]){
//// cout << to << ' ';
//// }
//// cout << '\n';
//// }
//// cout << "OK\n";
// if(!check(mid)) l = mid;
// else r = mid - 1;
// }
l = n + m - 1 - __gcd(n, m);
cout << l << '\n';
create(l);
top.clear();
for(int i = 0; i <= l; ++i){
if(!used[i]) topsort(i);
}
reverse(top.begin(), top.end());
for(int i = 0; i < top.size(); ++i){
// cout << top[i] << ' ' << i << '\n';
pref[i] = {top[i], i};
}
// cout << '\n';
sort(pref, pref + top.size());
for(int i = 1; i < top.size(); i++){
cout << (pref[i].S - pref[i - 1].S) << ' ';
}
cout << '\n';
}
return 0;
}
// merge sort tree
// l <= b <= r
// r < b
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp:65:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
65 | main() {
| ^~~~
sequence.cpp: In function 'int main()':
sequence.cpp:99:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
99 | for(int i = 0; i < top.size(); ++i){
| ~~^~~~~~~~~~~~
sequence.cpp:105:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | for(int i = 1; i < top.size(); i++){
| ~~^~~~~~~~~~~~
sequence.cpp:75:20: warning: unused variable 'r' [-Wunused-variable]
75 | int l = 0, r = n + m , mid;
| ^
sequence.cpp:75:32: warning: unused variable 'mid' [-Wunused-variable]
75 | int l = 0, r = n + m , mid;
| ^~~
# | 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... |