more files
This commit is contained in:
parent
bbb475ed71
commit
6746faf742
113 changed files with 4693 additions and 1 deletions
9
codeforces/762/.clang-format
Normal file
9
codeforces/762/.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
|
||||
38
codeforces/762/.clangd
Normal file
38
codeforces/762/.clangd
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
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
|
||||
99
codeforces/762/a.cc
Normal file
99
codeforces/762/a.cc
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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 (s.size() % 2 == 0 &&
|
||||
s.substr(0, s.size() / 2) == s.substr(s.size() / 2, s.size())) {
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
103
codeforces/762/b.cc
Normal file
103
codeforces/762/b.cc
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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() {
|
||||
u64 n;
|
||||
cin >> n;
|
||||
|
||||
unordered_set<u64> ans;
|
||||
|
||||
for (u64 x = 1; x * x <= n; ++x) {
|
||||
ans.insert(x * x);
|
||||
}
|
||||
for (u64 x = 1; x * x * x <= n; ++x) {
|
||||
ans.insert(x * x * x);
|
||||
}
|
||||
|
||||
println("{}", ans.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;
|
||||
}
|
||||
// }}}
|
||||
122
codeforces/762/c.cc
Normal file
122
codeforces/762/c.cc
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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() {
|
||||
u64 a, s;
|
||||
cin >> a >> s;
|
||||
|
||||
string ans;
|
||||
|
||||
while (s) {
|
||||
auto ad = a % 10, sd = s % 10;
|
||||
if (ad <= sd) {
|
||||
ans += to_string(sd - ad);
|
||||
} else if (ad > sd && (10 + sd - ad) + ad == s % 100) {
|
||||
ans += to_string(10 + sd - ad);
|
||||
s /= 10;
|
||||
} else {
|
||||
println("-1");
|
||||
return;
|
||||
}
|
||||
s /= 10;
|
||||
a /= 10;
|
||||
}
|
||||
|
||||
if (a) {
|
||||
println("-1");
|
||||
return;
|
||||
}
|
||||
|
||||
reverse(all(ans));
|
||||
u32 i = 0;
|
||||
while (ans[i] == '0')
|
||||
++i;
|
||||
for (; i < ans.size(); ++i)
|
||||
print("{}", ans[i]);
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
31
codeforces/762/compile_flags.txt
Normal file
31
codeforces/762/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
|
||||
168
codeforces/762/d.cc
Normal file
168
codeforces/762/d.cc
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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<100000 + 1> friends;
|
||||
void solve() {
|
||||
/*
|
||||
binary search on alpha
|
||||
|
||||
how to know if i can choose at least n - 1 shops to give each guy a present
|
||||
basically, choose, out of all m shops, n shops, one gives each guy a
|
||||
present (in the worst)
|
||||
|
||||
hm - must dynamically, per bsearch query, filter arrays
|
||||
|
||||
consider each array: if someone unset can be set, + 1 to count, update max
|
||||
if already set, take max of large value
|
||||
|
||||
challenge: n - 1 shops, not all n
|
||||
take a step back:
|
||||
|
||||
we have m arrays, each which set values offriend individually
|
||||
|
||||
consider each friend separately - have multiple values of joy set to; filter to
|
||||
>= mid alphaq
|
||||
|
||||
not nec. choose ones that set most -> greedy
|
||||
|
||||
ok - one shop per friend - per friend, iterate - find shop that sets their joy
|
||||
>= alpha
|
||||
|
||||
now, either < n (bad) or n shops - consider each friend as the "substitute"
|
||||
candidate
|
||||
|
||||
in other words, consider each friend, and iter AGAIN thru the shit - can we
|
||||
find ANOTHER diff array setting this guy, as well as setting another friend?
|
||||
|
||||
if so, done!
|
||||
*/
|
||||
|
||||
u32 m, n;
|
||||
cin >> m >> n;
|
||||
|
||||
vec<vec<u64>> p(m, vec<u64>(n));
|
||||
u64 maxp = 0;
|
||||
for (auto& row : p) {
|
||||
for (auto& e : row) {
|
||||
cin >> e;
|
||||
maxp = max(maxp, e);
|
||||
}
|
||||
}
|
||||
|
||||
u64 l = 1, r = maxp;
|
||||
|
||||
auto ok = [&](u64 alpha) {
|
||||
friends.reset();
|
||||
bool both_covered = false;
|
||||
|
||||
for (auto& shop : p) {
|
||||
u32 shop_count = 0;
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
if (shop[i] >= alpha) {
|
||||
++shop_count;
|
||||
friends.set(i);
|
||||
}
|
||||
}
|
||||
both_covered |= shop_count > 1;
|
||||
}
|
||||
|
||||
return friends.count() == n && both_covered;
|
||||
};
|
||||
|
||||
while (l <= r) {
|
||||
u64 alpha = l + (r - l) / 2;
|
||||
|
||||
if (ok(alpha)) {
|
||||
l = alpha + 1;
|
||||
} else {
|
||||
r = alpha - 1;
|
||||
}
|
||||
}
|
||||
|
||||
println("{}", r);
|
||||
}
|
||||
|
||||
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/762/debug_flags.txt
Normal file
14
codeforces/762/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
|
||||
187
codeforces/762/e.cc
Normal file
187
codeforces/762/e.cc
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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() {
|
||||
/*
|
||||
i=0->n, # opers (-1 if no)
|
||||
|
||||
|
||||
when impossible? mex MEX, cannot form 0, 1, 2, ... MEX - 1
|
||||
|
||||
consider bf, needing to form mex MEX
|
||||
need MEX - 1 - take if there
|
||||
ow, need i; take from largest candidate x, i - x "pull" it up, b/c closest
|
||||
|
||||
continue repeatedly - if not there, return -1
|
||||
|
||||
for all n, n^2 bf
|
||||
|
||||
is there a recursive structure?
|
||||
|
||||
say i pull up for mex MEX, does this help with MEX + 1
|
||||
what's the challenge - pulling up to MEX, may need to pull up to MEX - 1,
|
||||
etc. then the gap eventually filled (if solution)
|
||||
|
||||
idea, as go L->R, pull up minimal for answer -> making 0->MEX; also pull up
|
||||
|
||||
observation - say missing for mex MEX, need to poull up - repeatedly
|
||||
hoisting each, to push up is same as pulling up from closest gap index; keep
|
||||
track of gap indices, and pull from closest one?
|
||||
|
||||
but is puling from closets optimal? -> yes, it is
|
||||
|
||||
narrow down in on this
|
||||
|
||||
also, you have to push elements away - i.e., for each element equal to the
|
||||
mex, + 1 is the "extra" count
|
||||
|
||||
so, for mex M; push freq[m] first
|
||||
then, pull for M - 1, and take max free unused #, M - it, + 1 to the prev
|
||||
score (excluding the M count there)
|
||||
|
||||
subtleties: the equal count - if matching MEX - 1 required pushing, we don't
|
||||
need to (we can ignore count) really, we just care about pulled for each in our
|
||||
dependent calculations
|
||||
|
||||
let's be concrete
|
||||
|
||||
mex MEX, solved 0->MEX - 1
|
||||
|
||||
- sort a increasingly, and for each mex
|
||||
1. push off ==MEX values
|
||||
2. define pull[mex] as total cost of pulling to make 0->mex-1
|
||||
- if no pull[MEX-1], -1
|
||||
- else,
|
||||
pull from largest available value, adding MEX - 1 - value
|
||||
- pop used value
|
||||
push self
|
||||
|
||||
great, now, impl
|
||||
|
||||
we iter over array and mex from 0 to n - which order?
|
||||
def iter over mex, then have freq map + available
|
||||
|
||||
AFTER: so many mistakes
|
||||
|
||||
only push f-1 elems, using 64-bit types, ease of implementation, breaking loop, using accumulator instead of deriving, etc.
|
||||
*/
|
||||
u64 n;
|
||||
cin >> n;
|
||||
vec<i64> a(n);
|
||||
map<i64, i64> f;
|
||||
for (auto& e : a) {
|
||||
cin >> e;
|
||||
++f[e];
|
||||
}
|
||||
|
||||
vec<i64> available;
|
||||
vec<i64> ans(n + 1, -1);
|
||||
|
||||
ans[0] = f[0];
|
||||
for (i64 i = 0; i < max((i64)0, f[0] - 1); ++i)
|
||||
available.push_back(0);
|
||||
|
||||
for (i64 mex = 1; mex <= (i64)n; ++mex) {
|
||||
ans[mex] = ans[mex - 1] - f[mex - 1] + f[mex];
|
||||
|
||||
if (f[mex - 1] == 0) {
|
||||
if (available.empty()) {
|
||||
ans[mex] = -1;
|
||||
break;
|
||||
}
|
||||
ans[mex] += (mex - 1 - available.back());
|
||||
available.pop_back();
|
||||
}
|
||||
|
||||
for (i64 i = 0; i < max((i64)0, f[mex] - 1); ++i)
|
||||
available.push_back(mex);
|
||||
}
|
||||
|
||||
for (u64 i = 0; i <= n; ++i)
|
||||
cout << ans[i] << " \n"[i == 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;
|
||||
}
|
||||
// }}}
|
||||
122
codeforces/762/e2.cc
Normal file
122
codeforces/762/e2.cc
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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;
|
||||
map<u32, u64> f;
|
||||
for (auto e : a)
|
||||
++f[e];
|
||||
|
||||
u64 pull = 0;
|
||||
vec<i64> ans(n + 1, -1);
|
||||
vec<u32> available;
|
||||
|
||||
for (u32 mex = 0; mex <= n; ++mex) {
|
||||
if (mex > 0 && f[mex - 1] == 0) {
|
||||
if (available.empty()) {
|
||||
break;
|
||||
}
|
||||
pull += mex - 1 - available.back();
|
||||
available.pop_back();
|
||||
}
|
||||
ans[mex] = pull + f[mex];
|
||||
|
||||
for (u32 i = 0; i < (f[mex] > 0 ? f[mex] - 1 : 0); ++i) {
|
||||
available.push_back(mex);
|
||||
}
|
||||
}
|
||||
|
||||
for (u32 i = 0; i <= n; ++i) {
|
||||
cout << ans[i] << " \n"[i == 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/762/io/a.in
Normal file
11
codeforces/762/io/a.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
10
|
||||
a
|
||||
aa
|
||||
aaa
|
||||
aaaa
|
||||
abab
|
||||
abcabc
|
||||
abacaba
|
||||
xxyy
|
||||
xyyx
|
||||
xyxy
|
||||
14
codeforces/762/io/a.out
Normal file
14
codeforces/762/io/a.out
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
NO
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
YES
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 6.08635 ms
|
||||
[debug]: false
|
||||
8
codeforces/762/io/b.in
Normal file
8
codeforces/762/io/b.in
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
6
|
||||
10
|
||||
1
|
||||
25
|
||||
1000000000
|
||||
999999999
|
||||
500000000
|
||||
|
||||
10
codeforces/762/io/b.out
Normal file
10
codeforces/762/io/b.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
4
|
||||
1
|
||||
6
|
||||
32591
|
||||
32590
|
||||
23125
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.6577 ms
|
||||
[debug]: false
|
||||
8
codeforces/762/io/c.in
Normal file
8
codeforces/762/io/c.in
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
7
|
||||
17236 1106911
|
||||
1 5
|
||||
108 112
|
||||
12345 1023412
|
||||
1 11
|
||||
1 20
|
||||
200 202
|
||||
11
codeforces/762/io/c.out
Normal file
11
codeforces/762/io/c.out
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
3465
|
||||
4
|
||||
-1
|
||||
90007
|
||||
10
|
||||
-1
|
||||
2
|
||||
|
||||
[code]: 0
|
||||
[time]: 5.78475 ms
|
||||
[debug]: false
|
||||
25
codeforces/762/io/d.in
Normal file
25
codeforces/762/io/d.in
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
5
|
||||
|
||||
2 2
|
||||
1 2
|
||||
3 4
|
||||
|
||||
4 3
|
||||
1 3 1
|
||||
3 1 1
|
||||
1 2 2
|
||||
1 1 3
|
||||
|
||||
2 3
|
||||
5 3 4
|
||||
2 5 1
|
||||
|
||||
4 2
|
||||
7 9
|
||||
8 1
|
||||
9 6
|
||||
10 8
|
||||
|
||||
2 4
|
||||
6 5 2 1
|
||||
7 9 7 2
|
||||
9
codeforces/762/io/d.out
Normal file
9
codeforces/762/io/d.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
3
|
||||
2
|
||||
4
|
||||
8
|
||||
2
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.3489 ms
|
||||
[debug]: false
|
||||
12
codeforces/762/io/e.in
Normal file
12
codeforces/762/io/e.in
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
5
|
||||
3
|
||||
0 1 3
|
||||
7
|
||||
0 1 2 3 4 3 2
|
||||
4
|
||||
3 0 0 0
|
||||
7
|
||||
4 6 2 3 5 0 5
|
||||
5
|
||||
4 0 1 0 4
|
||||
|
||||
9
codeforces/762/io/e.out
Normal file
9
codeforces/762/io/e.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
1 1 0 -1
|
||||
1 1 2 2 1 0 2 6
|
||||
3 0 1 4 3
|
||||
1 0 -1 -1 -1 -1 -1 -1
|
||||
2 1 0 2 -1 -1
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.57897 ms
|
||||
[debug]: false
|
||||
11
codeforces/762/io/e2.in
Normal file
11
codeforces/762/io/e2.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
5
|
||||
3
|
||||
0 1 3
|
||||
7
|
||||
0 1 2 3 4 3 2
|
||||
4
|
||||
3 0 0 0
|
||||
7
|
||||
4 6 2 3 5 0 5
|
||||
5
|
||||
4 0 1 0 4
|
||||
9
codeforces/762/io/e2.out
Normal file
9
codeforces/762/io/e2.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
1 1 0 -1
|
||||
1 1 2 2 1 0 2 6
|
||||
3 0 1 4 3
|
||||
1 0 -1 -1 -1 -1 -1 -1
|
||||
2 1 0 2 -1 -1
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.49767 ms
|
||||
[debug]: false
|
||||
30
codeforces/762/makefile
Normal file
30
codeforces/762/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/762/scripts/debug.sh
Normal file
29
codeforces/762/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/762/scripts/run.sh
Normal file
29
codeforces/762/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/762/scripts/utils.sh
Normal file
61
codeforces/762/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/920/.clang-format
Normal file
9
codeforces/920/.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
|
||||
44
codeforces/920/.clangd
Normal file
44
codeforces/920/.clangd
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
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
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
99
codeforces/920/a.cc
Normal file
99
codeforces/920/a.cc
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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<pair<u32, u32>> coords(4);
|
||||
for (auto& coord : coords)
|
||||
cin >> coord.first >> coord.second;
|
||||
|
||||
sort(all(coords));
|
||||
|
||||
auto side = coords[1].second - coords[0].second;
|
||||
|
||||
println("{}", side * side);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
124
codeforces/920/b.cc
Normal file
124
codeforces/920/b.cc
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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() {
|
||||
/*
|
||||
if both set/unset -> done
|
||||
|
||||
if final set, start unset - need + 1
|
||||
if orig set, final unset - must move
|
||||
|
||||
must delete x, need y slots
|
||||
|
||||
use min(x, y) slots for y
|
||||
|
||||
remaining y must be added, remaining x must be deleted
|
||||
*/
|
||||
|
||||
u32 n;
|
||||
cin >> n;
|
||||
|
||||
string a, b;
|
||||
cin >> a >> b;
|
||||
|
||||
u32 A{}, B{};
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
if (a[i] == b[i]) {
|
||||
continue;
|
||||
}
|
||||
if (a[i] == '1')
|
||||
++A;
|
||||
else
|
||||
++B;
|
||||
}
|
||||
|
||||
u32 ans = B;
|
||||
A -= min(A, B);
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
137
codeforces/920/c.cc
Normal file
137
codeforces/920/c.cc
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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() {
|
||||
u64 n;
|
||||
i64 f, b, a;
|
||||
cin >> n >> f >> a >> b;
|
||||
|
||||
vec<i64> m(n);
|
||||
for (auto& e : m) {
|
||||
cin >> e;
|
||||
}
|
||||
|
||||
i64 prev = 0;
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
auto delta = m[i] - prev;
|
||||
f -= min(b, delta * a);
|
||||
prev = m[i];
|
||||
}
|
||||
|
||||
if (f <= 0) {
|
||||
NO();
|
||||
} else {
|
||||
YES();
|
||||
}
|
||||
|
||||
/*
|
||||
f charge
|
||||
off costs b
|
||||
on costs 1
|
||||
|
||||
if
|
||||
|
||||
when to turn on/off the phone?
|
||||
|
||||
NOTE: phone starts on
|
||||
assume phone turns off, then, of course, you have to turn on at m[0]
|
||||
|
||||
so, WLOG, the phone is on
|
||||
|
||||
when to turn off?
|
||||
if i have to wait > b to turn off, it will cost me > b; otherwise, it costs
|
||||
me b
|
||||
|
||||
wait, or turn off then on?
|
||||
say delta seconds pass: min(delta * a, 2*b)
|
||||
|
||||
details: message sending
|
||||
|
||||
iter thru m, take time delta
|
||||
*/
|
||||
}
|
||||
|
||||
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/920/compile_flags.txt
Normal file
31
codeforces/920/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
|
||||
147
codeforces/920/d.cc
Normal file
147
codeforces/920/d.cc
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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<i64> a(n), b(m);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
for (auto& e : b)
|
||||
cin >> e;
|
||||
|
||||
/*
|
||||
idea: maximize difference from a to b
|
||||
|
||||
note: order doesn't matter in matching (but must print output)
|
||||
|
||||
sort a?
|
||||
|
||||
hm: consider a[0], w/ some remaining candidates
|
||||
|
||||
min/max choice from b optimal - take better, alter ptrs
|
||||
|
||||
3 6 7 9 10
|
||||
2 3 5 9 9
|
||||
|
||||
8
|
||||
|
||||
1 2 4 6
|
||||
1 2 3 3 5 7
|
||||
|
||||
6532
|
||||
|
||||
|
||||
tbh, idk why greedy even works here
|
||||
*/
|
||||
sort(all(a));
|
||||
sort(all(b));
|
||||
|
||||
u32 a_l = 0, a_r = n - 1;
|
||||
u32 b_l = 0, b_r = m - 1;
|
||||
u64 ans = 0;
|
||||
while (a_l <= a_r) {
|
||||
array<i64, 4> diffs{abs(a[a_l] - b[b_l]), abs(a[a_l] - b[b_r]),
|
||||
abs(a[a_r] - b[b_l]), abs(a[a_r] - b[b_r])};
|
||||
|
||||
auto best_diff = max_element(all(diffs));
|
||||
auto i = distance(diffs.begin(), best_diff);
|
||||
|
||||
ans += *best_diff;
|
||||
|
||||
if (i < 2)
|
||||
++a_l;
|
||||
else
|
||||
--a_r;
|
||||
if (i % 2 == 0)
|
||||
++b_l;
|
||||
else
|
||||
--b_r;
|
||||
}
|
||||
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/920/debug_flags.txt
Normal file
14
codeforces/920/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
|
||||
181
codeforces/920/e.cc
Normal file
181
codeforces/920/e.cc
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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() {
|
||||
i64 n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
i64 ar, ac, br, bc;
|
||||
cin >> ar >> ac >> br >> bc;
|
||||
|
||||
// NOTE: forgot to adjust frontier + 1 (rly think thru!)
|
||||
|
||||
string ans{"Draw"};
|
||||
if (ar < br) {
|
||||
i64 frontier = (u64)ceill((ar + br) / 2.0);
|
||||
|
||||
// NOTE: key is alice gets extra move
|
||||
// TBH, still confused (see mistaken note above) - don't understand
|
||||
// didn't think about "optimal" play - i.e. alice leading one way
|
||||
// can bob just go the opposite? then, alice ought to lead straight
|
||||
// i think if u dig into the logic alice can lead straight in which bob
|
||||
// can't do antyhing, but anyway all of this logic circumvented my mind, smh
|
||||
// NOTE: this is why - SIMPLIFY
|
||||
// simply consider the two player's positions on the frontier row itself -
|
||||
// both on the same alice goes first so she gets extra move if frontier
|
||||
// distance odd also, optimal strategy principle (explore too)
|
||||
i64 aleft = max((i64)1, ac - (frontier - ar));
|
||||
i64 aright = min(m, ac + frontier - ar);
|
||||
|
||||
i64 bleft = max((i64)1, bc - (br - frontier));
|
||||
i64 bright = min(m, bc + (br - frontier));
|
||||
|
||||
bool alice_aggressor = (br - ar) & 1;
|
||||
|
||||
if (alice_aggressor) {
|
||||
if (aleft <= bleft && aright >= bright) {
|
||||
ans = "Alice";
|
||||
}
|
||||
} else {
|
||||
if (bleft <= aleft && bright >= aright) {
|
||||
ans = "Bob";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println("{}", ans);
|
||||
/*
|
||||
|
||||
--A-------
|
||||
-A-A------
|
||||
BB--------
|
||||
B---------
|
||||
----------
|
||||
----------
|
||||
----------
|
||||
----------
|
||||
----------
|
||||
----------
|
||||
|
||||
Alice
|
||||
Bob
|
||||
Draw
|
||||
Draw
|
||||
Draw
|
||||
Alice
|
||||
Draw
|
||||
Draw
|
||||
Bob
|
||||
Alice
|
||||
Alice
|
||||
Draw
|
||||
|
||||
idea: consider frontier
|
||||
|
||||
note: ar >= br -> DRAW
|
||||
ow, alice below bob, and there is a frontier
|
||||
|
||||
alice/bob have frontier pos - enumerate them
|
||||
find aggressor - they cannot lose
|
||||
|
||||
if aggressor can take all passive piece -> win, print aggressor
|
||||
ow, draw
|
||||
|
||||
chess moment :sunglasses:
|
||||
|
||||
O(h) -> ok
|
||||
|
||||
to flesh out:
|
||||
|
||||
derive frontier row
|
||||
derive a/b cols on row
|
||||
derive aggressor
|
||||
|
||||
note: only care about the coords
|
||||
*/
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
13
codeforces/920/io/a.in
Normal file
13
codeforces/920/io/a.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
3
|
||||
1 2
|
||||
4 5
|
||||
1 5
|
||||
4 2
|
||||
-1 1
|
||||
1 -1
|
||||
1 1
|
||||
-1 -1
|
||||
45 11
|
||||
45 39
|
||||
17 11
|
||||
17 39
|
||||
7
codeforces/920/io/a.out
Normal file
7
codeforces/920/io/a.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
9
|
||||
4
|
||||
784
|
||||
|
||||
[code]: 0
|
||||
[time]: 6.03485 ms
|
||||
[debug]: false
|
||||
19
codeforces/920/io/b.in
Normal file
19
codeforces/920/io/b.in
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
6
|
||||
5
|
||||
10010
|
||||
00001
|
||||
1
|
||||
1
|
||||
1
|
||||
3
|
||||
000
|
||||
111
|
||||
4
|
||||
0101
|
||||
1010
|
||||
3
|
||||
100
|
||||
101
|
||||
8
|
||||
10011001
|
||||
11111110
|
||||
10
codeforces/920/io/b.out
Normal file
10
codeforces/920/io/b.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
2
|
||||
0
|
||||
3
|
||||
2
|
||||
1
|
||||
4
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.50673 ms
|
||||
[debug]: false
|
||||
13
codeforces/920/io/c.in
Normal file
13
codeforces/920/io/c.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
1 3 1 5
|
||||
3
|
||||
7 21 1 3
|
||||
4 6 10 13 17 20 26
|
||||
5 10 1 2
|
||||
1 2 3 4 5
|
||||
1 1000000000 1000000000 1000000000
|
||||
1000000000
|
||||
3 11 9 6
|
||||
6 8 10
|
||||
12 621526648 2585904 3566299
|
||||
51789 61859 71998 73401 247675 298086 606959 663464 735972 806043 806459 919683
|
||||
10
codeforces/920/io/c.out
Normal file
10
codeforces/920/io/c.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
NO
|
||||
YES
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 5.87606 ms
|
||||
[debug]: false
|
||||
28
codeforces/920/io/d.in
Normal file
28
codeforces/920/io/d.in
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
9
|
||||
4 6
|
||||
6 1 2 4
|
||||
3 5 1 7 2 3
|
||||
3 4
|
||||
1 1 1
|
||||
1 1 1 1
|
||||
5 5
|
||||
1 2 3 4 5
|
||||
1 2 3 4 5
|
||||
2 6
|
||||
5 8
|
||||
8 7 5 8 2 10
|
||||
2 2
|
||||
4 1
|
||||
9 6
|
||||
4 6
|
||||
8 10 6 4
|
||||
3 10 6 1 8 9
|
||||
3 5
|
||||
6 5 2
|
||||
1 7 9 7 2
|
||||
5 5
|
||||
9 10 6 3 7
|
||||
5 9 2 3 9
|
||||
1 6
|
||||
3
|
||||
2 7 10 1 1 5
|
||||
13
codeforces/920/io/d.out
Normal file
13
codeforces/920/io/d.out
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
16
|
||||
0
|
||||
12
|
||||
11
|
||||
10
|
||||
23
|
||||
15
|
||||
25
|
||||
7
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.69318 ms
|
||||
[debug]: false
|
||||
13
codeforces/920/io/e.in
Normal file
13
codeforces/920/io/e.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
12
|
||||
6 5 2 2 5 3
|
||||
4 1 2 1 4 1
|
||||
1 4 1 3 1 1
|
||||
5 5 1 4 5 2
|
||||
4 4 1 1 4 4
|
||||
10 10 1 6 10 8
|
||||
10 10 2 6 10 7
|
||||
10 10 9 1 8 1
|
||||
10 10 8 1 10 2
|
||||
10 10 1 1 2 1
|
||||
10 10 1 3 4 1
|
||||
10 10 3 1 1 1
|
||||
16
codeforces/920/io/e.out
Normal file
16
codeforces/920/io/e.out
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
Alice
|
||||
Bob
|
||||
Draw
|
||||
Draw
|
||||
Draw
|
||||
Alice
|
||||
Draw
|
||||
Draw
|
||||
Bob
|
||||
Alice
|
||||
Alice
|
||||
Draw
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.4941 ms
|
||||
[debug]: false
|
||||
30
codeforces/920/makefile
Normal file
30
codeforces/920/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/920/scripts/debug.sh
Normal file
29
codeforces/920/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/920/scripts/run.sh
Normal file
29
codeforces/920/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/920/scripts/utils.sh
Normal file
61
codeforces/920/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/929/.clang-format
Normal file
9
codeforces/929/.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
|
||||
46
codeforces/929/.clangd
Normal file
46
codeforces/929/.clangd
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
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
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++20
|
||||
-e -std=c++23
|
||||
129
codeforces/929/a.cc
Normal file
129
codeforces/929/a.cc
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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
|
||||
// }}}
|
||||
|
||||
#include <ext/pb_ds/assoc_container.hpp>
|
||||
#include <ext/pb_ds/tree_policy.hpp>
|
||||
namespace pbds = __gnu_pbds;
|
||||
|
||||
template <class T>
|
||||
using hashset = pbds::gp_hash_table<T, pbds::null_type>;
|
||||
|
||||
template <class K, class V>
|
||||
using hashmap = pbds::gp_hash_table<K, V>;
|
||||
|
||||
template <class K, class V>
|
||||
using treemultimap =
|
||||
pbds::tree<K, V, less_equal<K>, pbds::rb_tree_tag,
|
||||
pbds::tree_order_statistics_node_update>;
|
||||
|
||||
template <class T>
|
||||
using treeset =
|
||||
pbds::tree<T, pbds::null_type, less<T>, pbds::rb_tree_tag,
|
||||
pbds::tree_order_statistics_node_update>;
|
||||
|
||||
template <class K, class V>
|
||||
using treemap =
|
||||
pbds::tree<K, V, less<K>, pbds::rb_tree_tag,
|
||||
pbds::tree_order_statistics_node_update>;
|
||||
|
||||
template <class T>
|
||||
using treemultiset =
|
||||
pbds::tree<T, pbds::null_type, less_equal<T>, pbds::rb_tree_tag,
|
||||
pbds::tree_order_statistics_node_update>;
|
||||
|
||||
void solve() {
|
||||
u32 n;
|
||||
cin >> n;
|
||||
vec<i64> a(n);
|
||||
for (auto& e : a) {
|
||||
cin >> e;
|
||||
e = abs(e);
|
||||
}
|
||||
|
||||
cout << accumulate(all(a), 0LL) << '\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;
|
||||
}
|
||||
// }}}
|
||||
120
codeforces/929/b.cc
Normal file
120
codeforces/929/b.cc
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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);
|
||||
u64 odd = 0;
|
||||
for (auto& e : a) {
|
||||
cin >> e;
|
||||
if (e & 1)
|
||||
odd = e;
|
||||
}
|
||||
|
||||
auto A = accumulate(all(a), 0LL);
|
||||
u32 ans = 2;
|
||||
|
||||
switch (A % 3) {
|
||||
case 0:
|
||||
cout << "0\n";
|
||||
return;
|
||||
case 1:
|
||||
for (auto e : a) {
|
||||
if ((A - e) % 3 == 0) {
|
||||
ans = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cout << ans << '\n';
|
||||
return;
|
||||
case 2:
|
||||
cout << "1\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;
|
||||
}
|
||||
// }}}
|
||||
106
codeforces/929/c.cc
Normal file
106
codeforces/929/c.cc
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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() {
|
||||
u64 a, b, l;
|
||||
cin >> a >> b >> l;
|
||||
|
||||
unordered_set<u64> seen;
|
||||
|
||||
u64 ax = 1;
|
||||
for (u32 x = 0; x <= 20 && ax <= l; ++x, ax *= a) {
|
||||
u64 by = 1;
|
||||
for (u32 y = 0; y <= 20 & ax * by <= l; ++y, by *= b) {
|
||||
if (l % (ax * by) == 0) {
|
||||
seen.insert(l / (ax * by));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println("{}", seen.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;
|
||||
}
|
||||
// }}}
|
||||
31
codeforces/929/compile_flags.txt
Normal file
31
codeforces/929/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
|
||||
111
codeforces/929/d.cc
Normal file
111
codeforces/929/d.cc
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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;
|
||||
|
||||
sort(all(a));
|
||||
|
||||
if (a[0] != a[1]) {
|
||||
YES();
|
||||
return;
|
||||
}
|
||||
|
||||
for (u32 i = 2; i < n; ++i) {
|
||||
if (a[i] % a[0] != 0) {
|
||||
YES();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
14
codeforces/929/debug_flags.txt
Normal file
14
codeforces/929/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
|
||||
133
codeforces/929/e.cc
Normal file
133
codeforces/929/e.cc
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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;
|
||||
vec<i64> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
vec<i64> pref(n + 1, 0);
|
||||
for (i32 i = 1; i <= n; ++i) {
|
||||
pref[i] = pref[i - 1] + a[i - 1];
|
||||
}
|
||||
|
||||
u32 q;
|
||||
cin >> q;
|
||||
|
||||
i64 u;
|
||||
i32 l;
|
||||
|
||||
auto f = [&](i64 i) {
|
||||
auto S = pref[i] - pref[l - 1];
|
||||
return (u + 1) * S - S * (S + 1) / 2;
|
||||
};
|
||||
|
||||
auto delta = [&](i64 i) {
|
||||
return f(i) - f(i - 1);
|
||||
};
|
||||
|
||||
for (u32 i = 0; i < q; ++i) {
|
||||
cin >> l >> u;
|
||||
|
||||
i32 L = l + 1, R = n;
|
||||
|
||||
while (L <= R) {
|
||||
auto M = L + (R - L) / 2;
|
||||
|
||||
if (delta(M) > 0) {
|
||||
L = M + 1;
|
||||
} else {
|
||||
R = M - 1;
|
||||
}
|
||||
}
|
||||
|
||||
print("{}{}", L - 1, " \n"[i == q - 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;
|
||||
}
|
||||
// }}}
|
||||
145
codeforces/929/f.cc
Normal file
145
codeforces/929/f.cc
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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<1000000 + 1> seen;
|
||||
|
||||
void solve() {
|
||||
seen.reset();
|
||||
|
||||
i32 n, m;
|
||||
cin >> n >> m;
|
||||
vec<vec<u32>> grid(n, vec<u32>(m));
|
||||
for (auto& row : grid)
|
||||
for (auto& cell : row)
|
||||
cin >> cell;
|
||||
|
||||
queue<pair<i32, i32>> q{{{0, 0}}};
|
||||
auto index = [&](i32 r, i32 c) {
|
||||
return r * m + c;
|
||||
};
|
||||
|
||||
seen.set(index(0, 0));
|
||||
|
||||
auto valid = [&](i32 r, i32 c) {
|
||||
return min(r, c) >= 0 && r < n && c < m;
|
||||
};
|
||||
|
||||
i32 time = 0;
|
||||
i32 ans = MAX<i32>;
|
||||
while (!q.empty()) {
|
||||
auto qsize{q.size()};
|
||||
|
||||
for (u32 i = 0; i < qsize; ++i) {
|
||||
auto [r, c] = q.front();
|
||||
q.pop();
|
||||
|
||||
if (c == m - 1) {
|
||||
ans = min(ans, time + min(n - 1 - r, (r + 1) % n));
|
||||
continue;
|
||||
}
|
||||
|
||||
i32 T = time % n;
|
||||
|
||||
if (c < m - 1 && grid[(r + T + 1) % n][c + 1] == 0 &&
|
||||
!seen[index(r, c + 1)]) {
|
||||
q.emplace(r, c + 1);
|
||||
seen.set(index(r, c + 1));
|
||||
}
|
||||
|
||||
if (grid[(r + T + 1) % n][c] == 0 && grid[(r + T + 2) % n][c] == 0 &&
|
||||
!seen[index((r + 1) % n, c)]) {
|
||||
q.emplace((r + 1) % n, c);
|
||||
seen.set(index((r + 1) % n, c));
|
||||
}
|
||||
}
|
||||
|
||||
++time;
|
||||
}
|
||||
|
||||
println("{}", ans == MAX<i32> ? -1 : 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;
|
||||
}
|
||||
// }}}
|
||||
17
codeforces/929/io/a.in
Normal file
17
codeforces/929/io/a.in
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
8
|
||||
3
|
||||
-2 3 -3
|
||||
1
|
||||
0
|
||||
2
|
||||
0 1
|
||||
1
|
||||
-99
|
||||
4
|
||||
10 -2 -3 7
|
||||
5
|
||||
-1 -2 -3 -4 -5
|
||||
6
|
||||
-41 22 -69 73 -15 -50
|
||||
12
|
||||
1 2 3 4 5 6 7 8 9 10 11 12
|
||||
12
codeforces/929/io/a.out
Normal file
12
codeforces/929/io/a.out
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
8
|
||||
0
|
||||
1
|
||||
99
|
||||
22
|
||||
15
|
||||
270
|
||||
78
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.30837 ms
|
||||
[debug]: false
|
||||
18
codeforces/929/io/b.in
Normal file
18
codeforces/929/io/b.in
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
8
|
||||
4
|
||||
2 2 5 4
|
||||
3
|
||||
1 3 2
|
||||
4
|
||||
3 7 6 8
|
||||
1
|
||||
1
|
||||
4
|
||||
2 2 4 2
|
||||
2
|
||||
5 5
|
||||
7
|
||||
2 4 8 1 9 3 4
|
||||
2
|
||||
4 10
|
||||
|
||||
12
codeforces/929/io/b.out
Normal file
12
codeforces/929/io/b.out
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
1
|
||||
0
|
||||
0
|
||||
1
|
||||
1
|
||||
2
|
||||
1
|
||||
1
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.33126 ms
|
||||
[debug]: false
|
||||
12
codeforces/929/io/c.in
Normal file
12
codeforces/929/io/c.in
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
11
|
||||
2 5 20
|
||||
2 5 21
|
||||
4 6 48
|
||||
2 3 72
|
||||
3 5 75
|
||||
2 2 1024
|
||||
3 7 83349
|
||||
100 100 1000000
|
||||
7 3 2
|
||||
2 6 6
|
||||
17 3 632043
|
||||
15
codeforces/929/io/c.out
Normal file
15
codeforces/929/io/c.out
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
6
|
||||
1
|
||||
5
|
||||
12
|
||||
6
|
||||
11
|
||||
24
|
||||
4
|
||||
1
|
||||
3
|
||||
24
|
||||
|
||||
[code]: 0
|
||||
[time]: 5.31888 ms
|
||||
[debug]: false
|
||||
17
codeforces/929/io/d.in
Normal file
17
codeforces/929/io/d.in
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
8
|
||||
6
|
||||
1 2 3 4 5 6
|
||||
5
|
||||
3 3 3 3 3
|
||||
3
|
||||
2 2 3
|
||||
5
|
||||
1 1 2 3 7
|
||||
3
|
||||
1 2 2
|
||||
3
|
||||
1 1 2
|
||||
6
|
||||
5 2 10 10 10 2
|
||||
4
|
||||
3 6 9 3
|
||||
12
codeforces/929/io/d.out
Normal file
12
codeforces/929/io/d.out
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.24853 ms
|
||||
[debug]: false
|
||||
40
codeforces/929/io/e.in
Normal file
40
codeforces/929/io/e.in
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
5
|
||||
6
|
||||
3 1 4 1 5 9
|
||||
3
|
||||
1 8
|
||||
2 7
|
||||
5 9
|
||||
1
|
||||
10
|
||||
1
|
||||
1 1
|
||||
9
|
||||
5 10 9 6 8 3 10 7 3
|
||||
5
|
||||
8 56
|
||||
1 12
|
||||
9 3
|
||||
1 27
|
||||
5 45
|
||||
5
|
||||
7 9 2 5 2
|
||||
10
|
||||
1 37
|
||||
2 9
|
||||
3 33
|
||||
4 32
|
||||
4 15
|
||||
2 2
|
||||
4 2
|
||||
2 19
|
||||
3 7
|
||||
2 7
|
||||
10
|
||||
9 1 6 7 6 3 10 7 3 10
|
||||
5
|
||||
10 43
|
||||
3 23
|
||||
9 3
|
||||
6 8
|
||||
5 14
|
||||
9
codeforces/929/io/e.out
Normal file
9
codeforces/929/io/e.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
3 4 5
|
||||
1
|
||||
9 2 9 4 9
|
||||
5 2 5 5 5 2 4 5 4 2
|
||||
10 6 9 7 7
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.41303 ms
|
||||
[debug]: false
|
||||
31
codeforces/929/io/f.in
Normal file
31
codeforces/929/io/f.in
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
6
|
||||
4 5
|
||||
0 1 0 0 0
|
||||
0 0 1 0 0
|
||||
1 0 1 1 0
|
||||
0 0 0 0 0
|
||||
3 3
|
||||
0 0 0
|
||||
1 0 0
|
||||
0 0 0
|
||||
5 3
|
||||
0 0 0
|
||||
0 0 0
|
||||
1 0 0
|
||||
0 0 0
|
||||
1 0 0
|
||||
3 7
|
||||
0 0 1 0 0 1 0
|
||||
1 0 1 0 1 0 0
|
||||
0 1 0 0 0 0 0
|
||||
3 4
|
||||
0 1 0 0
|
||||
1 0 0 0
|
||||
0 1 1 0
|
||||
5 5
|
||||
0 0 0 0 0
|
||||
0 1 0 1 0
|
||||
0 1 0 1 0
|
||||
0 1 0 1 0
|
||||
0 0 0 1 0
|
||||
|
||||
10
codeforces/929/io/f.out
Normal file
10
codeforces/929/io/f.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
7
|
||||
3
|
||||
3
|
||||
8
|
||||
-1
|
||||
12
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.4085 ms
|
||||
[debug]: false
|
||||
30
codeforces/929/makefile
Normal file
30
codeforces/929/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/929/scripts/debug.sh
Normal file
29
codeforces/929/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/929/scripts/run.sh
Normal file
29
codeforces/929/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/929/scripts/utils.sh
Normal file
61
codeforces/929/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/946/.clang-format
Normal file
9
codeforces/946/.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
|
||||
37
codeforces/946/.clangd
Normal file
37
codeforces/946/.clangd
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
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
|
||||
91
codeforces/946/a.cc
Normal file
91
codeforces/946/a.cc
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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() {
|
||||
|
||||
}
|
||||
|
||||
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/946/compile_flags.txt
Normal file
31
codeforces/946/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
|
||||
14
codeforces/946/debug_flags.txt
Normal file
14
codeforces/946/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
|
||||
0
codeforces/946/io/a.in
Normal file
0
codeforces/946/io/a.in
Normal file
0
codeforces/946/io/a.out
Normal file
0
codeforces/946/io/a.out
Normal file
30
codeforces/946/makefile
Normal file
30
codeforces/946/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/946/scripts/debug.sh
Normal file
29
codeforces/946/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/946/scripts/run.sh
Normal file
29
codeforces/946/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/946/scripts/utils.sh
Normal file
61
codeforces/946/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/962/.clang-format
Normal file
9
codeforces/962/.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/962/.clangd
Normal file
41
codeforces/962/.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
|
||||
99
codeforces/962/a.cc
Normal file
99
codeforces/962/a.cc
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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;
|
||||
|
||||
u32 ans = n / 4;
|
||||
n -= ans * 4;
|
||||
|
||||
ans += n / 2;
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
103
codeforces/962/b.cc
Normal file
103
codeforces/962/b.cc
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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, k;
|
||||
cin >> n >> k;
|
||||
|
||||
vec<string> grid(n);
|
||||
for (auto& e : grid)
|
||||
cin >> e;
|
||||
|
||||
for (u32 i = 0; i < n; i += k) {
|
||||
for (u32 j = 0; j < n; j += k) {
|
||||
print("{}", grid[i][j]);
|
||||
}
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
120
codeforces/962/c.cc
Normal file
120
codeforces/962/c.cc
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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;
|
||||
|
||||
string a, b;
|
||||
cin >> a >> b;
|
||||
|
||||
vec<vec<u32>> fa(n + 1, vec<u32>(26, 0)), fb(n + 1, vec<u32>(26, 0));
|
||||
|
||||
for (u32 i = 1; i <= n; ++i) {
|
||||
fa[i] = fa[i - 1];
|
||||
++fa[i][a[i - 1] - 'a'];
|
||||
fb[i] = fb[i - 1];
|
||||
++fb[i][b[i - 1] - 'a'];
|
||||
}
|
||||
|
||||
u32 l, r;
|
||||
for (u32 i = 0; i < q; ++i) {
|
||||
cin >> l >> r;
|
||||
|
||||
u64 acc = 0;
|
||||
for (u32 j = 0; j < 26; ++j) {
|
||||
auto adiff = fa[r][j] - fa[l - 1][j];
|
||||
auto bdiff = fb[r][j] - fb[l - 1][j];
|
||||
|
||||
acc += max(adiff, bdiff) - min(adiff, bdiff);
|
||||
}
|
||||
|
||||
u64 ans = acc / 2;
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
31
codeforces/962/compile_flags.txt
Normal file
31
codeforces/962/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
|
||||
102
codeforces/962/d.cc
Normal file
102
codeforces/962/d.cc
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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() {
|
||||
i64 n, x;
|
||||
cin >> n >> x;
|
||||
|
||||
u64 ans = 0;
|
||||
for (i64 a = 1; a <= min(n, x); ++a) {
|
||||
for (i64 b = 1; a * b <= n && a + b < x; ++b) {
|
||||
i64 crange = min((n - a * b) / (a + b), x - a - b);
|
||||
ans += crange;
|
||||
}
|
||||
}
|
||||
|
||||
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/962/debug_flags.txt
Normal file
14
codeforces/962/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
|
||||
111
codeforces/962/e.cc
Normal file
111
codeforces/962/e.cc
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_ranges_enumerate
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
namespace rs = std::ranges;
|
||||
#endif
|
||||
|
||||
// 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
|
||||
// }}}
|
||||
|
||||
static constexpr size_t MOD = 1e9 + 7;
|
||||
|
||||
void solve() {
|
||||
string s;
|
||||
cin >> s;
|
||||
|
||||
u32 n = s.size();
|
||||
vec<i64> pref10(n + 1, 0);
|
||||
for (u32 i = 1; i <= n; ++i) {
|
||||
pref10[i] = pref10[i - 1] + (s[i - 1] == '1' ? 1 : -1);
|
||||
}
|
||||
map<i64, u64> cnt;
|
||||
cnt[0] = 1;
|
||||
|
||||
u64 ans = 0;
|
||||
|
||||
for (u32 y = 1; y <= n; ++y) {
|
||||
ans = (ans + cnt[pref10[y]] * (n - y + 1)) % MOD;
|
||||
cnt[pref10[y]] = (cnt[pref10[y]] + y + 1) % MOD;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
4
codeforces/962/io/a.in
Normal file
4
codeforces/962/io/a.in
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
3
|
||||
2
|
||||
6
|
||||
8
|
||||
7
codeforces/962/io/a.out
Normal file
7
codeforces/962/io/a.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
1
|
||||
2
|
||||
2
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.64907 ms
|
||||
[debug]: false
|
||||
29
codeforces/962/io/b.in
Normal file
29
codeforces/962/io/b.in
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
4
|
||||
4 4
|
||||
0000
|
||||
0000
|
||||
0000
|
||||
0000
|
||||
6 3
|
||||
000111
|
||||
000111
|
||||
000111
|
||||
111000
|
||||
111000
|
||||
111000
|
||||
6 2
|
||||
001100
|
||||
001100
|
||||
111111
|
||||
111111
|
||||
110000
|
||||
110000
|
||||
8 1
|
||||
11111111
|
||||
11111111
|
||||
11111111
|
||||
11111111
|
||||
11111111
|
||||
11111111
|
||||
11111111
|
||||
11111111
|
||||
18
codeforces/962/io/b.out
Normal file
18
codeforces/962/io/b.out
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
0
|
||||
01
|
||||
10
|
||||
010
|
||||
111
|
||||
100
|
||||
11111111
|
||||
11111111
|
||||
11111111
|
||||
11111111
|
||||
11111111
|
||||
11111111
|
||||
11111111
|
||||
11111111
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.57421 ms
|
||||
[debug]: false
|
||||
18
codeforces/962/io/c.in
Normal file
18
codeforces/962/io/c.in
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
3
|
||||
5 3
|
||||
abcde
|
||||
edcba
|
||||
1 5
|
||||
1 4
|
||||
3 3
|
||||
4 2
|
||||
zzde
|
||||
azbe
|
||||
1 3
|
||||
1 4
|
||||
6 3
|
||||
uwuwuw
|
||||
wuwuwu
|
||||
2 4
|
||||
1 3
|
||||
1 6
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue