more code

This commit is contained in:
Barrett Ruth 2025-01-30 17:06:38 -05:00
parent 7aacde99f4
commit 742bf851a9
149 changed files with 7065 additions and 0 deletions

View file

@ -0,0 +1,2 @@
BasedOnStyle: Google
AllowShortFunctionsOnASingleLine: Empty

126
codeforces/640/a.cc Normal file
View file

@ -0,0 +1,126 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
if constexpr (std::is_convertible_v<T, char const *>) {
std::cout << t << '\n';
} else {
for (auto const &e : t) {
std::cout << e << ' ';
}
std::cout << '\n';
}
}
template <typename... Args>
void println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return std::numeric_limits<T>::min();
}
#define ff first
#define ss second
#define eb emplace_back
#define ll long long
#define ld long double
#define vec vector
#define all(x) (x).begin(), (x).end()
#define rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
int n;
cin >> n;
int k = 0;
vec<int> summands;
int power = 0;
while (n) {
int digit = n % 10;
if (digit) {
++k;
summands.push_back(static_cast<int>(pow(10, power)) * digit);
}
++power;
n /= 10;
}
cout << k << '\n';
for (auto summand : summands) cout << summand << ' ';
cout << '\n';
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

6
codeforces/640/a.in Normal file
View file

@ -0,0 +1,6 @@
5
5009
7
9876
10000
10

10
codeforces/640/a.out Normal file
View file

@ -0,0 +1,10 @@
2
9 5000
1
7
4
6 70 800 9000
1
10000
1
10

134
codeforces/640/b.cc Normal file
View file

@ -0,0 +1,134 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
if constexpr (std::is_convertible_v<T, char const *>) {
std::cout << t << '\n';
} else {
for (auto const &e : t) {
std::cout << e << ' ';
}
std::cout << '\n';
}
}
template <typename... Args>
void println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return std::numeric_limits<T>::min();
}
#define ff first
#define ss second
#define eb emplace_back
#define ll long long
#define ld long double
#define vec vector
#define all(x) (x).begin(), (x).end()
#define rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
/*
n, k; SUM ai = n, same parity
n odd: k even -> NO; k odd -> YES
n even: k even: odd #s -> NO, only even
*/
int n, k;
cin >> n >> k;
if (k > n) {
NO();
return;
}
if ((n - 2 * (k - 1)) % 2 == 0 && (n - 2 * (k - 1)) > 0) {
YES();
FOR(i, 1, k)
cout << 2 << ' ';
cout << n - 2 * (k - 1) << '\n';
} else if ((n - k + 1) & 1) {
YES();
FOR(i, 1, k)
cout << 1 << ' ';
cout << n - k + 1 << '\n';
} else
NO();
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

9
codeforces/640/b.in Normal file
View file

@ -0,0 +1,9 @@
8
10 3
100 4
8 7
97 2
8 8
3 10
5 3
1000000000 9

13
codeforces/640/b.out Normal file
View file

@ -0,0 +1,13 @@
YES
2 2 6
YES
2 2 2 94
NO
NO
YES
1 1 1 1 1 1 1 1
NO
YES
1 1 3
YES
2 2 2 2 2 2 2 2 999999984

124
codeforces/640/c.cc Normal file
View file

@ -0,0 +1,124 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
if constexpr (std::is_convertible_v<T, char const *>) {
std::cout << t << '\n';
} else {
for (auto const &e : t) {
std::cout << e << ' ';
}
std::cout << '\n';
}
}
template <typename... Args>
void println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return std::numeric_limits<T>::min();
}
#define ff first
#define ss second
#define eb emplace_back
#define ll long long
#define ld long double
#define vec vector
#define all(x) (x).begin(), (x).end()
#define rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
int n, k;
cin >> n >> k;
/*
take n;
n divides n, 2n, 3n, 4n, ...
kth positive integer not divisible by n;
just count ^ : n - 1, n - 1 between each
binary search on the right #;
*/
ll x = k + k / (n - 1);
if (x % n == 0) --x;
println(x);
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

7
codeforces/640/c.in Normal file
View file

@ -0,0 +1,7 @@
6
3 7
4 12
2 1000000000
7 97
1000000000 1000000000
2 1

6
codeforces/640/c.out Normal file
View file

@ -0,0 +1,6 @@
10
15
1999999999
113
1000000001
1

View file

@ -0,0 +1,5 @@
-std=c++20
-Wall
-Wextra
-Wshadow
-DLOCAL

139
codeforces/640/d.cc Normal file
View file

