feat(codeforces): 1017
This commit is contained in:
parent
375a673932
commit
f366180f50
31 changed files with 857 additions and 1 deletions
9
codeforces/1017/.clang-format
Normal file
9
codeforces/1017/.clang-format
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
BasedOnStyle: Google
|
||||||
|
AllowShortBlocksOnASingleLine: false
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortCompoundRequirementOnASingleLine: false
|
||||||
|
AllowShortEnumsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: false
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
AllowShortLambdasOnASingleLine: false
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
27
codeforces/1017/.clangd
Normal file
27
codeforces/1017/.clangd
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
CompileFlags:
|
||||||
|
Add:
|
||||||
|
- -std=c++20
|
||||||
|
- -Wall
|
||||||
|
- -Wextra
|
||||||
|
- -Wshadow
|
||||||
|
- -Wnon-virtual-dtor
|
||||||
|
- -Wold-style-cast
|
||||||
|
- -Wcast-align
|
||||||
|
- -Wunused
|
||||||
|
- -Woverloaded-virtual
|
||||||
|
- -Wpedantic
|
||||||
|
- -Wconversion
|
||||||
|
- -Wsign-conversion
|
||||||
|
- -Wmisleading-indentation
|
||||||
|
- -Wduplicated-cond
|
||||||
|
- -Wduplicated-branches
|
||||||
|
- -Wlogical-op
|
||||||
|
- -Wnull-dereference
|
||||||
|
- -Wuseless-cast
|
||||||
|
- -Wformat=2
|
||||||
|
- -Wformat-overflow
|
||||||
|
- -Wformat-truncation
|
||||||
|
- -Wdouble-promotion
|
||||||
|
- -Wundef
|
||||||
|
- -DLOCAL
|
||||||
|
- -Wno-unknown-pragmas
|
||||||
37
codeforces/1017/a.cc
Normal file
37
codeforces/1017/a.cc
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
#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;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using f64 = double;
|
||||||
|
using f128 = long double;
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
string a, b, c;
|
||||||
|
cin >> a >> b >> c;
|
||||||
|
cout << a[0] << b[0] << c[0] << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
int tc = 1;
|
||||||
|
cin >> tc;
|
||||||
|
|
||||||
|
for (int t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
8
codeforces/1017/a.in
Normal file
8
codeforces/1017/a.in
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
7
|
||||||
|
united states america
|
||||||
|
oh my god
|
||||||
|
i cant lie
|
||||||
|
binary indexed tree
|
||||||
|
believe in yourself
|
||||||
|
skibidi slay sigma
|
||||||
|
god bless america
|
||||||
10
codeforces/1017/a.out
Normal file
10
codeforces/1017/a.out
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
a.cc: In function ‘void solve()’:
|
||||||
|
a.cc:21:31: error: invalid operands of types ‘int’ and ‘<unresolved overloaded function type>’ to binary ‘operator<<’
|
||||||
|
21 | cout << a[0] << b[0] << c[0 << endl;
|
||||||
|
| ~~^~~~~~~
|
||||||
|
a.cc:21:38: error: expected ‘]’ before ‘;’ token
|
||||||
|
21 | cout << a[0] << b[0] << c[0 << endl;
|
||||||
|
| ^
|
||||||
|
| ]
|
||||||
|
|
||||||
|
[code]: 1
|
||||||
43
codeforces/1017/b.cc
Normal file
43
codeforces/1017/b.cc
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
#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;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using f64 = double;
|
||||||
|
using f128 = long double;
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
int n, m, l, r;
|
||||||
|
cin >> n >> m >> l >> r;
|
||||||
|
|
||||||
|
int lp = max(l, -m), rp = lp + m;
|
||||||
|
if (rp > r) {
|
||||||
|
rp = r;
|
||||||
|
lp = rp - m;
|
||||||
|
}
|
||||||
|
cout << lp << ' ' << rp << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
int tc = 1;
|
||||||
|
cin >> tc;
|
||||||
|
|
||||||
|
for (int t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
5
codeforces/1017/b.in
Normal file
5
codeforces/1017/b.in
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
4
|
||||||
|
4 2 -2 2
|
||||||
|
4 1 0 4
|
||||||
|
3 3 -1 2
|
||||||
|
9 8 -6 3
|
||||||
6
codeforces/1017/b.out
Normal file
6
codeforces/1017/b.out
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
-2 0
|
||||||
|
0 1
|
||||||
|
-1 2
|
||||||
|
-6 2
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
174
codeforces/1017/c.cc
Normal file
174
codeforces/1017/c.cc
Normal 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;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using f64 = double;
|
||||||
|
using f128 = long double;
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
#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 = null_type>
|
||||||
|
using hashtable = 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>>;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#ifdef PB_DS_TREE_POLICY_HPP
|
||||||
|
template <typename T>
|
||||||
|
using multitree = 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;
|
||||||
|
vector<vector<int>> grid((size_t)n, vector<int>(size_t(n)));
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
for (int j = 0; j < n; ++j) {
|
||||||
|
cin >> grid[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<int> ans(2 * size_t(n) + 1, 0);
|
||||||
|
hashtable<int> seen;
|
||||||
|
|
||||||
|
for (int k = 2; k <= 2 * n; ++k) {
|
||||||
|
int x = -1, good = 1;
|
||||||
|
for (int i = 1; i <= n; ++i) {
|
||||||
|
int j = k - i;
|
||||||
|
if (j >= 1 && j <= n) {
|
||||||
|
if (x == -1) {
|
||||||
|
x = grid[i - 1][j - 1];
|
||||||
|
} else if (grid[i - 1][j - 1] != x) {
|
||||||
|
good = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (good && x != -1) {
|
||||||
|
ans[k] = x;
|
||||||
|
seen.insert(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int first_candidate = 1; first_candidate <= 2 * n; ++first_candidate) {
|
||||||
|
if (seen.find(first_candidate) == seen.end()) {
|
||||||
|
cout << first_candidate << ' ';
|
||||||
|
for (size_t i = 2; i <= 2 * n; ++i) {
|
||||||
|
cout << ans[i] << ' ';
|
||||||
|
}
|
||||||
|
cout << '\n';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
int tc = 1;
|
||||||
|
cin >> tc;
|
||||||
|
|
||||||
|
for (int t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
10
codeforces/1017/c.in
Normal file
10
codeforces/1017/c.in
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
3
|
||||||
|
3
|
||||||
|
1 6 2
|
||||||
|
6 2 4
|
||||||
|
2 4 3
|
||||||
|
1
|
||||||
|
1
|
||||||
|
2
|
||||||
|
2 3
|
||||||
|
3 4
|
||||||
5
codeforces/1017/c.out
Normal file
5
codeforces/1017/c.out
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
5 1 6 2 4 3
|
||||||
|
2 1
|
||||||
|
1 2 3 4
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
24
codeforces/1017/compile_flags.txt
Normal file
24
codeforces/1017/compile_flags.txt
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
-std=c++20
|
||||||
|
-Wall
|
||||||
|
-Wextra
|
||||||
|
-Wshadow
|
||||||
|
-Wnon-virtual-dtor
|
||||||
|
-Wold-style-cast
|
||||||
|
-Wcast-align
|
||||||
|
-Wunused
|
||||||
|
-Woverloaded-virtual
|
||||||
|
-Wpedantic
|
||||||
|
-Wconversion
|
||||||
|
-Wsign-conversion
|
||||||
|
-Wmisleading-indentation
|
||||||
|
-Wduplicated-cond
|
||||||
|
-Wduplicated-branches
|
||||||
|
-Wlogical-op
|
||||||
|
-Wnull-dereference
|
||||||
|
-Wuseless-cast
|
||||||
|
-Wformat=2
|
||||||
|
-Wformat-overflow
|
||||||
|
-Wformat-truncation
|
||||||
|
-Wdouble-promotion
|
||||||
|
-Wundef
|
||||||
|
-DLOCAL
|
||||||
43
codeforces/1017/d.cc
Normal file
43
codeforces/1017/d.cc
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int x;
|
||||||
|
std::cin >> x;
|
||||||
|
|
||||||
|
while (x--) {
|
||||||
|
std::string p, s;
|
||||||
|
std::cin >> p >> s;
|
||||||
|
|
||||||
|
size_t pi = 0;
|
||||||
|
size_t si = 0;
|
||||||
|
while (pi < p.size() && si < s.size()) {
|
||||||
|
if (p[pi] != s[si]) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto TO_MATCH = p[pi];
|
||||||
|
|
||||||
|
size_t LEFT_POS_CHANGE = 0;
|
||||||
|
size_t RIGHT_POST_CHANGE = 0;
|
||||||
|
while (p[pi] == TO_MATCH) {
|
||||||
|
++LEFT_POS_CHANGE;
|
||||||
|
if (++pi == p.size())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
while (s[si] == TO_MATCH) {
|
||||||
|
++RIGHT_POST_CHANGE;
|
||||||
|
if (++si == s.size())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// clamp delta
|
||||||
|
if (RIGHT_POST_CHANGE < LEFT_POS_CHANGE ||
|
||||||
|
RIGHT_POST_CHANGE > 2 * LEFT_POS_CHANGE) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << (pi == p.size() && si == s.size() ? "YES\n" : "NO\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
11
codeforces/1017/d.in
Normal file
11
codeforces/1017/d.in
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
5
|
||||||
|
R
|
||||||
|
RR
|
||||||
|
LRLR
|
||||||
|
LRLR
|
||||||
|
LR
|
||||||
|
LLLR
|
||||||
|
LLLLLRL
|
||||||
|
LLLLRRLL
|
||||||
|
LLRLRLRRL
|
||||||
|
LLLRLRRLLRRRL
|
||||||
7
codeforces/1017/d.out
Normal file
7
codeforces/1017/d.out
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
YES
|
||||||
|
YES
|
||||||
|
NO
|
||||||
|
NO
|
||||||
|
YES
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
52
codeforces/1017/e.cc
Normal file
52
codeforces/1017/e.cc
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
#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;
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
size_t n;
|
||||||
|
cin >> n;
|
||||||
|
vector<long long> a(n);
|
||||||
|
for (auto& e : a)
|
||||||
|
cin >> e;
|
||||||
|
|
||||||
|
vector<long long> f(30, 0);
|
||||||
|
for (long long x : a) {
|
||||||
|
for (size_t bit = 0; bit < 30; ++bit) {
|
||||||
|
if (x & (1 << bit))
|
||||||
|
++f[bit];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long long ans = 0;
|
||||||
|
for (long long x : a) {
|
||||||
|
long long cur = 0;
|
||||||
|
for (long long bit = 0; bit < 30; ++bit) {
|
||||||
|
// add left/right accordingly
|
||||||
|
cur += (x & (1 << bit)) ? ((n - f[bit]) * (1 << bit))
|
||||||
|
: (f[bit] * (1 << bit));
|
||||||
|
}
|
||||||
|
ans = max(ans, cur);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << ans << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
int tc = 1;
|
||||||
|
cin >> tc;
|
||||||
|
|
||||||
|
for (long long t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
11
codeforces/1017/e.in
Normal file
11
codeforces/1017/e.in
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
5
|
||||||
|
3
|
||||||
|
18 18 18
|
||||||
|
5
|
||||||
|
1 2 4 8 16
|
||||||
|
5
|
||||||
|
8 13 4 5 15
|
||||||
|
6
|
||||||
|
625 676 729 784 841 900
|
||||||
|
1
|
||||||
|
1
|
||||||
7
codeforces/1017/e.out
Normal file
7
codeforces/1017/e.out
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
0
|
||||||
|
79
|
||||||
|
37
|
||||||
|
1555
|
||||||
|
0
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
59
codeforces/1017/f.cc
Normal file
59
codeforces/1017/f.cc
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
#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;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using f64 = double;
|
||||||
|
using f128 = long double;
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
i32 n, m, k;
|
||||||
|
cin >> n >> m >> k;
|
||||||
|
|
||||||
|
if (n > m) {
|
||||||
|
swap(n, m);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3x4 -> [1, 2 ,1, 2]
|
||||||
|
// [2, 1, 2, 1]
|
||||||
|
// [1, 2, 1, 2]
|
||||||
|
|
||||||
|
// if even # cols/rows -> ez (i.e. either even, swap)
|
||||||
|
// REDUCE: odd # cols & rows
|
||||||
|
// [1, 2, 3]
|
||||||
|
// [2, 3, 1]
|
||||||
|
// [3, 2, 1]
|
||||||
|
|
||||||
|
|
||||||
|
i32 cur = -1;
|
||||||
|
if (n & 1 && m & 1) {
|
||||||
|
cur = (cur + 1) % m;
|
||||||
|
for (i32 i = 0; i < n; ++i) {
|
||||||
|
for ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
int tc = 1;
|
||||||
|
cin >> tc;
|
||||||
|
|
||||||
|
for (int t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
4
codeforces/1017/f.in
Normal file
4
codeforces/1017/f.in
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
3
|
||||||
|
2 2 2
|
||||||
|
3 4 6
|
||||||
|
5 5 25
|
||||||
12
codeforces/1017/f.out
Normal file
12
codeforces/1017/f.out
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
1 2
|
||||||
|
2 1
|
||||||
|
1 2 3 4
|
||||||
|
2 3 4 5
|
||||||
|
3 4 5 6
|
||||||
|
1 2 3 4 5
|
||||||
|
2 3 4 5 6
|
||||||
|
3 4 5 6 7
|
||||||
|
4 5 6 7 8
|
||||||
|
5 6 7 8 9
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
73
codeforces/1017/g.cc
Normal file
73
codeforces/1017/g.cc
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
#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;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using f64 = double;
|
||||||
|
using f128 = long double;
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
i32 q;
|
||||||
|
cin >> q;
|
||||||
|
|
||||||
|
deque<i64> dq;
|
||||||
|
i64 S = 0;
|
||||||
|
i64 total = 0;
|
||||||
|
bool reversed = false;
|
||||||
|
|
||||||
|
while (q--) {
|
||||||
|
i32 cmd;
|
||||||
|
cin >> cmd;
|
||||||
|
|
||||||
|
if (cmd == 1) { // left cyclic shift
|
||||||
|
if (reversed) {
|
||||||
|
S += total - dq.front() * dq.size();
|
||||||
|
dq.push_back(dq.front());
|
||||||
|
dq.pop_front();
|
||||||
|
} else {
|
||||||
|
S += total - dq.back() * dq.size();
|
||||||
|
dq.push_front(dq.back());
|
||||||
|
dq.pop_back();
|
||||||
|
}
|
||||||
|
} else if (cmd == 2) { // reverse
|
||||||
|
S = ((i64)dq.size() + 1) * total - S;
|
||||||
|
reversed ^= 1;
|
||||||
|
} else { // append
|
||||||
|
i64 k;
|
||||||
|
cin >> k;
|
||||||
|
if (reversed) {
|
||||||
|
dq.push_front(k);
|
||||||
|
} else {
|
||||||
|
dq.push_back(k);
|
||||||
|
}
|
||||||
|
total += k;
|
||||||
|
S += k * dq.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << S << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
int tc = 1;
|
||||||
|
cin >> tc;
|
||||||
|
|
||||||
|
for (int t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
15
codeforces/1017/g.in
Normal file
15
codeforces/1017/g.in
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
1
|
||||||
|
13
|
||||||
|
3 1
|
||||||
|
3 2
|
||||||
|
3 3
|
||||||
|
1
|
||||||
|
3 4
|
||||||
|
2
|
||||||
|
3 5
|
||||||
|
1
|
||||||
|
3 6
|
||||||
|
2
|
||||||
|
3 7
|
||||||
|
2
|
||||||
|
1
|
||||||
15
codeforces/1017/g.out
Normal file
15
codeforces/1017/g.out
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
1
|
||||||
|
5
|
||||||
|
14
|
||||||
|
11
|
||||||
|
27
|
||||||
|
23
|
||||||
|
48
|
||||||
|
38
|
||||||
|
74
|
||||||
|
73
|
||||||
|
122
|
||||||
|
102
|
||||||
|
88
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
44
codeforces/1017/h.cc
Normal file
44
codeforces/1017/h.cc
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
#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;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using f64 = double;
|
||||||
|
using f128 = long double;
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
i32 n, q;
|
||||||
|
cin >> n >> q;
|
||||||
|
vector<i32> a(n);
|
||||||
|
for (auto& e : a) cin >> e;
|
||||||
|
i32 k, l, r;
|
||||||
|
while (q--) {
|
||||||
|
cin >> k >> l >> r;
|
||||||
|
// perceived as a[i] / k (WRONG)
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
int tc = 1;
|
||||||
|
cin >> tc;
|
||||||
|
|
||||||
|
for (int t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
11
codeforces/1017/h.in
Normal file
11
codeforces/1017/h.in
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
2
|
||||||
|
5 3
|
||||||
|
2 3 5 7 11
|
||||||
|
2 1 5
|
||||||
|
2 2 4
|
||||||
|
2310 1 5
|
||||||
|
4 3
|
||||||
|
18 12 8 9
|
||||||
|
216 1 2
|
||||||
|
48 2 4
|
||||||
|
82944 1 4
|
||||||
0
codeforces/1017/h.out
Normal file
0
codeforces/1017/h.out
Normal file
95
codeforces/1017/makefile
Normal file
95
codeforces/1017/makefile
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
.PHONY: run debug clean setup init
|
||||||
|
|
||||||
|
CXX = g++
|
||||||
|
# lefticus.gitbooks.io/cpp-best-practice
|
||||||
|
CXXFLAGS := -O2 -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 \
|
||||||
|
-Wfloat-equal -Wlogical-op -Wshift-overflow=2 -Wnon-virtual-dtor \
|
||||||
|
-Wold-style-cast -Wcast-equal -Wuseless-cast -Wno-sign-promotion \
|
||||||
|
-Wcast-align -Wunused -Woverloaded-virtual -Wconversion \
|
||||||
|
-Wsign-conversion -Wmisleading-indentation -Wduplicated-cond \
|
||||||
|
-Wduplicated-branches -Wlogical-op -Wnull-dereference -Wformat=2 \
|
||||||
|
-Wformat-overflow -Wformat-truncation -Wdouble-promotion -Wundef \
|
||||||
|
-DLOCAL -std=c++20
|
||||||
|
|
||||||
|
# https://interrupt.memfault.com/blog/best-and-worst-gcc-clang-compiler-flags
|
||||||
|
DEBUG_CXX_FLAGS := -g3 -fsanitize=address,undefined \
|
||||||
|
-fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow \
|
||||||
|
-fno-sanitize-recover=all -fstack-protector-all -fstack-usage \
|
||||||
|
-fno-omit-frame-pointer -fno-inline -ffunction-sections
|
||||||
|
|
||||||
|
DEBUG_CXXFLAGS += -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
|
||||||
|
|
||||||
|
SRC = $(word 2,$(MAKECMDGOALS))
|
||||||
|
BASE = $(basename $(SRC))
|
||||||
|
INPUT = $(BASE).in
|
||||||
|
OUTPUT = $(BASE).out
|
||||||
|
RUN_BIN = $(BASE).run
|
||||||
|
DBG_BIN = $(BASE).debug
|
||||||
|
|
||||||
|
TEMPLATE_DIR = ~/.config/cp-template
|
||||||
|
|
||||||
|
.SILENT:
|
||||||
|
|
||||||
|
run: $(RUN_BIN)
|
||||||
|
$(call execute_binary,$(RUN_BIN))
|
||||||
|
|
||||||
|
debug: $(DBG_BIN)
|
||||||
|
$(call execute_binary,$(DBG_BIN))
|
||||||
|
|
||||||
|
$(RUN_BIN): $(SRC)
|
||||||
|
test -f $@ && rm $@ || true
|
||||||
|
$(CXX) @compile_flags.txt $(SRC) -o $@ 2>$(OUTPUT); \
|
||||||
|
CODE=$$?; \
|
||||||
|
if [ $${CODE} -gt 0 ]; then \
|
||||||
|
printf '\n[code]: %s' $${CODE} >>$(OUTPUT); \
|
||||||
|
exit $${CODE}; \
|
||||||
|
else \
|
||||||
|
echo '' >$(OUTPUT); \
|
||||||
|
fi
|
||||||
|
|
||||||
|
$(DBG_BIN): $(SRC)
|
||||||
|
test -f $@ && rm $@ || true
|
||||||
|
$(CXX) @compile_flags.txt $(DEBUG_CXX_FLAGS) $(SRC) -o $@ 2>$(OUTPUT); \
|
||||||
|
CODE=$$?; \
|
||||||
|
if [ $${CODE} -gt 0 ]; then \
|
||||||
|
printf '\n[code]: %s' $${CODE} >>$(OUTPUT); \
|
||||||
|
exit $${CODE}; \
|
||||||
|
else \
|
||||||
|
echo '' >$(OUTPUT); \
|
||||||
|
fi
|
||||||
|
|
||||||
|
define execute_binary
|
||||||
|
timeout 2s ./$1 < $(INPUT) >$(OUTPUT) 2>&1; \
|
||||||
|
CODE=$$?; \
|
||||||
|
truncate -s $$(head -n 1000 $(OUTPUT) | wc -c) $(OUTPUT); \
|
||||||
|
if [ $${CODE} -ge 124 ]; then \
|
||||||
|
MSG=''; \
|
||||||
|
case $${CODE} in \
|
||||||
|
124) MSG='TIMEOUT';; \
|
||||||
|
128) MSG='SIGILL';; \
|
||||||
|
130) MSG='SIGABRT';; \
|
||||||
|
131) MSG='SIGBUS';; \
|
||||||
|
136) MSG='SIGFPE';; \
|
||||||
|
135) MSG='SIGSEGV';; \
|
||||||
|
137) MSG='SIGPIPE';; \
|
||||||
|
139) MSG='SIGTERM';; \
|
||||||
|
esac; \
|
||||||
|
[ -n "$${MSG}" ] && printf '\n[code]: %s (%s)' "$${CODE}" "$${MSG}" >>$(OUTPUT); \
|
||||||
|
else \
|
||||||
|
printf '\n[code]: %s' $${CODE} >>$(OUTPUT); \
|
||||||
|
fi
|
||||||
|
endef
|
||||||
|
|
||||||
|
clean:
|
||||||
|
find . -type f -name "*.run" -o -name "*.debug" -o -name "*.su" | xargs rm -f
|
||||||
|
|
||||||
|
setup:
|
||||||
|
test -f compile_flags.txt || cp $(TEMPLATE_DIR)/compile_flags.txt .
|
||||||
|
test -f .clangd || cp $(TEMPLATE_DIR)/.clangd .
|
||||||
|
test -f .clang-format || cp $(TEMPLATE_DIR)/.clang-format .
|
||||||
|
|
||||||
|
init:
|
||||||
|
make setup
|
||||||
|
|
||||||
|
%:
|
||||||
|
@:
|
||||||
|
|
@ -45,7 +45,7 @@ void solve() {
|
||||||
if (a[l] == 0) {
|
if (a[l] == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// NOTE: while loop instead of maintaing invariant
|
// NOTE: i wrote a while loop instead of maintaing invariant
|
||||||
++r;
|
++r;
|
||||||
while (r < n && a[r] == 0) {
|
while (r < n && a[r] == 0) {
|
||||||
++r;
|
++r;
|
||||||
|
|
|
||||||
39
codeforces/799/h.cc
Normal file
39
codeforces/799/h.cc
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
#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;
|
||||||
|
|
||||||
|
#define prln(...) std::println(__VA_ARGS__)
|
||||||
|
#define pr(...) std::print(__VA_ARGS__)
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
#define dbgln(...) std::println(__VA_ARGS__)
|
||||||
|
#define dbg(...) std::print(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define dbgln(...)
|
||||||
|
#define dbg(...)
|
||||||
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
int tc = 1;
|
||||||
|
cin >> tc;
|
||||||
|
|
||||||
|
for (int t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
0
codeforces/799/h.in
Normal file
0
codeforces/799/h.in
Normal file
Loading…
Add table
Add a link
Reference in a new issue