last of div 4
This commit is contained in:
parent
1e18e29af4
commit
78ead22797
80 changed files with 2214 additions and 11 deletions
9
codeforces/784/.clang-format
Normal file
9
codeforces/784/.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
|
||||
47
codeforces/784/.clangd
Normal file
47
codeforces/784/.clangd
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
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++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
92
codeforces/784/a.cc
Normal file
92
codeforces/784/a.cc
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
#if __cplusplus >= 202002L
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
i32 rating;
|
||||
cin >> rating;
|
||||
|
||||
u32 division;
|
||||
|
||||
if (rating <= 1399) {
|
||||
division = 4;
|
||||
} else if (rating <= 1599) {
|
||||
division = 3;
|
||||
} else if (rating <= 1899) {
|
||||
division = 2;
|
||||
} else {
|
||||
division = 1;
|
||||
}
|
||||
|
||||
println("Division {}", division);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
92
codeforces/784/b.cc
Normal file
92
codeforces/784/b.cc
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
#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), f(n + 1);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
for (auto e : a)
|
||||
f[e]++;
|
||||
|
||||
for (u32 i = 1; i <= n; ++i) {
|
||||
if (f[i] >= 3) {
|
||||
println("{}", i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
println("-1");
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
u32 tc = 1;
|
||||
cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
96
codeforces/784/c.cc
Normal file
96
codeforces/784/c.cc
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
#if __cplusplus >= 202002L
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
u32 n;
|
||||
cin >> n;
|
||||
|
||||
vec<u32> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
for (u32 i = 1; i < n; i += 2) {
|
||||
if ((a[i] & 1) != (a[1] & 1)) {
|
||||
NO();
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (u32 i = 0; i < n; i += 2) {
|
||||
if ((a[i] & 1) != (a[0] & 1)) {
|
||||
NO();
|
||||
return;
|
||||
}
|
||||
}
|
||||
YES();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
u32 tc = 1;
|
||||
cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
31
codeforces/784/compile_flags.txt
Normal file
31
codeforces/784/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/784/d.cc
Normal file
103
codeforces/784/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;
|
||||
cin >> n;
|
||||
string s;
|
||||
cin >> s;
|
||||
istringstream ss{s};
|
||||
|
||||
string word;
|
||||
|
||||
while (getline(ss, word, 'W')) {
|
||||
if (word.size() == 0)
|
||||
continue;
|
||||
|
||||
u32 R = 0, B = 0;
|
||||
for (auto c : word) {
|
||||
if (c == 'R')
|
||||
++R;
|
||||
if (c == 'B')
|
||||
++B;
|
||||
}
|
||||
|
||||
if (!(R > 0 && B > 0)) {
|
||||
NO();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
YES();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
u32 tc = 1;
|
||||
cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
14
codeforces/784/debug_flags.txt
Normal file
14
codeforces/784/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
|
||||
100
codeforces/784/e.cc
Normal file
100
codeforces/784/e.cc
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
#if __cplusplus >= 202002L
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
u32 n;
|
||||
cin >> n;
|
||||
|
||||
vec<string> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
u64 ans = 0;
|
||||
|
||||
unordered_map<char, unordered_map<char, u32>> f;
|
||||
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
for (char c = 'a'; c <= 'k'; ++c) {
|
||||
if (c != a[i][0])
|
||||
ans += f[c][a[i][1]];
|
||||
if (c != a[i][1]) {
|
||||
ans += f[a[i][0]][c];
|
||||
}
|
||||
}
|
||||
|
||||
f[a[i][0]][a[i][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;
|
||||
}
|
||||
// }}}
|
||||
101
codeforces/784/f.cc
Normal file
101
codeforces/784/f.cc
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
#if __cplusplus >= 202002L
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
i32 n;
|
||||
cin >> n;
|
||||
|
||||
vec<u64> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
i32 ans = 0;
|
||||
|
||||
u64 left = 0, right = 0;
|
||||
i32 l = 0, r = n - 1;
|
||||
|
||||
while (l <= r) {
|
||||
if (left <= right) {
|
||||
left += a[l++];
|
||||
} else {
|
||||
right += a[r--];
|
||||
}
|
||||
|
||||
if (left == right) {
|
||||
ans = max(ans, l + n - r - 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;
|
||||
}
|
||||
// }}}
|
||||
107
codeforces/784/g.cc
Normal file
107
codeforces/784/g.cc
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
#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> grid(n);
|
||||
for (auto& e : grid)
|
||||
cin >> e;
|
||||
|
||||
vec<string> ans(n, string(m, '.'));
|
||||
|
||||
for (u32 column = 0; column < m; ++column) {
|
||||
i32 write = n - 1;
|
||||
for (i32 row = n - 1; row >= 0; --row) {
|
||||
if (grid[row][column] == '.')
|
||||
continue;
|
||||
|
||||
if (grid[row][column] == 'o') {
|
||||
ans[row][column] = 'o';
|
||||
write = row - 1;
|
||||
}
|
||||
|
||||
if (grid[row][column] == '*') {
|
||||
ans[write][column] = '*';
|
||||
--write;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& e : ans) {
|
||||
println("{}", e);
|
||||
}
|
||||
println();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
102
codeforces/784/h.cc
Normal file
102
codeforces/784/h.cc
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
#if __cplusplus >= 202002L
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
i32 n;
|
||||
cin >> n;
|
||||
i64 k;
|
||||
cin >> k;
|
||||
|
||||
vec<u32> bit_count(31, 0);
|
||||
vec<u32> a(n);
|
||||
|
||||
for (auto& e : a) {
|
||||
cin >> e;
|
||||
for (u32 shift = 0; shift <= 30; ++shift) {
|
||||
bit_count[shift] += bool(e & (1 << shift));
|
||||
}
|
||||
}
|
||||
|
||||
u32 ans = 0;
|
||||
for (i32 shift = 30; shift >= 0; --shift) {
|
||||
i32 cost = n - bit_count[shift];
|
||||
|
||||
if (cost <= k) {
|
||||
k -= cost;
|
||||
ans |= 1 << shift;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
8
codeforces/784/io/a.in
Normal file
8
codeforces/784/io/a.in
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
7
|
||||
-789
|
||||
1299
|
||||
1300
|
||||
1399
|
||||
1400
|
||||
1679
|
||||
2300
|
||||
10
codeforces/784/io/a.out
Normal file
10
codeforces/784/io/a.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
Division 4
|
||||
Division 4
|
||||
Division 4
|
||||
Division 4
|
||||
Division 3
|
||||
Division 2
|
||||
Division 1
|
||||
|
||||
[code]: 0
|
||||
[time]: 5.79357 ms
|
||||
15
codeforces/784/io/b.in
Normal file
15
codeforces/784/io/b.in
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
7
|
||||
1
|
||||
1
|
||||
3
|
||||
2 2 2
|
||||
7
|
||||
2 2 3 3 4 2 2
|
||||
8
|
||||
1 4 3 4 3 2 4 1
|
||||
9
|
||||
1 1 1 2 2 2 3 3 3
|
||||
5
|
||||
1 5 2 4 3
|
||||
4
|
||||
4 4 4 4
|
||||
10
codeforces/784/io/b.out
Normal file
10
codeforces/784/io/b.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
-1
|
||||
2
|
||||
2
|
||||
4
|
||||
1
|
||||
-1
|
||||
4
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.40207 ms
|
||||
9
codeforces/784/io/c.in
Normal file
9
codeforces/784/io/c.in
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
4
|
||||
3
|
||||
1 2 1
|
||||
4
|
||||
2 2 2 3
|
||||
4
|
||||
2 2 2 2
|
||||
5
|
||||
1000 1 1000 1 1000
|
||||
7
codeforces/784/io/c.out
Normal file
7
codeforces/784/io/c.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
YES
|
||||
NO
|
||||
YES
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 6.10971 ms
|
||||
25
codeforces/784/io/d.in
Normal file
25
codeforces/784/io/d.in
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
12
|
||||
5
|
||||
BRBBW
|
||||
1
|
||||
B
|
||||
2
|
||||
WB
|
||||
2
|
||||
RW
|
||||
3
|
||||
BRB
|
||||
3
|
||||
RBB
|
||||
7
|
||||
WWWWWWW
|
||||
9
|
||||
RBWBWRRBW
|
||||
10
|
||||
BRBRBRBRRB
|
||||
12
|
||||
BBBRWWRRRWBR
|
||||
10
|
||||
BRBRBRBRBW
|
||||
5
|
||||
RBWBW
|
||||
15
codeforces/784/io/d.out
Normal file
15
codeforces/784/io/d.out
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
YES
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
YES
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.47884 ms
|
||||
27
codeforces/784/io/e.in
Normal file
27
codeforces/784/io/e.in
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
4
|
||||
6
|
||||
ab
|
||||
cb
|
||||
db
|
||||
aa
|
||||
cc
|
||||
ef
|
||||
7
|
||||
aa
|
||||
bb
|
||||
cc
|
||||
ac
|
||||
ca
|
||||
bb
|
||||
aa
|
||||
4
|
||||
kk
|
||||
kk
|
||||
ab
|
||||
ab
|
||||
5
|
||||
jf
|
||||
jf
|
||||
jk
|
||||
jk
|
||||
jk
|
||||
8
codeforces/784/io/e.out
Normal file
8
codeforces/784/io/e.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
5
|
||||
6
|
||||
0
|
||||
6
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.33087 ms
|
||||
[time]: 2.47264 ms
|
||||
9
codeforces/784/io/f.in
Normal file
9
codeforces/784/io/f.in
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
4
|
||||
3
|
||||
10 20 10
|
||||
6
|
||||
2 1 4 2 4 1
|
||||
5
|
||||
1 2 4 8 16
|
||||
9
|
||||
7 3 20 5 15 1 11 8 10
|
||||
7
codeforces/784/io/f.out
Normal file
7
codeforces/784/io/f.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
2
|
||||
6
|
||||
0
|
||||
7
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.23374 ms
|
||||
17
codeforces/784/io/g.in
Normal file
17
codeforces/784/io/g.in
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
3
|
||||
6 10
|
||||
.*.*....*.
|
||||
.*.......*
|
||||
...o....o.
|
||||
.*.*....*.
|
||||
..........
|
||||
.o......o*
|
||||
2 9
|
||||
...***ooo
|
||||
.*o.*o.*o
|
||||
5 5
|
||||
*****
|
||||
*....
|
||||
*****
|
||||
....*
|
||||
*****
|
||||
19
codeforces/784/io/g.out
Normal file
19
codeforces/784/io/g.out
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
..........
|
||||
...*....*.
|
||||
.*.o....o.
|
||||
.*........
|
||||
.*......**
|
||||
.o.*....o*
|
||||
|
||||
....**ooo
|
||||
.*o**o.*o
|
||||
|
||||
.....
|
||||
*...*
|
||||
*****
|
||||
*****
|
||||
*****
|
||||
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.32959 ms
|
||||
9
codeforces/784/io/h.in
Normal file
9
codeforces/784/io/h.in
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
4
|
||||
3 2
|
||||
2 1 1
|
||||
7 0
|
||||
4 6 6 28 6 6 12
|
||||
1 30
|
||||
0
|
||||
4 4
|
||||
3 1 3 1
|
||||
7
codeforces/784/io/h.out
Normal file
7
codeforces/784/io/h.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
2
|
||||
4
|
||||
2147483646
|
||||
1073741825
|
||||
|
||||
[code]: 0
|
||||
[time]: 3.09849 ms
|
||||
30
codeforces/784/makefile
Normal file
30
codeforces/784/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/784/scripts/debug.sh
Normal file
29
codeforces/784/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"
|
||||
exit $?
|
||||
29
codeforces/784/scripts/run.sh
Normal file
29
codeforces/784/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 $?
|
||||
53
codeforces/784/scripts/utils.sh
Normal file
53
codeforces/784/scripts/utils.sh
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#!/bin/sh
|
||||
|
||||
execute_binary() {
|
||||
binary="$1"
|
||||
input="$2"
|
||||
output="$3"
|
||||
|
||||
start=$(date '+%s.%N')
|
||||
timeout 2s ./"$binary" <"$input" >"$output" 2>&1
|
||||
CODE=$?
|
||||
end=$(date '+%s.%N')
|
||||
truncate -s "$(head -n 1000 "$output" | wc -c)" "$output"
|
||||
|
||||
if [ $CODE -ge 124 ]; then
|
||||
MSG=''
|
||||
case $CODE in
|
||||
124) MSG='TIMEOUT' ;;
|
||||
128) MSG='SIGILL' ;;
|
||||
130) MSG='SIGABRT' ;;
|
||||
131) MSG='SIGBUS' ;;
|
||||
136) MSG='SIGFPE' ;;
|
||||
135) MSG='SIGSEGV' ;;
|
||||
137) MSG='SIGPIPE' ;;
|
||||
139) MSG='SIGTERM' ;;
|
||||
esac
|
||||
[ $CODE -ne 124 ] && sed -i '$d' "$output"
|
||||
test -n "$MSG" && printf '\n[code]: %s (%s)' "$CODE" "$MSG" >>"$output"
|
||||
else
|
||||
printf '\n[code]: %s' "$CODE" >>"$output"
|
||||
fi
|
||||
|
||||
printf '\n[time]: %s ms' "$(awk "BEGIN {print ($end - $start) * 1000}")" >>$output
|
||||
return $CODE
|
||||
}
|
||||
|
||||
compile_source() {
|
||||
src="$1"
|
||||
bin="$2"
|
||||
output="$3"
|
||||
flags="$4"
|
||||
|
||||
test -f "$bin" && rm "$bin" || true
|
||||
g++ @compile_flags.txt $flags "$src" -o "$bin" 2>"$output"
|
||||
CODE=$?
|
||||
|
||||
if [ $CODE -gt 0 ]; then
|
||||
printf '\n[code]: %s' "$CODE" >>"$output"
|
||||
return $CODE
|
||||
else
|
||||
echo '' >"$output"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue