790
This commit is contained in:
parent
8a3884da87
commit
1b90a3d039
32 changed files with 1214 additions and 0 deletions
9
codeforces/790/.clang-format
Normal file
9
codeforces/790/.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/790/.clangd
Normal file
41
codeforces/790/.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
|
||||||
90
codeforces/790/a.cc
Normal file
90
codeforces/790/a.cc
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using f64 = double;
|
||||||
|
using f128 = long double;
|
||||||
|
|
||||||
|
#if __cplusplus >= 202002L
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::max();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sc(auto&& x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sz(auto&& x) {
|
||||||
|
return static_cast<T>(x.size());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void NO() {
|
||||||
|
std::cout << "NO\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void YES() {
|
||||||
|
std::cout << "YES\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using vec = std::vector<T>;
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (x).rbegin(), (x).rend()
|
||||||
|
#define ff first
|
||||||
|
#define ss second
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
#define db(...) std::print(__VA_ARGS__)
|
||||||
|
#define dbln(...) std::println(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define db(...)
|
||||||
|
#define dbln(...)
|
||||||
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
u32 n;
|
||||||
|
cin >> n;
|
||||||
|
|
||||||
|
u32 right = n % 1000;
|
||||||
|
u32 left = n / 1000;
|
||||||
|
|
||||||
|
u32 left_sum = (left % 10) + (left / 10 % 10) + (left / 100 % 10);
|
||||||
|
u32 right_sum = (right % 10) + (right / 10 % 10) + (right / 100 % 10);
|
||||||
|
|
||||||
|
if (left_sum == right_sum) {
|
||||||
|
YES();
|
||||||
|
} else {
|
||||||
|
NO();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
u32 tc = 1;
|
||||||
|
cin >> tc;
|
||||||
|
|
||||||
|
for (u32 t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
89
codeforces/790/b.cc
Normal file
89
codeforces/790/b.cc
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using f64 = double;
|
||||||
|
using f128 = long double;
|
||||||
|
|
||||||
|
#if __cplusplus >= 202002L
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::max();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sc(auto&& x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sz(auto&& x) {
|
||||||
|
return static_cast<T>(x.size());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void NO() {
|
||||||
|
std::cout << "NO\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void YES() {
|
||||||
|
std::cout << "YES\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using vec = std::vector<T>;
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (x).rbegin(), (x).rend()
|
||||||
|
#define ff first
|
||||||
|
#define ss second
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
#define db(...) std::print(__VA_ARGS__)
|
||||||
|
#define dbln(...) std::println(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define db(...)
|
||||||
|
#define dbln(...)
|
||||||
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
u32 n;
|
||||||
|
cin >> n;
|
||||||
|
vec<u32> a(n);
|
||||||
|
for (auto& e : a)
|
||||||
|
cin >> e;
|
||||||
|
|
||||||
|
auto small = *min_element(all(a));
|
||||||
|
u32 ans = 0;
|
||||||
|
for (auto e : a) {
|
||||||
|
ans += e - small;
|
||||||
|
}
|
||||||
|
|
||||||
|
println("{}", ans);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
u32 tc = 1;
|
||||||
|
cin >> tc;
|
||||||
|
|
||||||
|
for (u32 t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
98
codeforces/790/c.cc
Normal file
98
codeforces/790/c.cc
Normal file
|
|
@ -0,0 +1,98 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using f64 = double;
|
||||||
|
using f128 = long double;
|
||||||
|
|
||||||
|
#if __cplusplus >= 202002L
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::max();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sc(auto&& x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sz(auto&& x) {
|
||||||
|
return static_cast<T>(x.size());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void NO() {
|
||||||
|
std::cout << "NO\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void YES() {
|
||||||
|
std::cout << "YES\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using vec = std::vector<T>;
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (x).rbegin(), (x).rend()
|
||||||
|
#define ff first
|
||||||
|
#define ss second
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
#define db(...) std::print(__VA_ARGS__)
|
||||||
|
#define dbln(...) std::println(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define db(...)
|
||||||
|
#define dbln(...)
|
||||||
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
u32 n, m;
|
||||||
|
cin >> n >> m;
|
||||||
|
|
||||||
|
vec<string> words(n);
|
||||||
|
for (auto& e : words)
|
||||||
|
cin >> e;
|
||||||
|
|
||||||
|
u32 ans = 1e6;
|
||||||
|
|
||||||
|
for (u32 i = 0; i < n; ++i) {
|
||||||
|
for (u32 j = i + 1; j < n; ++j) {
|
||||||
|
u32 diff = 0;
|
||||||
|
|
||||||
|
for (u32 k = 0; k < m; ++k) {
|
||||||
|
diff += max(words[i][k], words[j][k]) - min(words[i][k], words[j][k]);
|
||||||
|
}
|
||||||
|
|
||||||
|
ans = min(ans, diff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println("{}", ans);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
u32 tc = 1;
|
||||||
|
cin >> tc;
|
||||||
|
|
||||||
|
for (u32 t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
31
codeforces/790/compile_flags.txt
Normal file
31
codeforces/790/compile_flags.txt
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
-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
|
||||||
|
-std=c++23
|
||||||
103
codeforces/790/d.cc
Normal file
103
codeforces/790/d.cc
Normal file
|
|
@ -0,0 +1,103 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using f64 = double;
|
||||||
|
using f128 = long double;
|
||||||
|
|
||||||
|
#if __cplusplus >= 202002L
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::max();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sc(auto&& x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sz(auto&& x) {
|
||||||
|
return static_cast<T>(x.size());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void NO() {
|
||||||
|
std::cout << "NO\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void YES() {
|
||||||
|
std::cout << "YES\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using vec = std::vector<T>;
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (x).rbegin(), (x).rend()
|
||||||
|
#define ff first
|
||||||
|
#define ss second
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
#define db(...) std::print(__VA_ARGS__)
|
||||||
|
#define dbln(...) std::println(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define db(...)
|
||||||
|
#define dbln(...)
|
||||||
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
u32 n, m;
|
||||||
|
cin >> n >> m;
|
||||||
|
vec<vec<u32>> grid(n, vec<u32>(m));
|
||||||
|
for (auto& row : grid)
|
||||||
|
for (auto& cell : row)
|
||||||
|
cin >> cell;
|
||||||
|
|
||||||
|
vec<u64> diag1(n + m - 1, 0);
|
||||||
|
vec<u64> diag2(n + m - 1, 0);
|
||||||
|
|
||||||
|
for (u32 i = 0; i < n; ++i) {
|
||||||
|
for (u32 j = 0; j < m; ++j) {
|
||||||
|
diag1[i + j] += grid[i][j];
|
||||||
|
diag2[i - j + m - 1] += grid[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 ans = 0;
|
||||||
|
|
||||||
|
for (u32 i = 0; i < n; ++i) {
|
||||||
|
for (u32 j = 0; j < m; ++j) {
|
||||||
|
u64 score = diag1[i + j] + diag2[i - j + m - 1] - grid[i][j];
|
||||||
|
ans = max(ans, score);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println("{}", ans);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
u32 tc = 1;
|
||||||
|
cin >> tc;
|
||||||
|
|
||||||
|
for (u32 t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
14
codeforces/790/debug_flags.txt
Normal file
14
codeforces/790/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
|
||||||
105
codeforces/790/e.cc
Normal file
105
codeforces/790/e.cc
Normal file
|
|
@ -0,0 +1,105 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using f64 = double;
|
||||||
|
using f128 = long double;
|
||||||
|
|
||||||
|
#if __cplusplus >= 202002L
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::max();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sc(auto&& x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sz(auto&& x) {
|
||||||
|
return static_cast<T>(x.size());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void NO() {
|
||||||
|
std::cout << "NO\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void YES() {
|
||||||
|
std::cout << "YES\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using vec = std::vector<T>;
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (x).rbegin(), (x).rend()
|
||||||
|
#define ff first
|
||||||
|
#define ss second
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
#define db(...) std::print(__VA_ARGS__)
|
||||||
|
#define dbln(...) std::println(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define db(...)
|
||||||
|
#define dbln(...)
|
||||||
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
u32 n, q;
|
||||||
|
cin >> n >> q;
|
||||||
|
|
||||||
|
vec<u64> a(n);
|
||||||
|
for (auto& e : a)
|
||||||
|
cin >> e;
|
||||||
|
|
||||||
|
sort(rall(a));
|
||||||
|
|
||||||
|
vec<u64> prefix(n + 1, 0);
|
||||||
|
for (u32 i = 1; i <= n; ++i) {
|
||||||
|
prefix[i] = prefix[i - 1] + a[i - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 k;
|
||||||
|
for (u32 i = 0; i < q; ++i) {
|
||||||
|
cin >> k;
|
||||||
|
|
||||||
|
auto it = lower_bound(all(prefix), k);
|
||||||
|
|
||||||
|
i32 ans;
|
||||||
|
if (it == prefix.end()) {
|
||||||
|
ans = -1;
|
||||||
|
} else {
|
||||||
|
ans = distance(prefix.begin(), it);
|
||||||
|
}
|
||||||
|
|
||||||
|
println("{}", ans);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
u32 tc = 1;
|
||||||
|
cin >> tc;
|
||||||
|
|
||||||
|
for (u32 t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
119
codeforces/790/f.cc
Normal file
119
codeforces/790/f.cc
Normal file
|
|
@ -0,0 +1,119 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using f64 = double;
|
||||||
|
using f128 = long double;
|
||||||
|
|
||||||
|
#if __cplusplus >= 202002L
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::max();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sc(auto&& x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sz(auto&& x) {
|
||||||
|
return static_cast<T>(x.size());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void NO() {
|
||||||
|
std::cout << "NO\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void YES() {
|
||||||
|
std::cout << "YES\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using vec = std::vector<T>;
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (x).rbegin(), (x).rend()
|
||||||
|
#define ff first
|
||||||
|
#define ss second
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
#define db(...) std::print(__VA_ARGS__)
|
||||||
|
#define dbln(...) std::println(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define db(...)
|
||||||
|
#define dbln(...)
|
||||||
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
u32 n, k;
|
||||||
|
cin >> n >> k;
|
||||||
|
|
||||||
|
vec<u64> a(n);
|
||||||
|
map<u64, u32> f;
|
||||||
|
for (auto& e : a) {
|
||||||
|
cin >> e;
|
||||||
|
++f[e];
|
||||||
|
}
|
||||||
|
|
||||||
|
vec<u64> candidates;
|
||||||
|
for (auto [number, frequency] : f) {
|
||||||
|
if (frequency >= k) {
|
||||||
|
candidates.push_back(number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sort(all(candidates));
|
||||||
|
|
||||||
|
u32 streak = 0;
|
||||||
|
u32 l, r, L, R;
|
||||||
|
u32 i = 0;
|
||||||
|
while (i < candidates.size()) {
|
||||||
|
l = i, r = i;
|
||||||
|
while (r + 1 < candidates.size() &&
|
||||||
|
candidates[r] + 1 == candidates[r + 1]) {
|
||||||
|
++r;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r - l + 1 > streak) {
|
||||||
|
streak = r - l + 1;
|
||||||
|
L = candidates[l];
|
||||||
|
R = candidates[r];
|
||||||
|
}
|
||||||
|
|
||||||
|
i = r + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (streak == 0) {
|
||||||
|
println("-1");
|
||||||
|
} else {
|
||||||
|
println("{} {}", L, R);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
u32 tc = 1;
|
||||||
|
cin >> tc;
|
||||||
|
|
||||||
|
for (u32 t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
116
codeforces/790/g.cc
Normal file
116
codeforces/790/g.cc
Normal file
|
|
@ -0,0 +1,116 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using f64 = double;
|
||||||
|
using f128 = long double;
|
||||||
|
|
||||||
|
#if __cplusplus >= 202002L
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::max();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sc(auto&& x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sz(auto&& x) {
|
||||||
|
return static_cast<T>(x.size());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void NO() {
|
||||||
|
std::cout << "NO\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void YES() {
|
||||||
|
std::cout << "YES\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using vec = std::vector<T>;
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (x).rbegin(), (x).rend()
|
||||||
|
#define ff first
|
||||||
|
#define ss second
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
#define db(...) std::print(__VA_ARGS__)
|
||||||
|
#define dbln(...) std::println(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define db(...)
|
||||||
|
#define dbln(...)
|
||||||
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
u32 n;
|
||||||
|
cin >> n;
|
||||||
|
|
||||||
|
vec<vec<u32>> tree(n + 1);
|
||||||
|
u32 parent;
|
||||||
|
for (u32 i = 1; i <= n - 1; ++i) {
|
||||||
|
cin >> parent;
|
||||||
|
tree[parent].push_back(i + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
string coloring;
|
||||||
|
cin >> coloring;
|
||||||
|
|
||||||
|
u32 ans = 0;
|
||||||
|
|
||||||
|
vec<u32> black(n + 1, 0), white(n + 1, 0);
|
||||||
|
|
||||||
|
auto dfs = [&](auto&& self, u32 u, u32 par) -> void {
|
||||||
|
white[u] = coloring[u - 1] == 'W';
|
||||||
|
black[u] = coloring[u - 1] == 'B';
|
||||||
|
|
||||||
|
for (auto v : tree[u]) {
|
||||||
|
if (v == par)
|
||||||
|
continue;
|
||||||
|
self(self, v, u);
|
||||||
|
|
||||||
|
white[u] += white[v];
|
||||||
|
black[u] += black[v];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (white[u] == black[u]) {
|
||||||
|
++ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
dfs(dfs, 1, 1);
|
||||||
|
|
||||||
|
println("{}", ans);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
u32 tc = 1;
|
||||||
|
cin >> tc;
|
||||||
|
|
||||||
|
for (u32 t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
80
codeforces/790/h.cc
Normal file
80
codeforces/790/h.cc
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using f64 = double;
|
||||||
|
using f128 = long double;
|
||||||
|
|
||||||
|
#if __cplusplus >= 202002L
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::max();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sc(auto&& x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sz(auto&& x) {
|
||||||
|
return static_cast<T>(x.size());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void NO() {
|
||||||
|
std::cout << "NO\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void YES() {
|
||||||
|
std::cout << "YES\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
using vec = std::vector<T>;
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (x).rbegin(), (x).rend()
|
||||||
|
#define ff first
|
||||||
|
#define ss second
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
#define db(...) std::print(__VA_ARGS__)
|
||||||
|
#define dbln(...) std::println(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define db(...)
|
||||||
|
#define dbln(...)
|
||||||
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
u32 n;
|
||||||
|
cin >> n;
|
||||||
|
vec<u32> a(n);
|
||||||
|
for (auto& e : a)cin >> e;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
u32 tc = 1;
|
||||||
|
cin >> tc;
|
||||||
|
|
||||||
|
for (u32 t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
6
codeforces/790/io/a.in
Normal file
6
codeforces/790/io/a.in
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
5
|
||||||
|
213132
|
||||||
|
973894
|
||||||
|
045207
|
||||||
|
000000
|
||||||
|
055776
|
||||||
14
codeforces/790/io/a.out
Normal file
14
codeforces/790/io/a.out
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
YES
|
||||||
|
NO
|
||||||
|
YES
|
||||||
|
YES
|
||||||
|
NO
|
||||||
|
213 132
|
||||||
|
973 894
|
||||||
|
45 207
|
||||||
|
0 0
|
||||||
|
55 776
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 8.57687 ms
|
||||||
|
[debug]: false
|
||||||
12
codeforces/790/io/b.in
Normal file
12
codeforces/790/io/b.in
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
5
|
||||||
|
5
|
||||||
|
1 2 3 4 5
|
||||||
|
6
|
||||||
|
1000 1000 5 1000 1000 1000
|
||||||
|
10
|
||||||
|
1 2 3 5 1 2 7 9 13 5
|
||||||
|
3
|
||||||
|
8 8 8
|
||||||
|
1
|
||||||
|
10000000
|
||||||
|
|
||||||
9
codeforces/790/io/b.out
Normal file
9
codeforces/790/io/b.out
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
10
|
||||||
|
4975
|
||||||
|
38
|
||||||
|
0
|
||||||
|
0
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 9.69386 ms
|
||||||
|
[debug]: false
|
||||||
25
codeforces/790/io/c.in
Normal file
25
codeforces/790/io/c.in
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
6
|
||||||
|
2 4
|
||||||
|
best
|
||||||
|
cost
|
||||||
|
6 3
|
||||||
|
abb
|
||||||
|
zba
|
||||||
|
bef
|
||||||
|
cdu
|
||||||
|
ooo
|
||||||
|
zzz
|
||||||
|
2 7
|
||||||
|
aaabbbc
|
||||||
|
bbaezfe
|
||||||
|
3 2
|
||||||
|
ab
|
||||||
|
ab
|
||||||
|
ab
|
||||||
|
2 8
|
||||||
|
aaaaaaaa
|
||||||
|
zzzzzzzz
|
||||||
|
3 1
|
||||||
|
a
|
||||||
|
u
|
||||||
|
y
|
||||||
10
codeforces/790/io/c.out
Normal file
10
codeforces/790/io/c.out
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
11
|
||||||
|
8
|
||||||
|
35
|
||||||
|
0
|
||||||
|
200
|
||||||
|
4
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 6.47712 ms
|
||||||
|
[debug]: false
|
||||||
17
codeforces/790/io/d.in
Normal file
17
codeforces/790/io/d.in
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
4
|
||||||
|
4 4
|
||||||
|
1 2 2 1
|
||||||
|
2 4 2 4
|
||||||
|
2 2 3 1
|
||||||
|
2 4 2 4
|
||||||
|
2 1
|
||||||
|
1
|
||||||
|
0
|
||||||
|
3 3
|
||||||
|
1 1 1
|
||||||
|
1 1 1
|
||||||
|
1 1 1
|
||||||
|
3 3
|
||||||
|
0 1 1
|
||||||
|
1 0 1
|
||||||
|
1 1 0
|
||||||
8
codeforces/790/io/d.out
Normal file
8
codeforces/790/io/d.out
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
20
|
||||||
|
1
|
||||||
|
5
|
||||||
|
3
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 2.32363 ms
|
||||||
|
[debug]: false
|
||||||
17
codeforces/790/io/e.in
Normal file
17
codeforces/790/io/e.in
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
3
|
||||||
|
8 7
|
||||||
|
4 3 3 1 1 4 5 9
|
||||||
|
1
|
||||||
|
10
|
||||||
|
50
|
||||||
|
14
|
||||||
|
15
|
||||||
|
22
|
||||||
|
30
|
||||||
|
4 1
|
||||||
|
1 2 3 4
|
||||||
|
3
|
||||||
|
1 2
|
||||||
|
5
|
||||||
|
4
|
||||||
|
6
|
||||||
14
codeforces/790/io/e.out
Normal file
14
codeforces/790/io/e.out
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
1
|
||||||
|
2
|
||||||
|
-1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
8
|
||||||
|
1
|
||||||
|
1
|
||||||
|
-1
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 2.58231 ms
|
||||||
|
[debug]: false
|
||||||
9
codeforces/790/io/f.in
Normal file
9
codeforces/790/io/f.in
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
4
|
||||||
|
7 2
|
||||||
|
11 11 12 13 13 14 14
|
||||||
|
5 1
|
||||||
|
6 3 5 2 1
|
||||||
|
6 4
|
||||||
|
4 3 4 3 3 4
|
||||||
|
14 2
|
||||||
|
1 1 2 2 2 3 3 3 3 4 4 4 4 4
|
||||||
12
codeforces/790/io/f.out
Normal file
12
codeforces/790/io/f.out
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
11 13 14
|
||||||
|
13 14
|
||||||
|
1 2 3 5 6
|
||||||
|
1 3
|
||||||
|
|
||||||
|
-1
|
||||||
|
1 2 3 4
|
||||||
|
1 4
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 2.43974 ms
|
||||||
|
[debug]: false
|
||||||
10
codeforces/790/io/g.in
Normal file
10
codeforces/790/io/g.in
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
3
|
||||||
|
7
|
||||||
|
1 1 2 3 3 5
|
||||||
|
WBBWWBW
|
||||||
|
2
|
||||||
|
1
|
||||||
|
BW
|
||||||
|
8
|
||||||
|
1 2 3 4 5 6 7
|
||||||
|
BWBWBWBW
|
||||||
7
codeforces/790/io/g.out
Normal file
7
codeforces/790/io/g.out
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
2
|
||||||
|
1
|
||||||
|
4
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 2.36297 ms
|
||||||
|
[debug]: false
|
||||||
0
codeforces/790/io/h.in
Normal file
0
codeforces/790/io/h.in
Normal file
0
codeforces/790/io/h.out
Normal file
0
codeforces/790/io/h.out
Normal file
30
codeforces/790/makefile
Normal file
30
codeforces/790/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/790/scripts/debug.sh
Normal file
29
codeforces/790/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/790/scripts/run.sh
Normal file
29
codeforces/790/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/790/scripts/utils.sh
Normal file
61
codeforces/790/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
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue