feat: 806
This commit is contained in:
parent
579760f0f8
commit
98ea573f5a
73 changed files with 2821 additions and 0 deletions
9
codeforces/806/.clang-format
Normal file
9
codeforces/806/.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
|
||||
41
codeforces/806/.clangd
Normal file
41
codeforces/806/.clangd
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
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
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
91
codeforces/806/a.cc
Normal file
91
codeforces/806/a.cc
Normal 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() {
|
||||
string s;
|
||||
cin >> s;
|
||||
|
||||
if (tolower(s[0]) == 'y' && tolower(s[1]) == 'e' && tolower(s[2]) == 's') {
|
||||
YES();
|
||||
} else {
|
||||
NO();
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
94
codeforces/806/b.cc
Normal file
94
codeforces/806/b.cc
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
#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;
|
||||
string s;
|
||||
cin >> s;
|
||||
|
||||
set<char> S;
|
||||
for (auto e : s) {
|
||||
S.insert(e);
|
||||
}
|
||||
|
||||
println("{}", n + S.size());
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
105
codeforces/806/c.cc
Normal file
105
codeforces/806/c.cc
Normal 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
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
u32 n;
|
||||
cin >> n;
|
||||
vec<i32> wheels(n);
|
||||
for (auto& e : wheels)
|
||||
cin >> e;
|
||||
|
||||
u32 moves;
|
||||
string pattern;
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
cin >> moves >> pattern;
|
||||
|
||||
i32 delta = 0;
|
||||
|
||||
for (auto letter : pattern) {
|
||||
if (letter == 'U')
|
||||
++delta;
|
||||
else
|
||||
--delta;
|
||||
}
|
||||
|
||||
cout << (wheels[i] - delta + 10) % 10 << " \n"[i == n - 1];
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
31
codeforces/806/compile_flags.txt
Normal file
31
codeforces/806/compile_flags.txt
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
-pedantic-errors
|
||||
-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
|
||||
109
codeforces/806/d.cc
Normal file
109
codeforces/806/d.cc
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
#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;
|
||||
|
||||
vec<string> strings(n);
|
||||
for (auto& s : strings)
|
||||
cin >> s;
|
||||
|
||||
set<string> S;
|
||||
for (auto& s : strings) {
|
||||
S.insert(s);
|
||||
}
|
||||
|
||||
for (auto& s : strings) {
|
||||
bool ok = false;
|
||||
|
||||
for (u32 i = 0; s.size() > 1 && i < s.size() - 1; ++i) {
|
||||
if (S.contains(s.substr(0, i + 1)) && S.contains(s.substr(i + 1))) {
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
print("{}", ok ? '1' : '0');
|
||||
}
|
||||
|
||||
println();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
14
codeforces/806/debug_flags.txt
Normal file
14
codeforces/806/debug_flags.txt
Normal 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
|
||||
115
codeforces/806/e.cc
Normal file
115
codeforces/806/e.cc
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
#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;
|
||||
vec<string> grid(n);
|
||||
for (auto& row : grid)
|
||||
cin >> row;
|
||||
|
||||
u32 changes = 0;
|
||||
|
||||
for (u32 i = 0; i < n / 2; ++i) {
|
||||
for (u32 j = 0; j < n / 2; ++j) {
|
||||
u32 ones = 0;
|
||||
ones += grid[i][j] == '1';
|
||||
ones += grid[j][n - 1 - i] == '1';
|
||||
ones += grid[n - 1 - i][n - 1 - j] == '1';
|
||||
ones += grid[n - 1 - j][i] == '1';
|
||||
changes += min(ones, 4 - ones);
|
||||
}
|
||||
}
|
||||
|
||||
if (n % 2 == 1) {
|
||||
u32 mid = n / 2;
|
||||
for (u32 i = 0; i < n / 2; ++i) {
|
||||
u32 ones = 0;
|
||||
ones += grid[i][mid] == '1';
|
||||
ones += grid[mid][n - 1 - i] == '1';
|
||||
ones += grid[n - 1 - i][mid] == '1';
|
||||
ones += grid[mid][i] == '1';
|
||||
changes += min(ones, 4 - ones);
|
||||
}
|
||||
}
|
||||
|
||||
println("{}", changes);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
105
codeforces/806/f.cc
Normal file
105
codeforces/806/f.cc
Normal 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
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
u32 n;
|
||||
cin >> n;
|
||||
|
||||
vec<u64> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
vec<u64> pref(n + 1, 0);
|
||||
for (u32 i = 1; i <= n; ++i) {
|
||||
pref[i] = pref[i - 1] + (a[i - 1] < i ? 1 : 0);
|
||||
}
|
||||
|
||||
u64 ans = 0;
|
||||
for (u32 j = 1; j <= n; ++j) {
|
||||
if (a[j - 1] < j) {
|
||||
u64 aj = a[j - 1];
|
||||
u32 limit = aj == 0 ? 0 : (aj - 1 > n ? n : aj - 1);
|
||||
ans += pref[limit];
|
||||
}
|
||||
}
|
||||
|
||||
println("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
112
codeforces/806/g.cc
Normal file
112
codeforces/806/g.cc
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
#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;
|
||||
i64 k;
|
||||
cin >> n >> k;
|
||||
vec<u64> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
const u32 B = 31;
|
||||
vec<i64> dp(B + 1, MIN<i64>), ndp(B + 1, MIN<i64>);
|
||||
dp[0] = 0;
|
||||
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
fill(all(ndp), MIN<i64>);
|
||||
u32 upto = min<u32>(B, i);
|
||||
for (u32 b = 0; b <= upto; ++b) {
|
||||
if (dp[b] == MIN<i64>)
|
||||
continue;
|
||||
|
||||
i64 gain_good = sc<i64>(a[i] >> b) - k;
|
||||
ndp[b] = max(ndp[b], dp[b] + gain_good);
|
||||
|
||||
u32 b2 = min<u32>(B, b + 1);
|
||||
i64 gain_bad = sc<i64>(a[i] >> b2);
|
||||
ndp[b2] = max(ndp[b2], dp[b] + gain_bad);
|
||||
}
|
||||
dp.swap(ndp);
|
||||
}
|
||||
|
||||
println("{}", *max_element(all(dp)));
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
11
codeforces/806/io/a.in
Normal file
11
codeforces/806/io/a.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
10
|
||||
YES
|
||||
yES
|
||||
yes
|
||||
Yes
|
||||
YeS
|
||||
Noo
|
||||
orZ
|
||||
yEz
|
||||
Yas
|
||||
XES
|
||||
14
codeforces/806/io/a.out
Normal file
14
codeforces/806/io/a.out
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
YES
|
||||
YES
|
||||
YES
|
||||
YES
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
|
||||
[code]: 0
|
||||
[time]: 5.40304 ms
|
||||
[debug]: false
|
||||
13
codeforces/806/io/b.in
Normal file
13
codeforces/806/io/b.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
3
|
||||
ABA
|
||||
1
|
||||
A
|
||||
3
|
||||
ORZ
|
||||
5
|
||||
BAAAA
|
||||
4
|
||||
BKPT
|
||||
10
|
||||
CODEFORCES
|
||||
10
codeforces/806/io/b.out
Normal file
10
codeforces/806/io/b.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
5
|
||||
2
|
||||
6
|
||||
7
|
||||
8
|
||||
17
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.34175 ms
|
||||
[debug]: false
|
||||
17
codeforces/806/io/c.in
Normal file
17
codeforces/806/io/c.in
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
3
|
||||
3
|
||||
9 3 1
|
||||
3 DDD
|
||||
4 UDUU
|
||||
2 DU
|
||||
2
|
||||
0 9
|
||||
9 DDDDDDDDD
|
||||
9 UUUUUUUUU
|
||||
5
|
||||
0 5 9 8 3
|
||||
10 UUUUUUUUUU
|
||||
3 UUD
|
||||
8 UUDUUDDD
|
||||
10 UUDUUDUDDU
|
||||
4 UUUU
|
||||
7
codeforces/806/io/c.out
Normal file
7
codeforces/806/io/c.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
2 1 1
|
||||
9 0
|
||||
0 4 9 6 9
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.40731 ms
|
||||
[debug]: false
|
||||
20
codeforces/806/io/d.in
Normal file
20
codeforces/806/io/d.in
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
3
|
||||
5
|
||||
abab
|
||||
ab
|
||||
abc
|
||||
abacb
|
||||
c
|
||||
3
|
||||
x
|
||||
xx
|
||||
xxx
|
||||
8
|
||||
codeforc
|
||||
es
|
||||
codes
|
||||
cod
|
||||
forc
|
||||
forces
|
||||
e
|
||||
code
|
||||
7
codeforces/806/io/d.out
Normal file
7
codeforces/806/io/d.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
10100
|
||||
011
|
||||
10100101
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.46286 ms
|
||||
[debug]: false
|
||||
26
codeforces/806/io/e.in
Normal file
26
codeforces/806/io/e.in
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
5
|
||||
3
|
||||
010
|
||||
110
|
||||
010
|
||||
1
|
||||
0
|
||||
5
|
||||
11100
|
||||
11011
|
||||
01011
|
||||
10011
|
||||
11000
|
||||
5
|
||||
01000
|
||||
10101
|
||||
01010
|
||||
00010
|
||||
01001
|
||||
5
|
||||
11001
|
||||
00000
|
||||
11111
|
||||
10110
|
||||
01111
|
||||
|
||||
9
codeforces/806/io/e.out
Normal file
9
codeforces/806/io/e.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
1
|
||||
0
|
||||
9
|
||||
7
|
||||
6
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.52557 ms
|
||||
[debug]: false
|
||||
11
codeforces/806/io/f.in
Normal file
11
codeforces/806/io/f.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
5
|
||||
8
|
||||
1 1 2 3 8 2 1 4
|
||||
2
|
||||
1 2
|
||||
10
|
||||
0 2 1 6 3 4 1 2 8 3
|
||||
2
|
||||
1 1000000000
|
||||
3
|
||||
0 1000000000 2
|
||||
9
codeforces/806/io/f.out
Normal file
9
codeforces/806/io/f.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
3
|
||||
0
|
||||
10
|
||||
0
|
||||
1
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.49338 ms
|
||||
[debug]: false
|
||||
11
codeforces/806/io/g.in
Normal file
11
codeforces/806/io/g.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
5
|
||||
4 5
|
||||
10 10 3 1
|
||||
1 2
|
||||
1
|
||||
3 12
|
||||
10 10 29
|
||||
12 51
|
||||
5 74 89 45 18 69 67 67 11 96 23 59
|
||||
2 57
|
||||
85 60
|
||||
9
codeforces/806/io/g.out
Normal file
9
codeforces/806/io/g.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
11
|
||||
0
|
||||
13
|
||||
60
|
||||
58
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.5022 ms
|
||||
[debug]: false
|
||||
30
codeforces/806/makefile
Normal file
30
codeforces/806/makefile
Normal 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
|
||||
|
||||
%:
|
||||
@:
|
||||
29
codeforces/806/scripts/debug.sh
Normal file
29
codeforces/806/scripts/debug.sh
Normal 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" true
|
||||
exit $?
|
||||
29
codeforces/806/scripts/run.sh
Normal file
29
codeforces/806/scripts/run.sh
Normal 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 $?
|
||||
61
codeforces/806/scripts/utils.sh
Normal file
61
codeforces/806/scripts/utils.sh
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#!/bin/sh
|
||||
|
||||
execute_binary() {
|
||||
binary="$1"
|
||||
input="$2"
|
||||
output="$3"
|
||||
is_debug="$4"
|
||||
|
||||
start=$(date '+%s.%N')
|
||||
if [ -n "$is_debug" ]; then
|
||||
asan="$(ldconfig -p | grep libasan.so | head -n1 | awk '{print $4}')"
|
||||
LD_PRELOAD="$asan" timeout 2s ./"$binary" <"$input" >"$output" 2>&1
|
||||
else
|
||||
timeout 2s ./"$binary" <"$input" >"$output" 2>&1
|
||||
fi
|
||||
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
|
||||
test -n "$is_debug" && is_debug_string=true || is_debug_string=false
|
||||
printf '\n[debug]: %s' "$is_debug_string" >>$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
|
||||
}
|
||||
9
codeforces/918/.clang-format
Normal file
9
codeforces/918/.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
|
||||
42
codeforces/918/.clangd
Normal file
42
codeforces/918/.clangd
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
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
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
100
codeforces/918/a.cc
Normal file
100
codeforces/918/a.cc
Normal 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() {
|
||||
u32 a, b, c;
|
||||
cin >> a >> b >> c;
|
||||
|
||||
u32 ans;
|
||||
// NOTE: ngl didn't even check if this was right lol
|
||||
if (a == b) {
|
||||
ans = c;
|
||||
}
|
||||
if (a == c) {
|
||||
ans = b;
|
||||
}
|
||||
|
||||
if (b == c) {
|
||||
ans = a;
|
||||
}
|
||||
|
||||
println("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
98
codeforces/918/b.cc
Normal file
98
codeforces/918/b.cc
Normal 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() {
|
||||
vec<string> grid(3);
|
||||
for (auto& e : grid)
|
||||
cin >> e;
|
||||
|
||||
for (auto& row : grid) {
|
||||
if (row.find('?') == string::npos)
|
||||
continue;
|
||||
|
||||
for (auto c : "ABC") {
|
||||
if (row.find(c) == string::npos) {
|
||||
println("{}", c);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
102
codeforces/918/c.cc
Normal file
102
codeforces/918/c.cc
Normal 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() {
|
||||
u32 n;
|
||||
cin >> n;
|
||||
vec<u32> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
u64 total = accumulate(all(a), 0LL);
|
||||
|
||||
// NOTE: used auto and float, WA
|
||||
u64 root = sqrtl(total);
|
||||
while (root * root < total) {
|
||||
++root;
|
||||
}
|
||||
|
||||
if (root * root == total) {
|
||||
YES();
|
||||
} else {
|
||||
NO();
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
31
codeforces/918/compile_flags.txt
Normal file
31
codeforces/918/compile_flags.txt
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
-pedantic-errors
|
||||
-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
|
||||
108
codeforces/918/d.cc
Normal file
108
codeforces/918/d.cc
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
#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;
|
||||
string s;
|
||||
cin >> s;
|
||||
|
||||
// idea: can form valid word, greedy
|
||||
// CV, CVC
|
||||
// working backwards is easier
|
||||
|
||||
string ans;
|
||||
// NOTE: control flow took a second
|
||||
for (i32 i = n - 1; i >= 0; --i) {
|
||||
ans.push_back(s[i]);
|
||||
ans.push_back(s[i - 1]);
|
||||
if (!(s[i] == 'e' || s[i] == 'a')) {
|
||||
ans.push_back(s[i - 2]);
|
||||
--i;
|
||||
}
|
||||
--i;
|
||||
if (i > 0)
|
||||
ans.push_back('.');
|
||||
}
|
||||
|
||||
reverse(all(ans));
|
||||
println("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
14
codeforces/918/debug_flags.txt
Normal file
14
codeforces/918/debug_flags.txt
Normal 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
|
||||
129
codeforces/918/e.cc
Normal file
129
codeforces/918/e.cc
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
#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() {
|
||||
/*
|
||||
want sum(o[l:r])==sum(e[l:r])
|
||||
|
||||
for every r:
|
||||
opref[r] - opref[l] == epref[r] - epref[l]
|
||||
opref[r] - epref[r] == opref[l] - epref[l]
|
||||
^ known O(1) ^ insert in tree
|
||||
*/
|
||||
u32 n;
|
||||
cin >> n;
|
||||
|
||||
vec<i64> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
if (n == 1) {
|
||||
NO();
|
||||
return;
|
||||
}
|
||||
|
||||
// NOTE: missed initial array
|
||||
// NOTE: had a major problem with your ideas
|
||||
// "oh just change the sign, my logic is not right"
|
||||
// TRUST YOUR LOGIC, BUT NOT THE IMPL - IMPL != IDEA
|
||||
set<i64> pref{0};
|
||||
i64 acc = 0;
|
||||
|
||||
for (u32 r = 1; r <= n; ++r) {
|
||||
if (r & 1) {
|
||||
acc += a[r - 1];
|
||||
} else {
|
||||
acc -= a[r - 1];
|
||||
}
|
||||
|
||||
// dbln("r={}, o={} e={}", r, o, e);
|
||||
|
||||
// NOTE: had this backwards, and honestly idk even why
|
||||
if (pref.find(acc) != pref.end()) {
|
||||
YES();
|
||||
return;
|
||||
}
|
||||
|
||||
pref.insert(acc);
|
||||
}
|
||||
|
||||
NO();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
114
codeforces/918/f.cc
Normal file
114
codeforces/918/f.cc
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
#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
|
||||
// }}}
|
||||
|
||||
i64 inv_merge(vector<i64>& a, vector<i64>& tmp) {
|
||||
if (r - l <= 1)
|
||||
return 0;
|
||||
int m = (l + r) >> 1;
|
||||
i64 ans = inv_merge(a, tmp, l, m) + inv_merge(a, tmp, m, r);
|
||||
int i = l, j = m, k = l;
|
||||
while (i < m || j < r) {
|
||||
if (j == r || (i < m && a[i] <= a[j]))
|
||||
tmp[k++] = a[i++];
|
||||
else {
|
||||
tmp[k++] = a[j++];
|
||||
ans += (m - i);
|
||||
}
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
void solve() {
|
||||
// NOTE: erroneosouyl thought was interval overlaps (even that took too long
|
||||
// to code) should've stayed at it and continued, but was tired/acted tired
|
||||
// consider the problem statemnt & examples more slowly
|
||||
// simplifcation: count the inversions
|
||||
i32 n;
|
||||
cin >> n;
|
||||
vector<pair<i64, i64>> p(n);
|
||||
for (i32 i = 0; i < n; ++i)
|
||||
cin >> p[i].first >> p[i].second;
|
||||
sort(all(p));
|
||||
vector<i64> b(n), tmp(n);
|
||||
for (i32 i = 0; i < n; ++i)
|
||||
b[i] = p[i].second;
|
||||
println("{}", inv_merge(b, tmp, 0, n));
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
128
codeforces/918/g.cc
Normal file
128
codeforces/918/g.cc
Normal 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, m;
|
||||
cin >> n >> m;
|
||||
vec<vec<pair<u32, u32>>> graph(n + 1);
|
||||
for (u32 i = 0; i < m; ++i) {
|
||||
u32 u, v, w;
|
||||
cin >> u >> v >> w;
|
||||
graph[u].push_back({v, w});
|
||||
graph[v].push_back({u, w});
|
||||
}
|
||||
vec<u32> s(n + 1);
|
||||
for (u32 i = 1; i <= n; ++i)
|
||||
cin >> s[i];
|
||||
|
||||
const i64 INF = static_cast<i64>(4e18);
|
||||
vec<vec<i64>> dist(n + 1, vec<i64>(1001, INF));
|
||||
using T = tuple<i64, u32, u32>;
|
||||
priority_queue<T, vec<T>, greater<T>> pq;
|
||||
|
||||
u32 b0 = s[1];
|
||||
dist[1][b0] = 0;
|
||||
pq.emplace(0, 1, b0);
|
||||
|
||||
while (!pq.empty()) {
|
||||
auto [t, u, b] = pq.top();
|
||||
pq.pop();
|
||||
if (t != dist[u][b])
|
||||
continue;
|
||||
u32 nb = min(b, s[u]);
|
||||
if (nb < b && t < dist[u][nb]) {
|
||||
dist[u][nb] = t;
|
||||
pq.emplace(t, u, nb);
|
||||
}
|
||||
for (auto [v, w] : graph[u]) {
|
||||
i64 nt = t + static_cast<i64>(w) * static_cast<i64>(b);
|
||||
if (nt < dist[v][b]) {
|
||||
dist[v][b] = nt;
|
||||
pq.emplace(nt, v, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i64 ans = INF;
|
||||
for (u32 b = 1; b <= 1000; ++b)
|
||||
ans = min(ans, dist[n][b]);
|
||||
cout << ans << '\n';
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
11
codeforces/918/io/a.in
Normal file
11
codeforces/918/io/a.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
10
|
||||
1 2 2
|
||||
4 3 4
|
||||
5 5 6
|
||||
7 8 8
|
||||
9 0 9
|
||||
3 6 3
|
||||
2 8 2
|
||||
5 7 7
|
||||
7 7 5
|
||||
5 7 5
|
||||
14
codeforces/918/io/a.out
Normal file
14
codeforces/918/io/a.out
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
1
|
||||
3
|
||||
6
|
||||
7
|
||||
0
|
||||
6
|
||||
8
|
||||
5
|
||||
5
|
||||
7
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.48575 ms
|
||||
[debug]: false
|
||||
10
codeforces/918/io/b.in
Normal file
10
codeforces/918/io/b.in
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
3
|
||||
ABC
|
||||
C?B
|
||||
BCA
|
||||
BCA
|
||||
CA?
|
||||
ABC
|
||||
?AB
|
||||
BCA
|
||||
ABC
|
||||
7
codeforces/918/io/b.out
Normal file
7
codeforces/918/io/b.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
A
|
||||
B
|
||||
C
|
||||
|
||||
[code]: 0
|
||||
[time]: 5.89085 ms
|
||||
[debug]: false
|
||||
11
codeforces/918/io/c.in
Normal file
11
codeforces/918/io/c.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
5
|
||||
1
|
||||
9
|
||||
2
|
||||
14 2
|
||||
7
|
||||
1 2 3 4 5 6 7
|
||||
6
|
||||
1 3 5 7 9 11
|
||||
4
|
||||
2 2 2 2
|
||||
9
codeforces/918/io/c.out
Normal file
9
codeforces/918/io/c.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
NO
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 6.36053 ms
|
||||
[debug]: false
|
||||
13
codeforces/918/io/d.in
Normal file
13
codeforces/918/io/d.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
8
|
||||
bacedbab
|
||||
4
|
||||
baba
|
||||
13
|
||||
daddecabeddad
|
||||
3
|
||||
dac
|
||||
6
|
||||
dacdac
|
||||
22
|
||||
dababbabababbabbababba
|
||||
10
codeforces/918/io/d.out
Normal file
10
codeforces/918/io/d.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
ba.ced.bab
|
||||
ba.ba
|
||||
dad.de.ca.bed.dad
|
||||
dac
|
||||
dac.dac
|
||||
da.bab.ba.ba.bab.bab.ba.bab.ba
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.4178 ms
|
||||
[debug]: false
|
||||
13
codeforces/918/io/e.in
Normal file
13
codeforces/918/io/e.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
3
|
||||
1 3 2
|
||||
6
|
||||
1 1 1 1 1 1
|
||||
10
|
||||
1 6 9 8 55 3 14 2 7 2
|
||||
8
|
||||
1 2 11 4 1 5 1 2
|
||||
6
|
||||
2 6 1 5 7 8
|
||||
9
|
||||
2 5 10 4 4 9 6 7 8
|
||||
10
codeforces/918/io/e.out
Normal file
10
codeforces/918/io/e.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
YES
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 9.7537 ms
|
||||
[debug]: false
|
||||
27
codeforces/918/io/f.in
Normal file
27
codeforces/918/io/f.in
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
5
|
||||
2
|
||||
2 3
|
||||
1 4
|
||||
6
|
||||
2 6
|
||||
3 9
|
||||
4 5
|
||||
1 8
|
||||
7 10
|
||||
-2 100
|
||||
4
|
||||
-10 10
|
||||
-5 5
|
||||
-12 12
|
||||
-13 13
|
||||
5
|
||||
-4 9
|
||||
-2 5
|
||||
3 4
|
||||
6 7
|
||||
8 10
|
||||
4
|
||||
1 2
|
||||
3 4
|
||||
5 6
|
||||
7 8
|
||||
30
codeforces/918/io/f.out
Normal file
30
codeforces/918/io/f.out
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
f.cc: In function ‘i64 inv_merge(std::vector<long int>&, std::vector<long int>&)’:
|
||||
f.cc:61:7: error: ‘r’ was not declared in this scope
|
||||
61 | if (r - l <= 1)
|
||||
| ^
|
||||
f.cc:61:11: error: ‘l’ was not declared in this scope
|
||||
61 | if (r - l <= 1)
|
||||
| ^
|
||||
f.cc:63:12: error: ‘l’ was not declared in this scope
|
||||
63 | int m = (l + r) >> 1;
|
||||
| ^
|
||||
f.cc:63:16: error: ‘r’ was not declared in this scope
|
||||
63 | int m = (l + r) >> 1;
|
||||
| ^
|
||||
f.cc: In function ‘void solve()’:
|
||||
f.cc:91:26: error: too many arguments to function ‘i64 inv_merge(std::vector<long int>&, std::vector<long int>&)’
|
||||
91 | println("{}", inv_merge(b, tmp, 0, n));
|
||||
| ~~~~~~~~~^~~~~~~~~~~~~~
|
||||
f.cc:60:5: note: declared here
|
||||
60 | i64 inv_merge(vector<i64>& a, vector<i64>& tmp) {
|
||||
| ^~~~~~~~~
|
||||
f.cc: At global scope:
|
||||
f.cc:39:13: warning: ‘void YES()’ defined but not used [-Wunused-function]
|
||||
39 | static void YES() {
|
||||
| ^~~
|
||||
f.cc:35:13: warning: ‘void NO()’ defined but not used [-Wunused-function]
|
||||
35 | static void NO() {
|
||||
| ^~
|
||||
cc1plus: note: unrecognized command-line option ‘-Wno-sign-promotion’ may have been intended to silence earlier diagnostics
|
||||
|
||||
[code]: 1
|
||||
32
codeforces/918/io/g.in
Normal file
32
codeforces/918/io/g.in
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
3
|
||||
5 5
|
||||
1 2 2
|
||||
3 2 1
|
||||
2 4 5
|
||||
2 5 7
|
||||
4 5 1
|
||||
5 2 1 3 3
|
||||
5 10
|
||||
1 2 5
|
||||
1 3 5
|
||||
1 4 4
|
||||
1 5 8
|
||||
2 3 6
|
||||
2 4 3
|
||||
2 5 2
|
||||
3 4 1
|
||||
3 5 8
|
||||
4 5 2
|
||||
7 2 8 4 1
|
||||
7 10
|
||||
3 2 8
|
||||
2 1 4
|
||||
2 5 7
|
||||
2 6 4
|
||||
7 1 2
|
||||
4 3 5
|
||||
6 4 2
|
||||
6 7 1
|
||||
6 7 4
|
||||
4 5 9
|
||||
7 6 5 4 3 2 1
|
||||
7
codeforces/918/io/g.out
Normal file
7
codeforces/918/io/g.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
19
|
||||
36
|
||||
14
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.39873 ms
|
||||
[debug]: false
|
||||
30
codeforces/918/makefile
Normal file
30
codeforces/918/makefile
Normal 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
|
||||
|
||||
%:
|
||||
@:
|
||||
29
codeforces/918/scripts/debug.sh
Normal file
29
codeforces/918/scripts/debug.sh
Normal 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" true
|
||||
exit $?
|
||||
29
codeforces/918/scripts/run.sh
Normal file
29
codeforces/918/scripts/run.sh
Normal 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 $?
|
||||
61
codeforces/918/scripts/utils.sh
Normal file
61
codeforces/918/scripts/utils.sh
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#!/bin/sh
|
||||
|
||||
execute_binary() {
|
||||
binary="$1"
|
||||
input="$2"
|
||||
output="$3"
|
||||
is_debug="$4"
|
||||
|
||||
start=$(date '+%s.%N')
|
||||
if [ -n "$is_debug" ]; then
|
||||
asan="$(ldconfig -p | grep libasan.so | head -n1 | awk '{print $4}')"
|
||||
LD_PRELOAD="$asan" timeout 2s ./"$binary" <"$input" >"$output" 2>&1
|
||||
else
|
||||
timeout 2s ./"$binary" <"$input" >"$output" 2>&1
|
||||
fi
|
||||
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
|
||||
test -n "$is_debug" && is_debug_string=true || is_debug_string=false
|
||||
printf '\n[debug]: %s' "$is_debug_string" >>$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
|
||||
}
|
||||
|
|
@ -42,3 +42,4 @@ CompileFlags:
|
|||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
|
|
|
|||
87
codeforces/928/f.cc
Normal file
87
codeforces/928/f.cc
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
#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;
|
||||
dbln("before");
|
||||
std::cout << "rad\n";
|
||||
println("{}", n);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
u32 tc = 1;
|
||||
cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
2
codeforces/928/io/f.in
Normal file
2
codeforces/928/io/f.in
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
1
|
||||
2
|
||||
7
codeforces/928/io/f.out
Normal file
7
codeforces/928/io/f.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
before
|
||||
rad
|
||||
2
|
||||
|
||||
[code]: 0
|
||||
[time]: 23.0269 ms
|
||||
[debug]: true
|
||||
Loading…
Add table
Add a link
Reference in a new issue