This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
//#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
#define pb push_back
//#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(data) data.begin() , data.end()
#define endl '\n'
//freopen("nenokku_easy.in", "r", stdin);
//freopen("nenokku_easy.out", "w", stdout);
#define int long long
#define pii pair < int, int >
#define pll pair < long long, long long >
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const int M = 305;
const int mod = 1e9 + 7;
int q, n, m, used[N], state, cl[N], ms[N];
vector < int > g[N], arr;
void topsort(int v) {
used[v] = 1;
for(int i = 0; i < g[v].size(); i++) {
int to = g[v][i];
if(!used[to]) {
topsort(to);
}
}
arr.pb(v);
}
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//file("pieaters");
cin >> q;
while(q--) {
cin >> n >> m;
int sz = n + m - 1 - __gcd(n, m);
cout << sz << endl;
for(int i = 0; i <= sz; i++) {
if(i - n >= 0) {
g[i].pb(i - n);
}
if(i + m <= sz) {
g[i].pb(i + m);
}
}
for(int i = 0; i <= sz; i++) {
if(!used[i]) {
topsort(i);
}
}
reverse(all(arr));
for(int i = 0; i < arr.size(); i++) {
//cout << arr[i] << " ";
ms[arr[i]] = i;
}
//cout << endl;
int val = ms[0];
ms[0] = 0;
for(int i = 1; i <= sz; i++) {
ms[i] -= val;
cout << ms[i] - ms[i - 1] << " ";
}
cout << endl;
arr.clear();
for(int i = 0; i <= sz; i++) {
g[i].clear();
used[i] = 0;
}
}
}
Compilation message (stderr)
sequence.cpp: In function 'void topsort(long long int)':
sequence.cpp:32:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i = 0; i < g[v].size(); i++) {
| ~~^~~~~~~~~~~~~
sequence.cpp: At global scope:
sequence.cpp:41:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
41 | main() {
| ^~~~
sequence.cpp: In function 'int main()':
sequence.cpp:65:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i = 0; i < arr.size(); i++) {
| ~~^~~~~~~~~~~~
# | 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... |