#include <bits/stdc++.h>
#define file ""
#define all(x) x.begin(), x.end()
#define sc second
#define fr first
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const ll inf = 1e18 + 5;
const ll mod = 1e9 + 7;
const int N = 1e6 + 5;
int dx[] = {+1, 0, -1, 0};
int dy[] = {0, +1, 0, -1};
int n, m;
void solve1() {
cout << max(n, m) - 1 << endl;
for (int i = 1; i < max(n, m); i++)
cout << (min(n, m) == n ? -1 : 1) << " ";
cout << endl;
}
void solve2() {
cout << max(n, m) << endl;
cout << (n == 2 ? 1 : -1) * (max(n, m) / 2 + 1) << " ";
for (int i = 1; i <= max(n, m) / 2; i++)
if (n == 2) cout << "-1000000 999999 ";
else cout << "1000000 -999999 ";
cout << endl;
}
vector<int> a;
bool solve3() {
if (a.size() == max(n, m)) {
for (int i = 0; i < a.size(); i++) {
ll sum = 0;
if (i + n - 1 >= a.size()) continue;
int cnt = n;
for (int j = i; cnt > 0; j++, cnt--) sum += a[j];
if (sum >= 0) return 0;
}
for (int i = 0; i < a.size(); i++) {
ll sum = 0;
if (i + m - 1 >= a.size()) continue;
int cnt = m;
for (int j = i; cnt > 0; j++, cnt--) sum += a[j];
if (sum <= 0) return 0;
}
for (int to : a) cout << to << " ";
cout << endl;
return 1;
}
for (int i = -4; i <= 4; i++) {
if (i == 0) continue;
a.pb(i);
if (solve3()) return 1;
a.pop_back();
}
return 0;
}
void solve() {
cin >> n >> m;
if (max(n, m) % min(n, m) == 0) {solve1(); return;}
if (min(n, m) == 2) {solve2(); return;}
if (max(n, m) <= 10) {cout << max(n, m) << "\n";solve3(); return;}
}
int main() {
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
srand(time(nullptr));
int t;
cin >> t;
while (t--) solve();
return 0;
}
Compilation message
sequence.cpp: In function 'bool solve3()':
sequence.cpp:46:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
46 | if (a.size() == max(n, m)) {
| ~~~~~~~~~^~~~~~~~~~~~
sequence.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i = 0; i < a.size(); i++) {
| ~~^~~~~~~~~~
sequence.cpp:49:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | if (i + n - 1 >= a.size()) continue;
| ~~~~~~~~~~^~~~~~~~~~~
sequence.cpp:54:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i = 0; i < a.size(); i++) {
| ~~^~~~~~~~~~
sequence.cpp:56:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | if (i + m - 1 >= a.size()) continue;
| ~~~~~~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
1 ms |
364 KB |
Ok |
7 |
Correct |
1 ms |
364 KB |
Ok |
8 |
Correct |
1 ms |
364 KB |
Ok |
9 |
Correct |
1 ms |
364 KB |
Ok |
10 |
Correct |
1 ms |
364 KB |
Ok |
11 |
Correct |
1 ms |
364 KB |
Ok |
12 |
Correct |
1 ms |
384 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
0 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
2 ms |
364 KB |
Ok |
7 |
Correct |
6 ms |
876 KB |
Ok |
8 |
Correct |
3 ms |
492 KB |
Ok |
9 |
Correct |
6 ms |
836 KB |
Ok |
10 |
Correct |
5 ms |
620 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Runtime error |
337 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Jury has the better answer : jans = 5, pans = 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
1 ms |
364 KB |
Ok |
7 |
Correct |
1 ms |
364 KB |
Ok |
8 |
Correct |
1 ms |
364 KB |
Ok |
9 |
Correct |
1 ms |
364 KB |
Ok |
10 |
Correct |
1 ms |
364 KB |
Ok |
11 |
Correct |
1 ms |
364 KB |
Ok |
12 |
Correct |
1 ms |
384 KB |
Ok |
13 |
Correct |
1 ms |
364 KB |
Ok |
14 |
Correct |
1 ms |
364 KB |
Ok |
15 |
Correct |
1 ms |
364 KB |
Ok |
16 |
Runtime error |
337 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
1 ms |
364 KB |
Ok |
7 |
Correct |
1 ms |
364 KB |
Ok |
8 |
Correct |
1 ms |
364 KB |
Ok |
9 |
Correct |
1 ms |
364 KB |
Ok |
10 |
Correct |
1 ms |
364 KB |
Ok |
11 |
Correct |
1 ms |
364 KB |
Ok |
12 |
Correct |
1 ms |
384 KB |
Ok |
13 |
Correct |
1 ms |
364 KB |
Ok |
14 |
Correct |
1 ms |
364 KB |
Ok |
15 |
Correct |
0 ms |
364 KB |
Ok |
16 |
Correct |
1 ms |
364 KB |
Ok |
17 |
Correct |
1 ms |
364 KB |
Ok |
18 |
Correct |
2 ms |
364 KB |
Ok |
19 |
Correct |
6 ms |
876 KB |
Ok |
20 |
Correct |
3 ms |
492 KB |
Ok |
21 |
Correct |
6 ms |
836 KB |
Ok |
22 |
Correct |
5 ms |
620 KB |
Ok |
23 |
Correct |
1 ms |
364 KB |
Ok |
24 |
Correct |
1 ms |
364 KB |
Ok |
25 |
Correct |
1 ms |
364 KB |
Ok |
26 |
Runtime error |
337 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
1 ms |
364 KB |
Ok |
7 |
Correct |
1 ms |
364 KB |
Ok |
8 |
Correct |
1 ms |
364 KB |
Ok |
9 |
Correct |
1 ms |
364 KB |
Ok |
10 |
Correct |
1 ms |
364 KB |
Ok |
11 |
Correct |
1 ms |
364 KB |
Ok |
12 |
Correct |
1 ms |
384 KB |
Ok |
13 |
Correct |
1 ms |
364 KB |
Ok |
14 |
Correct |
1 ms |
364 KB |
Ok |
15 |
Correct |
0 ms |
364 KB |
Ok |
16 |
Correct |
1 ms |
364 KB |
Ok |
17 |
Correct |
1 ms |
364 KB |
Ok |
18 |
Correct |
2 ms |
364 KB |
Ok |
19 |
Correct |
6 ms |
876 KB |
Ok |
20 |
Correct |
3 ms |
492 KB |
Ok |
21 |
Correct |
6 ms |
836 KB |
Ok |
22 |
Correct |
5 ms |
620 KB |
Ok |
23 |
Correct |
1 ms |
364 KB |
Ok |
24 |
Correct |
1 ms |
364 KB |
Ok |
25 |
Correct |
1 ms |
364 KB |
Ok |
26 |
Runtime error |
337 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
27 |
Halted |
0 ms |
0 KB |
- |