@ -0,0 +1,139 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
if constexpr (std::is_convertible_v<T, char const *>) {
std::cout << t << '\n';
} else {
for (auto const &e : t) {
std::cout << e << ' ';
}
std::cout << '\n';
}
}
template <typename... Args>
void println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return std::numeric_limits<T>::min();
}
#define ff first
#define ss second
#define eb emplace_back
#define ll long long
#define ld long double
#define vec vector
#define all(x) (x).begin(), (x).end()
#define rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
int n;
cin >> n;
vec<int> A(n);
for (auto &e : A) cin >> e;
int moves = 1, i = 1, j = sz(A) - 1;
int a = A[0], b = 0;
int prev = a;
while (i <= j) {
int cur = 0;
// bob
if (moves & 1) {
while (i <= j && cur <= prev) {
cur += A[j];
--j;
}
b += cur;
prev = cur;
} else { // alice
while (i <= j && cur <= prev) {
cur += A[i];
++i;
}
a += cur;
prev = cur;
}
++moves;
}
println("{} {} {}", moves, a, b);
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

15
codeforces/640/d.in Normal file
View file

@ -0,0 +1,15 @@
7
11
3 1 4 1 5 9 2 6 5 3 5
1
1000
3
1 1 1
13
1 2 3 4 5 6 7 8 9 10 11 12 13
2
2 1
6
1 1 1 1 1 1
7
1 1 1 1 1 1 1

7
codeforces/640/d.out Normal file
View file

@ -0,0 +1,7 @@
6 23 21
1 1000 0
2 1 2
6 45 46
2 2 1
3 4 2
4 4 3

231
codeforces/640/e.cc Normal file
View file

@ -0,0 +1,231 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
if constexpr (std::is_convertible_v<T, char const *>) {
std::cout << t << '\n';
} else {
for (auto const &e : t) {
std::cout << e << ' ';
}
std::cout << '\n';
}
}
template <typename... Args>
void println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return std::numeric_limits<T>::min();
}
#define ff first
#define ss second
#define eb emplace_back
#define ll long long
#define ld long double
#define vec vector
#define all(x) (x).begin(), (x).end()
#define rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// https://mirror.codeforces.com/blog/entry/124683
namespace hashing {
using i64 = std::int64_t;
using u64 = std::uint64_t;
static const u64 FIXED_RANDOM =
std::chrono::steady_clock::now().time_since_epoch().count();
#if USE_AES
std::mt19937 rd(FIXED_RANDOM);
const __m128i KEY1{(i64)rd(), (i64)rd()};
const __m128i KEY2{(i64)rd(), (i64)rd()};
#endif
template <class T, class D = void>
struct custom_hash {};
template <class T>
inline void hash_combine(u64 &seed, T const &v) {
custom_hash<T> hasher;
seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4);
};
template <class T>
struct custom_hash<T,
typename std::enable_if<std::is_integral<T>::value>::type> {
u64 operator()(T _x) const {
u64 x = _x;
#if USE_AES
__m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM};
__m128i y = _mm_aesenc_si128(m, KEY1);
__m128i z = _mm_aesenc_si128(y, KEY2);
return z[0];
#else
x += 0x9e3779b97f4a7c15 + FIXED_RANDOM;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
#endif
}
};
template <class T>
struct custom_hash<T, std::void_t<decltype(std::begin(std::declval<T>()))>> {
u64 operator()(T const &a) const {
u64 value = FIXED_RANDOM;
for (auto &x : a) hash_combine(value, x);
return value;
}
};
template <class... T>
struct custom_hash<std::tuple<T...>> {
u64 operator()(const std::tuple<T...> &a) const {
u64 value = FIXED_RANDOM;
std::apply([&value](T const &...args) { (hash_combine(value, args), ...); },
a);
return value;
}
};
template <class T, class U>
struct custom_hash<std::pair<T, U>> {
u64 operator()(std::pair<T, U> const &a) const {
u64 value = FIXED_RANDOM;
hash_combine(value, a.first);
hash_combine(value, a.second);
return value;
}
};
}; // namespace hashing
#ifdef PB_DS_ASSOC_CNTNR_HPP
template <class Key, class Value>
using hashmap = gp_hash_table<
Key, Value, hashing::custom_hash<Key>, std::equal_to<Key>,
direct_mask_range_hashing<>, linear_probe_fn<>,
hash_standard_resize_policy<hash_exponential_size_policy<>,
hash_load_check_resize_trigger<>, true>>;
template <class Key>
using hashset = gp_hash_table<
Key, null_type, hashing::custom_hash<Key>, std::equal_to<Key>,
direct_mask_range_hashing<>, linear_probe_fn<>,
hash_standard_resize_policy<hash_exponential_size_policy<>,
hash_load_check_resize_trigger<>, true>>;
#endif
#ifdef PB_DS_TREE_POLICY_HPP
template <typename T>
using multiset = tree<T, null_type, std::less_equal<T>, rb_tree_tag,
tree_order_statistics_node_update>;
template <class Key, class Value = null_type>
using rbtree = tree<Key, Value, std::less<Key>, rb_tree_tag,
tree_order_statistics_node_update>;
#endif
void solve() {
int n;
cin >> n;
vec<int> a(n);
vec<int> freq(n + 1, 0);
for (auto &e : a) {
cin >> e;
++freq[e];
}
int ans = 0;
FOR(i, 0, n) {
int total = 0;
FOR(j, i, n) {
total += a[j];
if (i != j && total <= n) {
ans += freq[total];
freq[total] = 0;
}
}
}
println(ans);
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

11
codeforces/640/e.in Normal file
View file

@ -0,0 +1,11 @@
5
9
3 1 4 1 5 9 2 6 5
3
1 1 2
5
1 1 1 1 1
8
8 7 6 5 4 3 2 1
1
1

5
codeforces/640/e.out Normal file
View file

@ -0,0 +1,5 @@
5
1
0
4
0

124
codeforces/640/f.cc Normal file
View file

@ -0,0 +1,124 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
if constexpr (std::is_convertible_v<T, char const *>) {
std::cout << t << '\n';
} else {
for (auto const &e : t) {
std::cout << e << ' ';
}
std::cout << '\n';
}
}
template <typename... Args>
void println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return std::numeric_limits<T>::min();
}
#define ff first
#define ss second
#define eb emplace_back
#define ll long long
#define ld long double
#define vec vector
#define all(x) (x).begin(), (x).end()
#define rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
int n0, n1, n2;
cin >> n0 >> n1 >> n2;
if (n1 == 0) {
char s = n0 ? '0' : '1';
cout << string(max(n0, n2) + 1, s) << '\n';
return;
}
string ans;
FOR(i, 0, n1 + 1)
ans += i & 1 ? '0' : '1';
ans.insert(1, string(n0, '0'));
ans = string(n2, '1') + ans;
println(ans);
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

