#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define ft first
#define sd second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define pll pair<ll, ll>
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long ll;
const int N = 400100;
vector<int> ts;
int n, m, len, mrk[N], pf[N];
bool cyc;
void DFS(int v){
mrk[v] = 1;
if (v >= m){
if (mrk[v - m] == 0)
DFS(v - m);
}
if (v + n <= len){
if (mrk[v + n] == 0)
DFS(v + n);
}
ts.PB(v);
}
int main(){
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#else
ios_base::sync_with_stdio(0); cin.tie(0);
#endif // _LOCAL
int qq; cin >> qq;
for (; qq; qq--){
cin >> n >> m;
len = n + m - __gcd(n, m) - 1;
cout << len << '\n';
fill(mrk, mrk + len + 1, 0);
fill(pf, pf + len + 1, -1);
ts.clear();
for (int i = 0; i <= len; i++)
if (!mrk[i])
DFS(i);
int it = -len;
for (int v : ts){
int mx = it;
it++;
if (v >= m)
mx = max(mx, pf[v - m]);
if (v + n <= len)
mx = max(mx, pf[v + n]);
pf[v] = mx + 1;
}
for (int i = 1; i <= len; i++)
cout << pf[i] - pf[i - 1] << " ";
cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
3712 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
3712 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |