fea: more contests

This commit is contained in:
Barrett Ruth 2025-05-16 22:04:03 -05:00
parent 00d23dc313
commit c65a12a652
103 changed files with 3871 additions and 143 deletions

View file

@ -0,0 +1,9 @@
BasedOnStyle: Google
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: false
AllowShortLoopsOnASingleLine: false

45
codeforces/827/.clangd Normal file
View file

@ -0,0 +1,45 @@
CompileFlags:
Add:
-O2
-Wall
-Wextra
-Wpedantic
-Wshadow
-Wformat=2
-Wfloat-equal
-Wlogical-op
-Wshift-overflow=2
-Wnon-virtual-dtor
-Wold-style-cast
-Wcast-qual
-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
-Wno-unknown-pragmas
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23

85
codeforces/827/a.cc Normal file
View file

@ -0,0 +1,85 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
u32 a, b, c;
cin >> a >> b >> c;
vector<u32> X{a, b, c};
sort(all(X));
if (X[0] + X[1] == X[2]) {
YES();
} else {
NO();
}
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

90
codeforces/827/b.cc Normal file
View file

@ -0,0 +1,90 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
u32 n;
cin >> n;
vector<u32> a(n);
for (auto& e : a)
cin >> e;
sort(all(a));
for (u32 i = 0; i < n - 1; ++i) {
if (!(a[i] < a[i + 1])) {
NO();
return;
}
}
YES();
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

100
codeforces/827/c.cc Normal file
View file

@ -0,0 +1,100 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
vector<string> grid(8);
for (auto& e : grid)
cin >> e;
for (u32 r = 0; r < 8; ++r) {
bool good = true;
for (u32 c = 0; c < 8; ++c) {
good &= grid[r][c] == grid[r][0];
}
if (good && grid[r][0] == 'R') {
cout << grid[r][0] << '\n';
return;
}
}
for (u32 c = 0; c < 8; ++c) {
bool good = true;
for (u32 r = 0; r < 8; ++r) {
good &= grid[r][c] == grid[0][c];
}
if (good && grid[0][c] == 'B') {
cout << grid[0][c] << '\n';
return;
}
}
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

View file

@ -0,0 +1,30 @@
-O2
-Wall
-Wextra
-Wpedantic
-Wshadow
-Wformat=2
-Wfloat-equal
-Wlogical-op
-Wshift-overflow=2
-Wnon-virtual-dtor
-Wold-style-cast
-Wcast-qual
-Wuseless-cast
-Wno-sign-promotion
-Wcast-align
-Wunused
-Woverloaded-virtual
-Wconversion
-Wmisleading-indentation
-Wduplicated-cond
-Wduplicated-branches
-Wlogical-op
-Wnull-dereference
-Wformat=2
-Wformat-overflow
-Wformat-truncation
-Wdouble-promotion
-Wundef
-DLOCAL
-std=c++23

123
codeforces/827/d.cc Normal file
View file

@ -0,0 +1,123 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
/*
a[i] has factors S, |S| < = log2(MAX_A[i] = 1000)
want to find rightmost j > i s.t. no common factors
factor -> [a[i] divisible by]
iter thru factors of a[i]
if i have log2(a[i]) factors;
there are 10^6 factors total
there are 10 factors here
so, factor each a[i], and manually compute
*/
u32 n;
cin >> n;
vector<u32> a(n);
for (auto& e : a)
cin >> e;
vector<bitset<1001>> coprime(1001);
for (u32 i = 1; i <= 1000; ++i) {
for (u32 j = 1; j <= 1000; ++j) {
coprime[i][j] = gcd(i, j) == 1;
}
}
vector<u32> right(1001, -1);
for (u32 i = 0; i < n; ++i) {
right[a[i]] = i;
}
u32 ans = 0;
for (i32 i = 1; i <= 1000; ++i) {
for (u32 j = 1; j <= 1000; ++j) {
if (coprime[i][j] && right[i] != -1 && right[j] != -1) {
ans = max(ans, right[i] + right[j] + 2);
}
}
}
if (ans == 0)
cout << -1;
else
cout << ans;
cout << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

View file

@ -0,0 +1,14 @@
-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
-D_GLIBCXX_DEBUG
-D_GLIBCXX_DEBUG_PEDANTIC
-DLOCAL
-std=c++23

128
codeforces/827/e.cc Normal file
View file

@ -0,0 +1,128 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
u32 n, q;
cin >> n >> q;
vec<u64> a(n);
vec<u64> biggest_step(n + 1, 0), prefix(n + 1, 0);
for (u32 i = 0; i < n; ++i) {
cin >> a[i];
biggest_step[i + 1] = max(biggest_step[i], a[i]);
prefix[i + 1] = prefix[i] + a[i];
}
u64 k;
for (u32 i = 0; i < q; ++i) {
cin >> k;
u32 d =
distance(biggest_step.begin(), upper_bound(all(biggest_step), k)) - 1;
cout << prefix[d] << " \n"[i == q - 1];
}
// vec<u64> a(n + 1);
// a[0] = 0;
// for (u32 i = 1; i <= n; ++i) {
// cin >> a[i];
// a[i] += a[i - 1];
// }
// u64 k;
// vec<pair<u64, u32>> questions(q);
// vec<u64> ans(q);
//
// for (u32 i = 0; i < q; ++i) {
// cin >> questions[i].ff;
// questions[i].ss = i;
// }
//
// sort(all(questions));
//
// u32 j = 0;
// for (auto& [k, i] : questions) {
// u32 J = j;
// while (J <= n && a[J] <= k + (J ? a[J - 1] : 0))
// ++J;
//
// if (J > j) {
// j = J - 1;
// }
//
// ans[i] = a[j];
// }
//
// for (u32 i = 0; i < q; ++i) {
// cout << ans[i] << " \n"[i == q - 1];
// }
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

124
codeforces/827/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;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
u32 q;
cin >> q;
vec<u64> S(26, 0), T(26, 0);
u64 scount = 1, tcount = 1;
S[0] = T[0] = 1;
u64 cmd, k;
string x;
for (u64 i = 0; i < q; ++i) {
cin >> cmd >> k >> x;
if (cmd == 1) {
for (auto c : x) {
S[c - 'a'] += k;
}
scount += k * x.size();
} else {
for (auto c : x) {
T[c - 'a'] += k;
}
tcount += k * x.size();
}
int loS = 0;
while (loS < 26 && S[loS] == 0)
++loS;
int hiT = 25;
while (hiT >= 0 && T[hiT] == 0)
--hiT;
bool ok;
if (loS < hiT) {
ok = true;
} else if (loS > hiT) {
ok = false;
} else {
int c = loS;
bool biggerInS = false;
for (int ch = c + 1; ch < 26 && !biggerInS; ++ch)
biggerInS = S[ch] > 0;
if (biggerInS)
ok = false;
else
ok = S[c] < T[c];
}
cout << (ok ? "YES\n" : "NO\n");
}
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

118
codeforces/827/g.cc Normal file
View file

@ -0,0 +1,118 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
bitset<2 * 100000 + 1> seen;
void solve() {
seen.reset();
u32 n;
cin >> n;
vec<u32> a(n);
for (auto& e : a)
cin >> e;
vec<u32> ans;
u32 prefix_or = 0;
for (u32 i = 0; i < 31; ++i) {
u32 current_or = prefix_or;
i32 index = -1;
for (u32 j = 0; j < n; ++j) {
if (seen[j])
continue;
if ((prefix_or | a[j]) > current_or) {
current_or = prefix_or | a[j];
index = j;
}
}
if (index == -1)
break;
ans.push_back(a[index]);
seen[index] = true;
prefix_or = current_or;
}
for (u32 i = 0; i < n; ++i) {
if (!seen[i]) {
ans.push_back(a[i]);
}
}
for (u32 i = 0; i < n; ++i) {
cout << ans[i] << " \n"[i == n - 1];
}
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

9
codeforces/827/io/a.in Normal file
View file

@ -0,0 +1,9 @@
7
1 4 3
2 5 8
9 11 20
0 0 0
20 20 20
4 12 3
15 7 8

10
codeforces/827/io/a.out Normal file
View file

@ -0,0 +1,10 @@
YES
NO
YES
YES
NO
NO
YES
[code]: 0
[time]: 11.7166 ms

7
codeforces/827/io/b.in Normal file
View file

@ -0,0 +1,7 @@
3
4
1 1 1 1
5
8 7 1 3 4
1
5

6
codeforces/827/io/b.out Normal file
View file

@ -0,0 +1,6 @@
NO
YES
YES
[code]: 0
[time]: 3.60322 ms

41
codeforces/827/io/c.in Normal file
View file

@ -0,0 +1,41 @@
4
....B...
....B...
....B...
RRRRRRRR
....B...
....B...
....B...
....B...
RRRRRRRB
B......B
B......B
B......B
B......B
B......B
B......B
RRRRRRRB
RRRRRRBB
.B.B..BB
RRRRRRBB
.B.B..BB
.B.B..BB
RRRRRRBB
.B.B..BB
.B.B..BB
........
........
........
RRRRRRRR
........
........
........
........

7
codeforces/827/io/c.out Normal file
View file

@ -0,0 +1,7 @@
R
B
B
R
[code]: 0
[time]: 10.8039 ms

13
codeforces/827/io/d.in Normal file
View file

@ -0,0 +1,13 @@
6
3
3 2 1
7
1 3 5 2 4 7 7
5
1 2 3 4 5
3
2 2 4
6
5 4 3 15 12 16
5
1 2 2 3 6

9
codeforces/827/io/d.out Normal file
View file

@ -0,0 +1,9 @@
6
12
9
-1
10
7
[code]: 0
[time]: 107.307 ms

10
codeforces/827/io/e.in Normal file
View file

@ -0,0 +1,10 @@
3
4 5
1 2 1 5
1 2 4 9 10
2 2
1 1
0 1
3 1
1000000000 1000000000 1000000000
1000000000

6
codeforces/827/io/e.out Normal file
View file

@ -0,0 +1,6 @@
1 4 4 9 9
0 2
3000000000
[code]: 0
[time]: 4.2367 ms

14
codeforces/827/io/f.in Normal file
View file

@ -0,0 +1,14 @@
3
5
2 1 aa
1 2 a
2 3 a
1 2 b
2 3 abca
2
1 5 mihai
2 2 buiucani
3
1 5 b
2 3 a
2 4 paiu

13
codeforces/827/io/f.out Normal file
View file

@ -0,0 +1,13 @@
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
[code]: 0
[time]: 3.97944 ms

11
codeforces/827/io/g.in Normal file
View file

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

8
codeforces/827/io/g.out Normal file
View file

@ -0,0 +1,8 @@
8 4 2 1
5 2 1 3 4 5 5
101 1
4 3 2 2 3 4
7 1 4 2 3 4 5 1
[code]: 0
[time]: 3.94392 ms

30
codeforces/827/makefile Normal file
View file

@ -0,0 +1,30 @@
.PHONY: run debug clean setup init
VERSION ?= 20
SRC = $(word 2,$(MAKECMDGOALS))
.SILENT:
run:
sh scripts/run.sh $(SRC)
debug:
sh scripts/debug.sh $(SRC)
clean:
rm -rf build/*
setup:
test -d build || mkdir -p build
test -d io || mkdir -p io
test -d scripts || mkdir -p scripts
test -f .clang-format || cp $(HOME)/.config/cp-template/.clang-format .
test -f compile_flags.txt || cp $(HOME)/.config/cp-template/compile_flags.txt . && echo -std=c++$(VERSION) >>compile_flags.txt
test -f .clangd || cp $(HOME)/.config/cp-template/.clangd . && echo -e "\t\t-std=c++$(VERSION)" >>.clangd
init:
make setup
%:
@:

View file

@ -0,0 +1,29 @@
#!/bin/sh
. ./scripts/utils.sh
SRC="$1"
BASE=$(basename "$SRC" .cc)
INPUT="${BASE}.in"
OUTPUT="${BASE}.out"
DBG_BIN="${BASE}.debug"
test -d build || mkdir -p build
test -d io || mkdir -p io
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
test -f "io/$INPUT" || touch "io/$INPUT"
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
INPUT="io/$INPUT"
OUTPUT="io/$OUTPUT"
DBG_BIN="build/$DBG_BIN"
compile_source "$SRC" "$DBG_BIN" "$OUTPUT" @debug_flags.txt
CODE=$?
test $CODE -gt 0 && exit $CODE
execute_binary "$DBG_BIN" "$INPUT" "$OUTPUT"
exit $?

View file

@ -0,0 +1,29 @@
#!/bin/sh
. ./scripts/utils.sh
SRC="$1"
BASE=$(basename "$SRC" .cc)
INPUT="${BASE}.in"
OUTPUT="${BASE}.out"
RUN_BIN="${BASE}.run"
test -d build || mkdir -p build
test -d io || mkdir -p io
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
test -f "io/$INPUT" || touch "io/$INPUT"
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
INPUT="io/$INPUT"
OUTPUT="io/$OUTPUT"
RUN_BIN="build/$RUN_BIN"
compile_source "$SRC" "$RUN_BIN" "$OUTPUT" ""
CODE=$?
test $CODE -gt 0 && exit $CODE
execute_binary "$RUN_BIN" "$INPUT" "$OUTPUT"
exit $?

View file

@ -0,0 +1,53 @@
#!/bin/sh
execute_binary() {
binary="$1"
input="$2"
output="$3"
start=$(date '+%s.%N')
timeout 2s ./"$binary" <"$input" >"$output" 2>&1
CODE=$?
end=$(date '+%s.%N')
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
[ $CODE -ne 124 ] && sed -i '$d' "$output"
test -n "$MSG" && printf '\n[code]: %s (%s)' "$CODE" "$MSG" >>"$output"
else
printf '\n[code]: %s' "$CODE" >>"$output"
fi
printf '\n[time]: %s ms' "$(awk "BEGIN {print ($end - $start) * 1000}")" >>$output
return $CODE
}
compile_source() {
src="$1"
bin="$2"
output="$3"
flags="$4"
test -f "$bin" && rm "$bin" || true
g++ @compile_flags.txt $flags "$src" -o "$bin" 2>"$output"
CODE=$?
if [ $CODE -gt 0 ]; then
printf '\n[code]: %s' "$CODE" >>"$output"
return $CODE
else
echo '' >"$output"
return 0
fi
}

View file

@ -5,4 +5,6 @@ CompileFlags:
- -Wpedantic
- -Wshadow
- -DLOCAL
- -Wno-unknown-pragmas
- -Wno-unknown-pragmas -std=c++23
-std=c++23
-std=c++23

View file

@ -16,7 +16,6 @@
-Wunused
-Woverloaded-virtual
-Wconversion
-Wsign-conversion
-Wmisleading-indentation
-Wduplicated-cond
-Wduplicated-branches

View file

@ -10,3 +10,5 @@
-ffunction-sections
-D_GLIBCXX_DEBUG
-D_GLIBCXX_DEBUG_PEDANTIC
-DLOCAL
-std=c++20

View file

@ -1,5 +1,7 @@
.PHONY: run debug clean setup init
VERSION ?= 20
SRC = $(word 2,$(MAKECMDGOALS))
.SILENT:
@ -17,9 +19,8 @@ setup:
test -d build || mkdir -p build
test -d io || mkdir -p io
test -d scripts || mkdir -p scripts
test -f compile_flags.txt || cp $(HOME)/.config/cp-template/compile_flags.txt .
test -f .clangd || cp $(HOME)/.config/cp-template/.clangd .
test -f .clang-format || cp $(HOME)/.config/cp-template/.clang-format .
test -f compile_flags.txt || cp $(HOME)/.config/cp-template/compile_flags.txt . && echo -std=c++$(VERSION) >>compile_flags.txt
test -f .clangd || cp $(HOME)/.config/cp-template/.clangd . && echo -e "\t\t-std=c++$(VERSION)" >>.clangd
init:
make setup

View file

@ -0,0 +1,9 @@
BasedOnStyle: Google
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: false
AllowShortLoopsOnASingleLine: false

45
codeforces/903/.clangd Normal file
View file

@ -0,0 +1,45 @@
CompileFlags:
Add:
-O2
-Wall
-Wextra
-Wpedantic
-Wshadow
-Wformat=2
-Wfloat-equal
-Wlogical-op
-Wshift-overflow=2
-Wnon-virtual-dtor
-Wold-style-cast
-Wcast-qual
-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
-Wno-unknown-pragmas
-std=c++23
-std=c++20
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23

91
codeforces/903/a.cc Normal file
View file

@ -0,0 +1,91 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto &&x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto &&x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
u32 n, m;
cin >> n >> m;
string N, M;
cin >> N >> M;
string cur = N;
for (u32 ans = 0; ans <= 5; ++ans) {
if (cur.find(M) != string::npos) {
cout << ans << '\n';
return;
}
cur += cur;
}
cout << "-1\n";
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

106
codeforces/903/b.cc Normal file
View file

@ -0,0 +1,106 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
u32 a, b, c;
cin >> a >> b >> c;
for (u32 mask = 0; mask < (1 << 9) - 1; ++mask) {
if (__builtin_popcount(mask) > 3)
continue;
u32 right = __builtin_popcount(mask & ((1 << 3) - 1));
u32 mid = __builtin_popcount((mask >> 3) & ((1 << 3) - 1));
u32 left = __builtin_popcount((mask >> 6) & ((1 << 3) - 1));
if (left && a % (left + 1))
continue;
if (mid && b % (mid + 1))
continue;
if (right && c % (right + 1))
continue;
u32 A = left ? a / (left + 1) : a;
u32 B = mid ? b / (mid + 1) : b;
u32 C = right ? c / (right + 1) : c;
if (A == B && B == C) {
YES();
return;
}
}
NO();
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

113
codeforces/903/c.cc Normal file
View file

@ -0,0 +1,113 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
u32 n;
cin >> n;
vector<string> grid(n);
for (auto& e : grid)
cin >> e;
/*
core strategy: walk every char in tL region, find other 3 matching chars
rotationally
- find formula
sort, dist is sum of char distances for each smaller than biggest (can only
inc char)
this is ans
optimizes walking "rin"
impl: fill in grid as we go fore easer coverage
actually, just walk top side
*/
u32 ans = 0;
for (i32 r = 0; r < n / 2; ++r) {
// NOTE: missed this condition + other vars, made unecessary
// // no need for pairs
// why is auto comment on, fix the autogroup
for (i32 c = r; c < n - 1 - r; ++c) {
char big = max({grid[r][c], grid[c][n - 1 - r],
grid[n - 1 - r][n - 1 - c], grid[n - 1 - c][r]});
ans += big - grid[r][c];
ans += big - grid[c][n - 1 - r];
ans += big - grid[n - 1 - r][n - 1 - c];
ans += big - grid[n - 1 - c][r];
}
}
cout << ans << endl;
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

View file

@ -0,0 +1,30 @@
-O2
-Wall
-Wextra
-Wpedantic
-Wshadow
-Wformat=2
-Wfloat-equal
-Wlogical-op
-Wshift-overflow=2
-Wnon-virtual-dtor
-Wold-style-cast
-Wcast-qual
-Wuseless-cast
-Wno-sign-promotion
-Wcast-align
-Wunused
-Woverloaded-virtual
-Wconversion
-Wmisleading-indentation
-Wduplicated-cond
-Wduplicated-branches
-Wlogical-op
-Wnull-dereference
-Wformat=2
-Wformat-overflow
-Wformat-truncation
-Wdouble-promotion
-Wundef
-DLOCAL
-std=c++23

132
codeforces/903/d.cc Normal file
View file

@ -0,0 +1,132 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
unordered_map<u32, u32> factor_counts;
vector<u32> primes;
void solve() {
u32 n;
cin >> n;
vector<u32> a(n);
for (auto& e : a)
cin >> e;
factor_counts.clear();
// NOTE: factorization skills are weak,. i.e. number theory and prime
// factorization i.e. skipping over 2
// also could binary search
// // NOTE: thought it was "minimum operations" complicating it
for (auto e : a) {
for (const auto& p : primes) {
if (p * p > e)
break;
u32 count = 0;
while (e % p == 0) {
++count;
e /= p;
}
if (count > 0) {
factor_counts[p] += count;
}
}
if (e > 1) {
++factor_counts[e];
}
}
for (const auto& [factor, count] : factor_counts) {
if (count % n) {
NO();
return;
}
}
YES();
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
vector<bool> P(10001, true);
P[0] = P[1] = false;
for (u32 p = 2; p * p <= 10000; ++p) {
if (P[p]) {
for (u32 i = p * p; i <= 10000; i += p) {
P[i] = false;
}
}
}
for (u32 i = 2; i <= 10000; ++i) {
if (P[i]) {
primes.push_back(i);
}
}
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

View file

@ -0,0 +1,14 @@
-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
-D_GLIBCXX_DEBUG
-D_GLIBCXX_DEBUG_PEDANTIC
-DLOCAL
-std=c++20

96
codeforces/903/e.cc Normal file
View file

@ -0,0 +1,96 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
u32 n;
cin >> n;
vector<u32> a(n);
for (auto& x : a)
cin >> x;
vector<u32> dp(n + 1, n);
dp[n] = 0;
for (i32 i = n - 1; i >= 0; --i) {
u32 dont = 1 + dp[i + 1];
u32 take = i + a[i] + 1;
if (take <= n)
dont = min(dont, dp[take]);
dp[i] = dont;
}
cout << dp[0] << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

142
codeforces/903/f.cc Normal file
View file

@ -0,0 +1,142 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
const u32 MAXN = 2 * 1e5 + 1;
bitset<MAXN> marked, seen;
vector<vector<u32>> tree(MAXN);
deque<u32> q;
void solve() {
u32 n, k;
cin >> n >> k;
marked.reset();
tree.assign(n + 1, vector<u32>());
u32 node;
for (u32 i = 0; i < k; ++i) {
cin >> node;
marked[node] = true;
}
u32 u, v;
for (u32 i = 0; i < n - 1; ++i) {
cin >> u >> v;
tree[u].emplace_back(v);
tree[v].emplace_back(u);
}
q.clear();
q.push_back(node);
seen.reset();
u32 last = node;
while (!q.empty()) {
auto top = q.front();
q.pop_front();
seen[top] = true;
if (marked[top])
last = top;
for (auto& neighbor : tree[top]) {
if (!seen[neighbor]) {
q.push_back(neighbor);
}
}
}
q.clear();
q.push_back(last);
seen.reset();
u32 ans = 0, d = 0;
while (!q.empty()) {
++d;
u32 size = q.size();
for (u32 i = 0; i < size; ++i) {
auto top = q.front();
q.pop_front();
if (marked[top])
ans = max(ans, d);
seen[top] = true;
for (auto& neighbor : tree[top]) {
if (!seen[neighbor]) {
q.push_back(neighbor);
}
}
}
}
cout << ans / 2 << endl;
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

37
codeforces/903/io/a.in Normal file
View file

@ -0,0 +1,37 @@
12
1 5
a
aaaaa
5 5
eforc
force
2 5
ab
ababa
3 5
aba
ababa
4 3
babb
bbb
5 1
aaaaa
a
4 2
aabb
ba
2 8
bk
kbkbkbkb
12 2
fjdgmujlcont
tf
2 2
aa
aa
3 5
abb
babba
1 19
m
mmmmmmmmmmmmmmmmmmm

15
codeforces/903/io/a.out Normal file
View file

@ -0,0 +1,15 @@
3
1
2
-1
1
0
1
3
1
0
2
5
[code]: 0
[time]: 4.27103 ms

16
codeforces/903/io/b.in Normal file
View file

@ -0,0 +1,16 @@
15
1 3 2
5 5 5
6 36 12
7 8 7
6 3 3
4 4 12
12 6 8
1000000000 1000000000 1000000000
3 7 1
9 9 1
9 3 6
2 8 2
5 3 10
8 4 8
2 8 4

18
codeforces/903/io/b.out Normal file
View file

@ -0,0 +1,18 @@
YES
YES
NO
NO
YES
YES
NO
YES
NO
NO
YES
YES
NO
YES
NO
[code]: 0
[time]: 11.1175 ms

26
codeforces/903/io/c.in Normal file
View file

@ -0,0 +1,26 @@
5
4
abba
bcbb
bccb
abba
2
ab
ba
6
codefo
rcesco
deforc
escode
forces
codefo
4
baaa
abba
baba
baab
4
bbaa
abba
aaba
abba

8
codeforces/903/io/c.out Normal file
View file

@ -0,0 +1,8 @@
1
2
181
5
9
[code]: 0
[time]: 4.35901 ms

15
codeforces/903/io/d.in Normal file
View file

@ -0,0 +1,15 @@
7
5
100 2 50 10 1
3
1 1 1
4
8 2 4 2
4
30 50 27 20
2
75 40
2
4 4
3
2 3 1

10
codeforces/903/io/d.out Normal file
View file

@ -0,0 +1,10 @@
YES
YES
NO
YES
NO
YES
NO
[code]: 0
[time]: 11.4608 ms

15
codeforces/903/io/e.in Normal file
View file

@ -0,0 +1,15 @@
7
7
3 3 4 5 2 6 1
4
5 6 3 2
6
3 4 1 6 7 7
3
1 4 3
5
1 2 3 4 5
5
1 2 3 1 2
5
4 5 5 1 5

10
codeforces/903/io/e.out Normal file
View file

@ -0,0 +1,10 @@
0
4
1
1
2
1
0
[code]: 0
[time]: 4.28152 ms

49
codeforces/903/io/f.in Normal file
View file

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

9
codeforces/903/io/f.out Normal file
View file

@ -0,0 +1,9 @@
2
2
0
1
4
5
[code]: 0
[time]: 4.84347 ms

30
codeforces/903/makefile Normal file
View file

@ -0,0 +1,30 @@
.PHONY: run debug clean setup init
VERSION ?= 20
SRC = $(word 2,$(MAKECMDGOALS))
.SILENT:
run:
sh scripts/run.sh $(SRC)
debug:
sh scripts/debug.sh $(SRC)
clean:
rm -rf build/*
setup:
test -d build || mkdir -p build
test -d io || mkdir -p io
test -d scripts || mkdir -p scripts
test -f .clang-format || cp $(HOME)/.config/cp-template/.clang-format .
test -f compile_flags.txt || cp $(HOME)/.config/cp-template/compile_flags.txt . && echo -std=c++$(VERSION) >>compile_flags.txt
test -f .clangd || cp $(HOME)/.config/cp-template/.clangd . && echo -e "\t\t-std=c++$(VERSION)" >>.clangd
init:
make setup
%:
@:

View file

@ -0,0 +1,29 @@
#!/bin/sh
. ./scripts/utils.sh
SRC="$1"
BASE=$(basename "$SRC" .cc)
INPUT="${BASE}.in"
OUTPUT="${BASE}.out"
DBG_BIN="${BASE}.debug"
test -d build || mkdir -p build
test -d io || mkdir -p io
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
test -f "io/$INPUT" || touch "io/$INPUT"
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
INPUT="io/$INPUT"
OUTPUT="io/$OUTPUT"
DBG_BIN="build/$DBG_BIN"
compile_source "$SRC" "$DBG_BIN" "$OUTPUT" @debug_flags.txt
CODE=$?
test $CODE -gt 0 && exit $CODE
execute_binary "$DBG_BIN" "$INPUT" "$OUTPUT"
exit $?

View file

@ -0,0 +1,29 @@
#!/bin/sh
. ./scripts/utils.sh
SRC="$1"
BASE=$(basename "$SRC" .cc)
INPUT="${BASE}.in"
OUTPUT="${BASE}.out"
RUN_BIN="${BASE}.run"
test -d build || mkdir -p build
test -d io || mkdir -p io
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
test -f "io/$INPUT" || touch "io/$INPUT"
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
INPUT="io/$INPUT"
OUTPUT="io/$OUTPUT"
RUN_BIN="build/$RUN_BIN"
compile_source "$SRC" "$RUN_BIN" "$OUTPUT" ""
CODE=$?
test $CODE -gt 0 && exit $CODE
execute_binary "$RUN_BIN" "$INPUT" "$OUTPUT"
exit $?

View file

@ -0,0 +1,53 @@
#!/bin/sh
execute_binary() {
binary="$1"
input="$2"
output="$3"
start=$(date '+%s.%N')
timeout 2s ./"$binary" <"$input" >"$output" 2>&1
CODE=$?
end=$(date '+%s.%N')
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
[ $CODE -ne 124 ] && sed -i '$d' "$output"
test -n "$MSG" && printf '\n[code]: %s (%s)' "$CODE" "$MSG" >>"$output"
else
printf '\n[code]: %s' "$CODE" >>"$output"
fi
printf '\n[time]: %s ms' "$(awk "BEGIN {print ($end - $start) * 1000}")" >>$output
return $CODE
}
compile_source() {
src="$1"
bin="$2"
output="$3"
flags="$4"
test -f "$bin" && rm "$bin" || true
g++ @compile_flags.txt $flags "$src" -o "$bin" 2>"$output"
CODE=$?
if [ $CODE -gt 0 ]; then
printf '\n[code]: %s' "$CODE" >>"$output"
return $CODE
else
echo '' >"$output"
return 0
fi
}

View file

@ -0,0 +1,9 @@
BasedOnStyle: Google
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: false
AllowShortLoopsOnASingleLine: false

40
codeforces/981/.clangd Normal file
View file

@ -0,0 +1,40 @@
CompileFlags:
Add:
-O2
-Wall
-Wextra
-Wpedantic
-Wshadow
-Wformat=2
-Wfloat-equal
-Wlogical-op
-Wshift-overflow=2
-Wnon-virtual-dtor
-Wold-style-cast
-Wcast-qual
-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
-Wno-unknown-pragmas
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23

102
codeforces/981/a.cc Normal file
View file

@ -0,0 +1,102 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
i32 n;
cin >> n;
bool s = true;
i32 pos = 0;
i32 i = 1;
for (;;) {
i32 moves = 2 * i - 1;
if (s) {
moves *= -1;
}
pos += moves;
if (abs(pos) > n)
break;
++i;
s = !s;
}
if (s) {
cout << "Sakurako";
} else {
cout << "Kosuke";
}
cout << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

99
codeforces/981/b.cc Normal file
View file

@ -0,0 +1,99 @@
#include <bits/stdc++.h> // {{{
#include <bit>
// 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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
u32 n;
cin >> n;
vector<vector<i32>> grid(n, vector<i32>(n));
for (auto& r : grid)
for (auto& r : r)
cin >> r;
unordered_map<i32, i32> m;
for (u32 i = 0; i < n; ++i) {
for (u32 j = 0; j < n; ++j) {
m[i - j] = min(grid[i][j], m[i - j]);
}
}
u32 ans = 0;
for (auto& [_, x] : m)
ans -= x;
cout << ans << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

93
codeforces/981/c.cc Normal file
View file

@ -0,0 +1,93 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
u32 n;
cin >> n;
vector<i32> a(n);
for (auto& e : a)
cin >> e;
for (i32 i = n / 2 - 2; i >= 0; --i) {
if (a[i] == a[i + 1] || a[n - i - 1] == a[n - i - 2]) {
swap(a[i], a[n - i - 1]);
}
}
u32 ans = 0;
for (u32 i = 0; i + 1 < n; ++i)
ans += a[i] == a[i + 1];
cout << ans << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

View file

@ -0,0 +1,30 @@
-O2
-Wall
-Wextra
-Wpedantic
-Wshadow
-Wformat=2
-Wfloat-equal
-Wlogical-op
-Wshift-overflow=2
-Wnon-virtual-dtor
-Wold-style-cast
-Wcast-qual
-Wuseless-cast
-Wno-sign-promotion
-Wcast-align
-Wunused
-Woverloaded-virtual
-Wconversion
-Wmisleading-indentation
-Wduplicated-cond
-Wduplicated-branches
-Wlogical-op
-Wnull-dereference
-Wformat=2
-Wformat-overflow
-Wformat-truncation
-Wdouble-promotion
-Wundef
-DLOCAL
-std=c++23

98
codeforces/981/d.cc Normal file
View file

@ -0,0 +1,98 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
u32 n;
cin >> n;
vector<i64> a(n);
for (auto& e : a)
cin >> e;
set<i64> prefixes;
prefixes.insert(0);
i64 prefix = 0;
u32 ans = 0;
for (u32 i = 0; i < n; ++i) {
prefix += a[i];
if (prefixes.contains(prefix)) {
++ans;
prefixes.clear();
prefix = 0;
}
prefixes.insert(prefix);
}
cout << ans << endl;
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

View file

@ -0,0 +1,14 @@
-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
-D_GLIBCXX_DEBUG
-D_GLIBCXX_DEBUG_PEDANTIC
-DLOCAL
-std=c++23

105
codeforces/981/e.cc Normal file
View file

@ -0,0 +1,105 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
bitset<1000001> seen;
void solve() {
u32 n;
cin >> n;
vector<u32> a(n + 1);
for (u32 i = 1; i <= n; ++i) {
cin >> a[i];
}
seen.reset();
u32 ans = 0;
for (u32 i = 1; i <= n; ++i) {
if (seen[i])
continue;
u32 pos = i;
u32 streak = 0;
while (!seen[pos]) {
++streak;
seen[pos] = true;
pos = a[pos];
}
ans += (streak - 1) / 2;
}
cout << ans << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

5
codeforces/981/io/a.in Normal file
View file

@ -0,0 +1,5 @@
4
1
6
3
98

7
codeforces/981/io/a.out Normal file
View file

@ -0,0 +1,7 @@
Kosuke
Sakurako
Kosuke
Sakurako
[code]: 0
[time]: 4.4868 ms

17
codeforces/981/io/b.in Normal file
View file

@ -0,0 +1,17 @@
4
1
1
2
-1 2
3 0
3
1 2 3
-2 1 -1
0 0 -1
5
1 1 -1 -1 3
-3 1 4 4 -4
-1 -1 3 0 -5
4 5 3 -3 -1
3 1 -3 -1 5

7
codeforces/981/io/b.out Normal file
View file

@ -0,0 +1,7 @@
0
1
4
19
[code]: 0
[time]: 4.14872 ms

19
codeforces/981/io/c.in Normal file
View file

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

12
codeforces/981/io/c.out Normal file
View file

@ -0,0 +1,12 @@
1
2
1
0
0
1
1
0
2
[code]: 0
[time]: 3.97801 ms

7
codeforces/981/io/d.in Normal file
View file

@ -0,0 +1,7 @@
3
5
2 1 -3 2 1
7
12 -4 4 43 -3 -5 8
6
0 -4 0 3 0 1

6
codeforces/981/io/d.out Normal file
View file

@ -0,0 +1,6 @@
1
2
3
[code]: 0
[time]: 3.10135 ms

13
codeforces/981/io/e.in Normal file
View file

@ -0,0 +1,13 @@
6
5
1 2 3 4 5
5
5 4 3 2 1
5
2 3 4 5 1
4
2 3 4 1
3
1 3 2
7
2 3 1 5 6 7 4

9
codeforces/981/io/e.out Normal file
View file

@ -0,0 +1,9 @@
0
0
2
1
0
2
[code]: 0
[time]: 4.17638 ms

37
codeforces/981/io/g.in Normal file
View file

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

6
codeforces/981/io/g.out Normal file
View file

@ -0,0 +1,6 @@
2 3 2
0 6 4 4 6 5 6
2 3 6
[code]: 0
[time]: 4.73642 ms

30
codeforces/981/makefile Normal file
View file

@ -0,0 +1,30 @@
.PHONY: run debug clean setup init
VERSION ?= 20
SRC = $(word 2,$(MAKECMDGOALS))
.SILENT:
run:
sh scripts/run.sh $(SRC)
debug:
sh scripts/debug.sh $(SRC)
clean:
rm -rf build/*
setup:
test -d build || mkdir -p build
test -d io || mkdir -p io
test -d scripts || mkdir -p scripts
test -f .clang-format || cp $(HOME)/.config/cp-template/.clang-format .
test -f compile_flags.txt || cp $(HOME)/.config/cp-template/compile_flags.txt . && echo -std=c++$(VERSION) >>compile_flags.txt
test -f .clangd || cp $(HOME)/.config/cp-template/.clangd . && echo -e "\t\t-std=c++$(VERSION)" >>.clangd
init:
make setup
%:
@:

View file

@ -0,0 +1,29 @@
#!/bin/sh
. ./scripts/utils.sh
SRC="$1"
BASE=$(basename "$SRC" .cc)
INPUT="${BASE}.in"
OUTPUT="${BASE}.out"
DBG_BIN="${BASE}.debug"
test -d build || mkdir -p build
test -d io || mkdir -p io
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
test -f "io/$INPUT" || touch "io/$INPUT"
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
INPUT="io/$INPUT"
OUTPUT="io/$OUTPUT"
DBG_BIN="build/$DBG_BIN"
compile_source "$SRC" "$DBG_BIN" "$OUTPUT" @debug_flags.txt
CODE=$?
test $CODE -gt 0 && exit $CODE
execute_binary "$DBG_BIN" "$INPUT" "$OUTPUT"
exit $?

View file

@ -0,0 +1,29 @@
#!/bin/sh
. ./scripts/utils.sh
SRC="$1"
BASE=$(basename "$SRC" .cc)
INPUT="${BASE}.in"
OUTPUT="${BASE}.out"
RUN_BIN="${BASE}.run"
test -d build || mkdir -p build
test -d io || mkdir -p io
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
test -f "io/$INPUT" || touch "io/$INPUT"
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
INPUT="io/$INPUT"
OUTPUT="io/$OUTPUT"
RUN_BIN="build/$RUN_BIN"
compile_source "$SRC" "$RUN_BIN" "$OUTPUT" ""
CODE=$?
test $CODE -gt 0 && exit $CODE
execute_binary "$RUN_BIN" "$INPUT" "$OUTPUT"
exit $?

View file

@ -0,0 +1,53 @@
#!/bin/sh
execute_binary() {
binary="$1"
input="$2"
output="$3"
start=$(date '+%s.%N')
timeout 2s ./"$binary" <"$input" >"$output" 2>&1
CODE=$?
end=$(date '+%s.%N')
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
[ $CODE -ne 124 ] && sed -i '$d' "$output"
test -n "$MSG" && printf '\n[code]: %s (%s)' "$CODE" "$MSG" >>"$output"
else
printf '\n[code]: %s' "$CODE" >>"$output"
fi
printf '\n[time]: %s ms' "$(awk "BEGIN {print ($end - $start) * 1000}")" >>$output
return $CODE
}
compile_source() {
src="$1"
bin="$2"
output="$3"
flags="$4"
test -f "$bin" && rm "$bin" || true
g++ @compile_flags.txt $flags "$src" -o "$bin" 2>"$output"
CODE=$?
if [ $CODE -gt 0 ]; then
printf '\n[code]: %s' "$CODE" >>"$output"
return $CODE
else
echo '' >"$output"
return 0
fi
}

36
codeforces/993/.clangd Normal file
View file

@ -0,0 +1,36 @@
CompileFlags:
Add:
-O2
-Wall
-Wextra
-Wpedantic
-Wshadow
-Wformat=2
-Wfloat-equal
-Wlogical-op
-Wshift-overflow=2
-Wnon-virtual-dtor
-Wold-style-cast
-Wcast-qual
-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
-Wno-unknown-pragmas
-std=c++23
-std=c++23
-std=c++23

View file

@ -1,5 +1,30 @@
-std=c++20
-O2
-Wall
-Wextra
-Wpedantic
-Wshadow
-Wformat=2
-Wfloat-equal
-Wlogical-op
-Wshift-overflow=2
-Wnon-virtual-dtor
-Wold-style-cast
-Wcast-qual
-Wuseless-cast
-Wno-sign-promotion
-Wcast-align
-Wunused
-Woverloaded-virtual
-Wconversion
-Wmisleading-indentation
-Wduplicated-cond
-Wduplicated-branches
-Wlogical-op
-Wnull-dereference
-Wformat=2
-Wformat-overflow
-Wformat-truncation
-Wdouble-promotion
-Wundef
-DLOCAL
-std=c++23

View file

@ -0,0 +1,14 @@
-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
-D_GLIBCXX_DEBUG
-D_GLIBCXX_DEBUG_PEDANTIC
-DLOCAL
-std=c++20

View file

@ -1,137 +0,0 @@
#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 dbg(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 dbg(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void dbgln(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 dbgln(std::string const &str, Args &&...args) {
dbg(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void dbgln(T const &t) {
dbg("{}\n", t);
}
void println() {
std::cout << '\n';
}
template <typename T>
constexpr auto MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr auto MAX = 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))
#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a))
std::random_device rd;
std::mt19937 gen(rd());
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
void solve() {
int n, q;
cin >> n;
vec<vec<int>> grid(n, vec<int>(n));
FOR(i, 0, n) {
FOR(j, 0, n) {
cin >> grid[i][j];
}
}
vec<vec<int>> dp(n + 1, vec<int>(n + 1, 1));
while (q--) {
int x1, x2, y1, y2;
cin >> x1 >> x2 >> y1 >> y2;
}
/*
00 01 02 03 04 05 ...
10 11 12 13 14 15 ...
1 * 00 * 2 * 01 + 3 * 02
4 * 01 + 5 *
1 * M[i][j] + 2 * M[i][j + 1] + 3 * M[i][j + 2]
+ 4 * M[i + 1][j] + 5 * M[i + 1][j + 2]
= sum r0 * n + c0 -> r1 * n + c1
1 2
3 4
5 6
1 2 0 0
1 2 + 2 2
1 2 + 4 4
3+4^2+8^3+9^4+13^5+14^6
8+9^2+13^3+14^4 - ( 8^2+9^2+13^2 )
*/
// FIX: cout
dbgln("hi");
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

127
codeforces/993/h.cpp Normal file
View file

@ -0,0 +1,127 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
template <typename T>
using vec = std::vector<T>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
u32 n, q;
cin >> n >> q;
vec<vec<u64>> grid(n, vec<u64>(n));
for (auto& r : grid)
for (auto& c : r)
cin >> c;
vec<vec<u64>> one(n + 1, vec<u64>(n + 1, 0));
auto colwise = one;
auto rowwise = one;
for (u32 i = 1; i <= n; ++i) {
for (u32 j = 1; j <= n; ++j) {
one[i][j] = grid[i - 1][j - 1] + one[i - 1][j] + one[i][j - 1] -
one[i - 1][j - 1];
}
}
for (u32 i = 1; i <= n; ++i) {
for (u32 j = 1; j <= n; ++j) {
colwise[i][j] = i * grid[i - 1][j - 1] + colwise[i][j - 1] +
colwise[i - 1][j] - colwise[i - 1][j - 1];
}
}
for (u32 i = 1; i <= n; ++i) {
for (u32 j = 1; j <= n; ++j) {
rowwise[i][j] = j * grid[i - 1][j - 1] + rowwise[i][j - 1] +
rowwise[i - 1][j] - rowwise[i - 1][j - 1];
}
}
u64 x1, y1, x2, y2;
for (u32 i = 0; i < q; ++i) {
cin >> x1 >> y1 >> x2 >> y2;
auto s =
one[x2][y2] - one[x2][y1 - 1] - one[x1 - 1][y2] + one[x1 - 1][y1 - 1];
auto sr = colwise[x2][y2] - colwise[x2][y1 - 1] - colwise[x1 - 1][y2] +
colwise[x1 - 1][y1 - 1];
auto sc = rowwise[x2][y2] - rowwise[x2][y1 - 1] - rowwise[x1 - 1][y2] +
rowwise[x1 - 1][y1 - 1];
u64 w = y2 - y1 + 1;
u64 ans = w * (sr - (u64)x1 * s) + (sc - (u64)y1 * s) + s;
cout << ans << " \n"[i == q - 1];
}
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

16
codeforces/993/io/h.in Normal file
View file

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

5
codeforces/993/io/h.out Normal file
View file

@ -0,0 +1,5 @@
500 42 168
14 42 5
[code]: 0
[time]: 4.26412 ms

29
codeforces/993/makefile Normal file
View file

@ -0,0 +1,29 @@
.PHONY: run debug clean setup init
VERSION ?= 20
SRC = $(word 2,$(MAKECMDGOALS))
.SILENT:
run:
sh scripts/run.sh $(SRC)
debug:
sh scripts/debug.sh $(SRC)
clean:
rm -rf build/*
setup:
test -d build || mkdir -p build
test -d io || mkdir -p io
test -d scripts || mkdir -p scripts
test -f compile_flags.txt || cp $(HOME)/.config/cp-template/compile_flags.txt . && echo -std=c++$(VERSION) >>compile_flags.txt
test -f .clangd || cp $(HOME)/.config/cp-template/.clangd . && echo -e "\t\t-std=c++$(VERSION)" >>.clangd
init:
make setup
%:
@:

View file

@ -0,0 +1,29 @@
#!/bin/sh
. ./scripts/utils.sh
SRC="$1"
BASE=$(basename "$SRC" .cc)
INPUT="${BASE}.in"
OUTPUT="${BASE}.out"
DBG_BIN="${BASE}.debug"
test -d build || mkdir -p build
test -d io || mkdir -p io
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
test -f "io/$INPUT" || touch "io/$INPUT"
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
INPUT="io/$INPUT"
OUTPUT="io/$OUTPUT"
DBG_BIN="build/$DBG_BIN"
compile_source "$SRC" "$DBG_BIN" "$OUTPUT" @debug_flags.txt
CODE=$?
test $CODE -gt 0 && exit $CODE
execute_binary "$DBG_BIN" "$INPUT" "$OUTPUT"
exit $?

View file

@ -0,0 +1,29 @@
#!/bin/sh
. ./scripts/utils.sh
SRC="$1"
BASE=$(basename "$SRC" .cc)
INPUT="${BASE}.in"
OUTPUT="${BASE}.out"
RUN_BIN="${BASE}.run"
test -d build || mkdir -p build
test -d io || mkdir -p io
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
test -f "io/$INPUT" || touch "io/$INPUT"
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
INPUT="io/$INPUT"
OUTPUT="io/$OUTPUT"
RUN_BIN="build/$RUN_BIN"
compile_source "$SRC" "$RUN_BIN" "$OUTPUT" ""
CODE=$?
test $CODE -gt 0 && exit $CODE
execute_binary "$RUN_BIN" "$INPUT" "$OUTPUT"
exit $?

View file

@ -0,0 +1,53 @@
#!/bin/sh
execute_binary() {
binary="$1"
input="$2"
output="$3"
start=$(date '+%s.%N')
timeout 2s ./"$binary" <"$input" >"$output" 2>&1
CODE=$?
end=$(date '+%s.%N')
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
[ $CODE -ne 124 ] && sed -i '$d' "$output"
test -n "$MSG" && printf '\n[code]: %s (%s)' "$CODE" "$MSG" >>"$output"
else
printf '\n[code]: %s' "$CODE" >>"$output"
fi
printf '\n[time]: %s ms' "$(awk "BEGIN {print ($end - $start) * 1000}")" >>$output
return $CODE
}
compile_source() {
src="$1"
bin="$2"
output="$3"
flags="$4"
test -f "$bin" && rm "$bin" || true
g++ @compile_flags.txt $flags "$src" -o "$bin" 2>"$output"
CODE=$?
if [ $CODE -gt 0 ]; then
printf '\n[code]: %s' "$CODE" >>"$output"
return $CODE
else
echo '' >"$output"
return 0
fi
}

View file

@ -35,3 +35,4 @@ CompileFlags:
-std=c++17
-std=c++17
-std=c++17
-std=c++17

View file

@ -0,0 +1,79 @@
#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;
#if __cplusplus >= 202002L
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#endif
static void NO() {
std::cout << "NO\n";
}
static void YES() {
std::cout << "YES\n";
}
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second
#ifdef LOCAL
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
// }}}
void solve() {
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
#define PROBLEM_NAME "angry"
#ifdef LOCAL
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
#else
freopen(PROBLEM_NAME ".in", "r", stdin);
freopen(PROBLEM_NAME ".out", "w", stdout);
#endif
solve();
return 0;
}
// }}}

View file

View file

@ -0,0 +1,29 @@
#!/bin/sh
. ./scripts/utils.sh
SRC="$1"
BASE=$(basename "$SRC" .cc)
INPUT="${BASE}.in"
OUTPUT="${BASE}.out"
DBG_BIN="${BASE}.debug"
test -d build || mkdir -p build
test -d io || mkdir -p io
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
test -f "io/$INPUT" || touch "io/$INPUT"
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
INPUT="io/$INPUT"
OUTPUT="io/$OUTPUT"
DBG_BIN="build/$DBG_BIN"
compile_source "$SRC" "$DBG_BIN" "$OUTPUT" @debug_flags.txt
CODE=$?
test $CODE -gt 0 && exit $CODE
execute_binary "$DBG_BIN" "$INPUT" "$OUTPUT"
exit $?

Some files were not shown because too many files have changed in this diff Show more