This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define f first
#define s second
#define pii pair<int,int>
#define int long long
using namespace std;
const int N = 1e6 + 5, mod = 1e9 + 7; // !
int t, in[N],n,m, p[N];
vector<int> V[N], v;
queue<int> q;
void construct(int x) {
for(int i = 0; i <= x; i++) in[i] = 0, V[i].clear();
for(int i = 0; i <= x; i++) {
if(i + n <= x) {
in[i + n]++; //cout << i <<"-->"<<i + n << endl;
V[i].push_back(i + n);
}
if(i + m <= x) {
in[i]++;
// cout << i + m <<"-->" << i << endl;
V[i + m].push_back(i);
}
}
for(int i = 0; i <= x; i++) {
if(!in[i]) q.push(i);
}
}
int check(int x) {
int c = 0;
construct(x);
v.clear();
while(q.size()) {
int u = q.front(); //cout <<"+" << u << endl;
q.pop();
v.push_back(u);
c++;
for(int i = 0; i < V[u].size(); i++) {
in[V[u][i]]--;
if(!in[V[u][i]]) q.push(V[u][i]);
}
}
reverse(v.begin(),v.end());
return c;
}
main() {
cin >> t;
while(t--) {
cin >> n >> m;
int l = 1, r = 1e6, ans = 0;
while(l <= r) {
int mid = (l + r)/2;
if(check(mid) == mid + 1) {
ans = mid, l = mid + 1;
} else r = mid - 1;
}
cout << ans << endl;
check(ans);
for(int i = 0; i < v.size(); i++) {
p[v[i]] = i + 1;
}
for(int i = 1; i <= ans; i++) {
cout << p[i] - p[i - 1] <<" ";
}
cout << endl;
}
}
Compilation message (stderr)
sequence.cpp: In function 'long long int check(long long int)':
sequence.cpp:37:20: 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]
37 | for(int i = 0; i < V[u].size(); i++) {
| ~~^~~~~~~~~~~~~
sequence.cpp: At global scope:
sequence.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
45 | main() {
| ^~~~
sequence.cpp: In function 'int main()':
sequence.cpp:58:20: 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]
58 | for(int i = 0; i < v.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... |