9
codeforces/640/f.in Normal file
View file

@ -0,0 +1,9 @@
8
0 3 4
1 3 5
1 1 1
3 9 3
0 1 0
3 1 2
0 0 3
2 0 0

8
codeforces/640/f.out Normal file
View file

@ -0,0 +1,8 @@
11111010
1111110010
1100
1111000010101010
10
1110000
1111
000

174
codeforces/640/g.cc Normal file
View file

@ -0,0 +1,174 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
if constexpr (std::is_convertible_v<T, char const *>) {
std::cout << t << '\n';
} else {
for (auto const &e : t) {
std::cout << e << ' ';
}
std::cout << '\n';
}
}
template <typename... Args>
void println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return std::numeric_limits<T>::min();
}
#define ff first
#define ss second
#define eb emplace_back
#define ll long long
#define ld long double
#define vec vector
#define all(x) (x).begin(), (x).end()
#define rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
int n;
cin >> n;
/*
1, 4, 2, 5, 3, 6, 9, 7, 10, 8
1: 5, 7, 3, 6 -> pop -> 2, -4, 3
2: 5, 7, 3, 6, 8
3: 3, 7, 9, 6, 8 -> +4, +2, -3, +2
4: 3, -2, 3, -2
1, 4, 2, 5, 3, 7, 9, 6, 8
n = 4 -> 2 4 1 3
+1, +3, -2, +3, -2, +3, +3, -2, +3, -2
*/
if (n < 4) {
println(-1);
return;
}
if (n == 4) {
println("2 4 1 3");
return;
}
vec<int> ans{1};
int prev = 1;
--n;
while (n >= 5) {
for (auto diff : {3, -2, 3, -2, 3}) {
prev += diff;
ans.push_back(prev);
}
n -= 5;
}
vec<int> diff;
switch (n) {
case 1:
ans.pop_back();
ans.pop_back();
diff = {2, -4, 3};
break;
case 2:
ans.pop_back();
ans.pop_back();
diff = {2, -4, 3, 2};
break;
case 3:
ans.pop_back();
diff = {4, 2, -3, 2};
break;
case 4:
diff = {3, -2, 3, -2};
break;
}
for (auto d : diff) ans.push_back(ans[sz(ans) - 1] + d);
for (auto e : ans) cout << e << ' ';
println();
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

8
codeforces/640/g.in Normal file
View file

@ -0,0 +1,8 @@
7
10
2
4
6
7
9
13

7
codeforces/640/g.out Normal file
View file

@ -0,0 +1,7 @@
1 4 2 5 3 6 9 7 10 8
-1
2 4 1 3
1 4 2 5 3 6
1 4 2 5 7 3 6
1 4 2 5 3 7 9 6 8
1 4 2 5 3 6 9 7 10 12 8 11 13