/***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 = 5e7;
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.back()--;
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;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Ok |
2 |
Correct |
0 ms |
212 KB |
Ok |
3 |
Correct |
1 ms |
212 KB |
Ok |
4 |
Correct |
1 ms |
212 KB |
Ok |
5 |
Correct |
0 ms |
212 KB |
Ok |
6 |
Correct |
0 ms |
212 KB |
Ok |
7 |
Correct |
1 ms |
212 KB |
Ok |
8 |
Correct |
0 ms |
212 KB |
Ok |
9 |
Correct |
0 ms |
212 KB |
Ok |
10 |
Correct |
0 ms |
212 KB |
Ok |
11 |
Correct |
0 ms |
212 KB |
Ok |
12 |
Correct |
0 ms |
212 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
there is incorrect sequence |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Ok |
2 |
Correct |
1 ms |
212 KB |
Ok |
3 |
Incorrect |
0 ms |
212 KB |
there is incorrect sequence |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Jury has the better answer : jans = 5, pans = 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Ok |
2 |
Correct |
0 ms |
212 KB |
Ok |
3 |
Correct |
1 ms |
212 KB |
Ok |
4 |
Correct |
1 ms |
212 KB |
Ok |
5 |
Correct |
0 ms |
212 KB |
Ok |
6 |
Correct |
0 ms |
212 KB |
Ok |
7 |
Correct |
1 ms |
212 KB |
Ok |
8 |
Correct |
0 ms |
212 KB |
Ok |
9 |
Correct |
0 ms |
212 KB |
Ok |
10 |
Correct |
0 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 |
Incorrect |
0 ms |
212 KB |
there is incorrect sequence |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Ok |
2 |
Correct |
0 ms |
212 KB |
Ok |
3 |
Correct |
1 ms |
212 KB |
Ok |
4 |
Correct |
1 ms |
212 KB |
Ok |
5 |
Correct |
0 ms |
212 KB |
Ok |
6 |
Correct |
0 ms |
212 KB |
Ok |
7 |
Correct |
1 ms |
212 KB |
Ok |
8 |
Correct |
0 ms |
212 KB |
Ok |
9 |
Correct |
0 ms |
212 KB |
Ok |
10 |
Correct |
0 ms |
212 KB |
Ok |
11 |
Correct |
0 ms |
212 KB |
Ok |
12 |
Correct |
0 ms |
212 KB |
Ok |
13 |
Incorrect |
1 ms |
212 KB |
there is incorrect sequence |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Ok |
2 |
Correct |
0 ms |
212 KB |
Ok |
3 |
Correct |
1 ms |
212 KB |
Ok |
4 |
Correct |
1 ms |
212 KB |
Ok |
5 |
Correct |
0 ms |
212 KB |
Ok |
6 |
Correct |
0 ms |
212 KB |
Ok |
7 |
Correct |
1 ms |
212 KB |
Ok |
8 |
Correct |
0 ms |
212 KB |
Ok |
9 |
Correct |
0 ms |
212 KB |
Ok |
10 |
Correct |
0 ms |
212 KB |
Ok |
11 |
Correct |
0 ms |
212 KB |
Ok |
12 |
Correct |
0 ms |
212 KB |
Ok |
13 |
Incorrect |
1 ms |
212 KB |
there is incorrect sequence |
14 |
Halted |
0 ms |
0 KB |
- |