/***Farhan132***/
// #pragma GCC optimize("Ofast,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
typedef pair<ll , ll> ii;
typedef tuple < ll, ll, ll > tp;
#define ff first
#define ss second
#define pb push_back
#define in insert
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clz(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcount(n)
#define clean fflush(stdout)
const ll mod = (ll) 998244353;
// const ll mod = (ll) 1e9 + 7;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = (ll)2e18;
// ll dx[]={0,1,0,-1};
// ll dy[]={1,0,-1,0};
// ll dxx[]={0,1,0,-1,1,1,-1,-1};
// ll dyy[]={1,0,-1,0,1,-1,1,-1};
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll N = 2005;
vector < ll > f(ll n, ll m){
if(n > m){
vector < ll > v = f(m, n);
for(auto &u : v) u = -u;
return v;
}
if(n == m){
vector < ll > v(n - 1, 1);
return v;
}
if(m % n == 0){
vector < ll > v(m - 1, 1);
return v;
}
ll M = m;
while(2 * n <= m) m -= n;
ll intersect = n * 2 - m;
ll sub = (m - intersect) / 2;
assert(2*sub + intersect == m);
vector < ll > v(M);
ll R = 1e8 - 2;
for(ll i = 0; i < sub; i++){
v[i] = -1; R--;
}
v[0] -= R;
R = 1e8;
for(ll i = sub; i < sub + intersect; i++){
v[i] = 1; R--;
}
v[sub] += R;
for(ll i = sub + intersect; i < M; i++){
v[i] = v[i - n];
}
v[m - 1]--;
return v;
}
void solve(){
ll n, m; cin >> n >> m;
auto v = f(m, n);
cout << v.size() << '\n';
for(auto u : v){
cout << u << ' ';
}
cout << '\n';
return;
}
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
auto start_time = clock();
#else
// freopen("subsequence.in", "r", stdin);
// freopen("subsequence.out", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#endif
//precalc();
ll T = 1, CT = 0; cin >> T;
while(T--){
// cout << "Case #" << ++CT << ": ";
solve();
}
#ifdef LOCAL
auto end_time = clock();
cerr<< "Execution time: "<<(end_time - start_time)*(int)1e3/CLOCKS_PER_SEC<<" ms\n";
#endif
return 0;
}
Compilation message
sequence.cpp: In function 'int main()':
sequence.cpp:112:15: warning: unused variable 'CT' [-Wunused-variable]
112 | ll T = 1, CT = 0; cin >> T;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Ok |
2 |
Correct |
0 ms |
212 KB |
Ok |
3 |
Correct |
1 ms |
212 KB |
Ok |
4 |
Correct |
0 ms |
212 KB |
Ok |
5 |
Correct |
0 ms |
212 KB |
Ok |
6 |
Correct |
0 ms |
292 KB |
Ok |
7 |
Correct |
0 ms |
212 KB |
Ok |
8 |
Correct |
0 ms |
212 KB |
Ok |
9 |
Correct |
0 ms |
212 KB |
Ok |
10 |
Correct |
1 ms |
212 KB |
Ok |
11 |
Correct |
0 ms |
212 KB |
Ok |
12 |
Correct |
0 ms |
212 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Ok |
2 |
Correct |
1 ms |
212 KB |
Ok |
3 |
Correct |
1 ms |
212 KB |
Ok |
4 |
Correct |
1 ms |
212 KB |
Ok |
5 |
Correct |
1 ms |
212 KB |
Ok |
6 |
Correct |
1 ms |
340 KB |
Ok |
7 |
Correct |
5 ms |
852 KB |
Ok |
8 |
Correct |
3 ms |
596 KB |
Ok |
9 |
Correct |
6 ms |
980 KB |
Ok |
10 |
Correct |
4 ms |
724 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Ok |
2 |
Correct |
0 ms |
212 KB |
Ok |
3 |
Correct |
0 ms |
212 KB |
Ok |
4 |
Incorrect |
1 ms |
212 KB |
Jury has the better answer : jans = 9, pans = 8 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Jury has the better answer : jans = 5, pans = 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Ok |
2 |
Correct |
0 ms |
212 KB |
Ok |
3 |
Correct |
1 ms |
212 KB |
Ok |
4 |
Correct |
0 ms |
212 KB |
Ok |
5 |
Correct |
0 ms |
212 KB |
Ok |
6 |
Correct |
0 ms |
292 KB |
Ok |
7 |
Correct |
0 ms |
212 KB |
Ok |
8 |
Correct |
0 ms |
212 KB |
Ok |
9 |
Correct |
0 ms |
212 KB |
Ok |
10 |
Correct |
1 ms |
212 KB |
Ok |
11 |
Correct |
0 ms |
212 KB |
Ok |
12 |
Correct |
0 ms |
212 KB |
Ok |
13 |
Correct |
0 ms |
212 KB |
Ok |
14 |
Correct |
0 ms |
212 KB |
Ok |
15 |
Correct |
0 ms |
212 KB |
Ok |
16 |
Incorrect |
1 ms |
212 KB |
Jury has the better answer : jans = 9, pans = 8 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Ok |
2 |
Correct |
0 ms |
212 KB |
Ok |
3 |
Correct |
1 ms |
212 KB |
Ok |
4 |
Correct |
0 ms |
212 KB |
Ok |
5 |
Correct |
0 ms |
212 KB |
Ok |
6 |
Correct |
0 ms |
292 KB |
Ok |
7 |
Correct |
0 ms |
212 KB |
Ok |
8 |
Correct |
0 ms |
212 KB |
Ok |
9 |
Correct |
0 ms |
212 KB |
Ok |
10 |
Correct |
1 ms |
212 KB |
Ok |
11 |
Correct |
0 ms |
212 KB |
Ok |
12 |
Correct |
0 ms |
212 KB |
Ok |
13 |
Correct |
0 ms |
212 KB |
Ok |
14 |
Correct |
1 ms |
212 KB |
Ok |
15 |
Correct |
1 ms |
212 KB |
Ok |
16 |
Correct |
1 ms |
212 KB |
Ok |
17 |
Correct |
1 ms |
212 KB |
Ok |
18 |
Correct |
1 ms |
340 KB |
Ok |
19 |
Correct |
5 ms |
852 KB |
Ok |
20 |
Correct |
3 ms |
596 KB |
Ok |
21 |
Correct |
6 ms |
980 KB |
Ok |
22 |
Correct |
4 ms |
724 KB |
Ok |
23 |
Correct |
0 ms |
212 KB |
Ok |
24 |
Correct |
0 ms |
212 KB |
Ok |
25 |
Correct |
0 ms |
212 KB |
Ok |
26 |
Incorrect |
1 ms |
212 KB |
Jury has the better answer : jans = 9, pans = 8 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Ok |
2 |
Correct |
0 ms |
212 KB |
Ok |
3 |
Correct |
1 ms |
212 KB |
Ok |
4 |
Correct |
0 ms |
212 KB |
Ok |
5 |
Correct |
0 ms |
212 KB |
Ok |
6 |
Correct |
0 ms |
292 KB |
Ok |
7 |
Correct |
0 ms |
212 KB |
Ok |
8 |
Correct |
0 ms |
212 KB |
Ok |
9 |
Correct |
0 ms |
212 KB |
Ok |
10 |
Correct |
1 ms |
212 KB |
Ok |
11 |
Correct |
0 ms |
212 KB |
Ok |
12 |
Correct |
0 ms |
212 KB |
Ok |
13 |
Correct |
0 ms |
212 KB |
Ok |
14 |
Correct |
1 ms |
212 KB |
Ok |
15 |
Correct |
1 ms |
212 KB |
Ok |
16 |
Correct |
1 ms |
212 KB |
Ok |
17 |
Correct |
1 ms |
212 KB |
Ok |
18 |
Correct |
1 ms |
340 KB |
Ok |
19 |
Correct |
5 ms |
852 KB |
Ok |
20 |
Correct |
3 ms |
596 KB |
Ok |
21 |
Correct |
6 ms |
980 KB |
Ok |
22 |
Correct |
4 ms |
724 KB |
Ok |
23 |
Correct |
0 ms |
212 KB |
Ok |
24 |
Correct |
0 ms |
212 KB |
Ok |
25 |
Correct |
0 ms |
212 KB |
Ok |
26 |
Incorrect |
1 ms |
212 KB |
Jury has the better answer : jans = 9, pans = 8 |
27 |
Halted |
0 ms |
0 KB |
- |