codeforces: 1003
This commit is contained in:
parent
7440bc2937
commit
d1b961e1c4
60 changed files with 2235 additions and 0 deletions
9
codeforces/1003/.clang-format
Normal file
9
codeforces/1003/.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
|
||||
8
codeforces/1003/.clangd
Normal file
8
codeforces/1003/.clangd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
- -std=c++23
|
||||
- -Wall
|
||||
- -Wextra
|
||||
- -Wpedantic
|
||||
- -Wshadow
|
||||
- -Wno-unknown-pragmas
|
||||
79
codeforces/1003/a.cc
Normal file
79
codeforces/1003/a.cc
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
// {{{
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args> void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args> void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
void prln() { std::println(); }
|
||||
|
||||
void prln(auto const &t) { std::println("{}", t); }
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T> using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
string s;
|
||||
cin >> s;
|
||||
for (int i = 0; i < s.size() - 2; ++i) {
|
||||
cout << s[i];
|
||||
}
|
||||
cout << "i\n";
|
||||
}
|
||||
|
||||
// {{{
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
10
codeforces/1003/a.in
Normal file
10
codeforces/1003/a.in
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
9
|
||||
us
|
||||
sus
|
||||
fungus
|
||||
cactus
|
||||
sussus
|
||||
amogus
|
||||
chungus
|
||||
ntarsus
|
||||
skibidus
|
||||
12
codeforces/1003/a.out
Normal file
12
codeforces/1003/a.out
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
i
|
||||
si
|
||||
fungi
|
||||
cacti
|
||||
sussi
|
||||
amogi
|
||||
chungi
|
||||
ntarsi
|
||||
skibidi
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.63152 ms
|
||||
102
codeforces/1003/b.cc
Normal file
102
codeforces/1003/b.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;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
void prln() {
|
||||
std::println();
|
||||
}
|
||||
|
||||
void prln(auto const& t) {
|
||||
std::println("{}", t);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
string s;
|
||||
cin >> s;
|
||||
vec<char> S;
|
||||
for (auto e : s) {
|
||||
if (!S.empty() && S.back() == e) {
|
||||
S.pop_back();
|
||||
S.push_back('*');
|
||||
} else
|
||||
S.push_back(e);
|
||||
}
|
||||
|
||||
while (sz<int>(S) >= 2) {
|
||||
if (S.back() == '*' || S[sz<int>(S) - 1] == '*')
|
||||
S.pop_back();
|
||||
else
|
||||
break;
|
||||
}
|
||||
prln("{}", sz<int>(S));
|
||||
}
|
||||
|
||||
// {{{
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
5
codeforces/1003/b.in
Normal file
5
codeforces/1003/b.in
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
4
|
||||
baa
|
||||
skibidus
|
||||
cc
|
||||
ohio
|
||||
7
codeforces/1003/b.out
Normal file
7
codeforces/1003/b.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
1
|
||||
8
|
||||
1
|
||||
4
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.9956 ms
|
||||
106
codeforces/1003/c.cc
Normal file
106
codeforces/1003/c.cc
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
// {{{
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
void prln() {
|
||||
std::println();
|
||||
}
|
||||
|
||||
void prln(auto const& t) {
|
||||
std::println("{}", t);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
vec<int> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
int x;
|
||||
cin >> x;
|
||||
|
||||
a[0] = min(a[0], x - a[0]);
|
||||
for (int i = 1; i < n; ++i) {
|
||||
if (a[i] >= a[i - 1] && x - a[i] >= a[i - 1]) {
|
||||
a[i] = min(a[i], x - a[i]);
|
||||
} else if (a[i] >= a[i - 1]) {
|
||||
;
|
||||
} else if (x - a[i] >= a[i - 1]) {
|
||||
a[i] = x - a[i];
|
||||
} else {
|
||||
prln("NO");
|
||||
return;
|
||||
}
|
||||
}
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
// {{{
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
16
codeforces/1003/c.in
Normal file
16
codeforces/1003/c.in
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
5
|
||||
1 1
|
||||
5
|
||||
9
|
||||
3 1
|
||||
1 4 3
|
||||
3
|
||||
4 1
|
||||
1 4 2 5
|
||||
6
|
||||
4 1
|
||||
5 4 10 5
|
||||
4
|
||||
3 1
|
||||
9 8 7
|
||||
8
|
||||
8
codeforces/1003/c.out
Normal file
8
codeforces/1003/c.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.0981 ms
|
||||
5
codeforces/1003/compile_flags.txt
Normal file
5
codeforces/1003/compile_flags.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
-std=c++23
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
109
codeforces/1003/d.cc
Normal file
109
codeforces/1003/d.cc
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
// {{{
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
void prln() {
|
||||
std::println();
|
||||
}
|
||||
|
||||
void prln(auto const& t) {
|
||||
std::println("{}", t);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
ll n, m;
|
||||
cin >> n >> m;
|
||||
vec<vec<ll>> arrays(n, vec<ll>(m));
|
||||
vec<pair<ll, int>> scores;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
ll score = 0;
|
||||
for (auto& e : arrays[i]) {
|
||||
cin >> e;
|
||||
score += e;
|
||||
}
|
||||
scores.eb(score, i);
|
||||
}
|
||||
|
||||
sort(rall(scores));
|
||||
|
||||
ll ans = 0;
|
||||
ll x = n * m;
|
||||
for (int i = 0; i < sz<int>(scores); ++i) {
|
||||
int index = scores[i].ss;
|
||||
for (auto e : arrays[index]) {
|
||||
ans += e * x--;
|
||||
}
|
||||
}
|
||||
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
// {{{
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
11
codeforces/1003/d.in
Normal file
11
codeforces/1003/d.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
3
|
||||
2 2
|
||||
4 4
|
||||
6 1
|
||||
3 4
|
||||
2 2 2 2
|
||||
3 2 1 2
|
||||
4 1 2 1
|
||||
2 3
|
||||
3 4 5
|
||||
1 1 9
|
||||
6
codeforces/1003/d.out
Normal file
6
codeforces/1003/d.out
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
41
|
||||
162
|
||||
72
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.8089 ms
|
||||
86
codeforces/1003/e.cc
Normal file
86
codeforces/1003/e.cc
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
// {{{
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename 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());
|
||||
}
|
||||
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
void prln() {
|
||||
std::println();
|
||||
}
|
||||
|
||||
void prln(auto const& t) {
|
||||
std::println("{}", t);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
|
||||
}
|
||||
|
||||
// {{{
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
0
codeforces/1003/e.in
Normal file
0
codeforces/1003/e.in
Normal file
0
codeforces/1003/e.out
Normal file
0
codeforces/1003/e.out
Normal file
134
codeforces/1003/f.cc
Normal file
134
codeforces/1003/f.cc
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
// {{{
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename 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());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
void prln() {
|
||||
std::println();
|
||||
}
|
||||
|
||||
void prln(auto const &t) {
|
||||
std::println("{}", t);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
vec<int> a(n + 1);
|
||||
for (int i = 1; i < sz<int>(a); ++i) {
|
||||
cin >> a[i];
|
||||
}
|
||||
|
||||
vec<vec<int>> tree(n + 1, vec<int>());
|
||||
string ans(n, '0');
|
||||
|
||||
int root;
|
||||
for (int i = 0; i < n - 1; ++i) {
|
||||
int u, v;
|
||||
cin >> u >> v;
|
||||
root = u;
|
||||
tree[u].pb(v);
|
||||
tree[v].pb(u);
|
||||
}
|
||||
|
||||
unordered_map<int, unordered_map<int, int>> children;
|
||||
vec<int> par(n + 1, -1);
|
||||
par[root] = root;
|
||||
|
||||
queue<int> q{{root}};
|
||||
|
||||
while (!q.empty()) {
|
||||
int size = sz<int>(q);
|
||||
while (size--) {
|
||||
auto u = q.front();
|
||||
q.pop();
|
||||
for (auto v : tree[u]) {
|
||||
if (par[v] != -1)
|
||||
continue;
|
||||
par[v] = u;
|
||||
q.push(v);
|
||||
if (++children[u][a[v]] == 2)
|
||||
ans[a[v] - 1] = '1';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
q.push(root);
|
||||
|
||||
for (int u = 1; u <= n; ++u) {
|
||||
if (par[u] != u && a[u] == a[par[u]] ||
|
||||
par[u] != root && a[u] == a[par[par[u]]])
|
||||
ans[a[u] - 1] = '1';
|
||||
}
|
||||
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
// {{{
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
29
codeforces/1003/f.in
Normal file
29
codeforces/1003/f.in
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
4
|
||||
3
|
||||
1 2 3
|
||||
1 3
|
||||
2 3
|
||||
4
|
||||
3 1 1 3
|
||||
1 2
|
||||
2 3
|
||||
4 2
|
||||
4
|
||||
2 4 4 2
|
||||
1 2
|
||||
2 3
|
||||
3 4
|
||||
13
|
||||
1 4 4 7 4 7 1 1 7 11 11 11 11
|
||||
1 2
|
||||
2 3
|
||||
3 4
|
||||
4 5
|
||||
4 6
|
||||
2 7
|
||||
7 8
|
||||
2 9
|
||||
6 10
|
||||
5 11
|
||||
11 12
|
||||
10 13
|
||||
7
codeforces/1003/f.out
Normal file
7
codeforces/1003/f.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
000
|
||||
1010
|
||||
0001
|
||||
1001001000100
|
||||
|
||||
[code]: 0
|
||||
[time]: 3.66259 ms
|
||||
9
codeforces/957/.clang-format
Normal file
9
codeforces/957/.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
|
||||
8
codeforces/957/.clangd
Normal file
8
codeforces/957/.clangd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
- -std=c++23
|
||||
- -Wall
|
||||
- -Wextra
|
||||
- -Wpedantic
|
||||
- -Wshadow
|
||||
- -Wno-unknown-pragmas
|
||||
87
codeforces/957/a.cc
Normal file
87
codeforces/957/a.cc
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
|
||||
#define FORI(a, b, c) for (int a = (b); a < (c); ++a)
|
||||
#define ROFI(a, b, c) for (int a = (b); a > (c); --a)
|
||||
#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a)
|
||||
#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) // }}}
|
||||
|
||||
void solve() {
|
||||
ll a, b, c;
|
||||
cin >> a >> b >> c;
|
||||
|
||||
ll ans = 0;
|
||||
FORI(i, 0, 5 + 1) {
|
||||
FORI(j, 0, 5 - i + 1) {
|
||||
ans = max(ans, (a + i) * (b + j) * (c + (5 - i - j)));
|
||||
}
|
||||
}
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
} //}}}
|
||||
3
codeforces/957/a.in
Normal file
3
codeforces/957/a.in
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
2
|
||||
2 3 4
|
||||
10 1 10
|
||||
5
codeforces/957/a.out
Normal file
5
codeforces/957/a.out
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
100
|
||||
600
|
||||
|
||||
[code]: 0
|
||||
[time]: 10.5841 ms
|
||||
93
codeforces/957/b.cc
Normal file
93
codeforces/957/b.cc
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
|
||||
#define FORI(a, b, c) for (int a = (b); a < (c); ++a)
|
||||
#define ROFI(a, b, c) for (int a = (b); a > (c); --a)
|
||||
#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a)
|
||||
#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) // }}}
|
||||
|
||||
void solve() {
|
||||
int n, k;
|
||||
cin >> n >> k;
|
||||
vec<int> a(k);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
sort(all(a));
|
||||
|
||||
ll ans = 0;
|
||||
FORI(i, 0, sz<int>(a) - 1) {
|
||||
if (a[i] > 1) {
|
||||
ans += (a[i] << 1) - 1;
|
||||
} else
|
||||
++ans;
|
||||
}
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
} //}}}
|
||||
9
codeforces/957/b.in
Normal file
9
codeforces/957/b.in
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
4
|
||||
5 3
|
||||
3 1 1
|
||||
5 2
|
||||
3 2
|
||||
11 4
|
||||
2 3 1 5
|
||||
16 6
|
||||
1 6 1 1 1 6
|
||||
7
codeforces/957/b.out
Normal file
7
codeforces/957/b.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
2
|
||||
3
|
||||
9
|
||||
15
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.924 ms
|
||||
87
codeforces/957/c.cc
Normal file
87
codeforces/957/c.cc
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
|
||||
#define FORI(a, b, c) for (int a = (b); a < (c); ++a)
|
||||
#define ROFI(a, b, c) for (int a = (b); a > (c); --a)
|
||||
#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a)
|
||||
#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) // }}}
|
||||
|
||||
void solve() {
|
||||
int n, m, k;
|
||||
cin >> n >> m >> k;
|
||||
|
||||
ROFI(x, n, m) {
|
||||
pr("{} ", x);
|
||||
}
|
||||
FORI(x, 1, m + 1) {
|
||||
pr("{} ", x);
|
||||
}
|
||||
println();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
} //}}}
|
||||
4
codeforces/957/c.in
Normal file
4
codeforces/957/c.in
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
3
|
||||
5 2 5
|
||||
3 1 3
|
||||
10 3 8
|
||||
6
codeforces/957/c.out
Normal file
6
codeforces/957/c.out
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
5 4 3 1 2
|
||||
3 2 1
|
||||
10 9 8 7 6 5 4 1 2 3
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.05407 ms
|
||||
5
codeforces/957/compile_flags.txt
Normal file
5
codeforces/957/compile_flags.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
-std=c++23
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
119
codeforces/957/d.cc
Normal file
119
codeforces/957/d.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;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
|
||||
#define FORI(a, b, c) for (int a = (b); a < (c); ++a)
|
||||
#define ROFI(a, b, c) for (int a = (b); a > (c); --a)
|
||||
#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a)
|
||||
#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) // }}}
|
||||
|
||||
void solve() {
|
||||
int _, jump, swim;
|
||||
cin >> _ >> jump >> swim;
|
||||
string s;
|
||||
cin >> s;
|
||||
|
||||
int get_to = 0;
|
||||
vec<int> logs;
|
||||
FORI(i, 0, sz<int>(s)) {
|
||||
if (s[i] == 'L')
|
||||
logs.pb(i);
|
||||
}
|
||||
|
||||
logs.pb(sz<int>(s) + 1);
|
||||
|
||||
int pos = -1;
|
||||
bool done = true;
|
||||
while (pos < sz<int>(s)) {
|
||||
auto diff = logs[get_to] - pos;
|
||||
if (jump < diff) {
|
||||
if ((pos += jump) < sz<int>(s)) {
|
||||
while (pos < sz<int>(s) && pos < logs[get_to]) {
|
||||
if (s[pos] == 'C' || swim == 0) {
|
||||
done = false;
|
||||
break;
|
||||
}
|
||||
++pos;
|
||||
--swim;
|
||||
}
|
||||
if (!done)
|
||||
break;
|
||||
} else
|
||||
break;
|
||||
} else {
|
||||
pos = logs[get_to];
|
||||
}
|
||||
++get_to;
|
||||
}
|
||||
|
||||
if (done)
|
||||
prln("YES");
|
||||
else
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
} //}}}
|
||||
13
codeforces/957/d.in
Normal file
13
codeforces/957/d.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
6 2 0
|
||||
LWLLLW
|
||||
6 1 1
|
||||
LWLLLL
|
||||
6 1 1
|
||||
LWLLWL
|
||||
6 2 15
|
||||
LWLLCC
|
||||
6 10 0
|
||||
CCCCCC
|
||||
6 6 1
|
||||
WCCCCW
|
||||
9
codeforces/957/d.out
Normal file
9
codeforces/957/d.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
YES
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 18.3692 ms
|
||||
81
codeforces/957/f.cc
Normal file
81
codeforces/957/f.cc
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename 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());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
void prln() {
|
||||
std::println();
|
||||
}
|
||||
|
||||
void prln(auto const& t) {
|
||||
std::println("{}", t);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
|
||||
void solve() {
|
||||
prln(5);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
} //}}}
|
||||
17
codeforces/957/f.in
Normal file
17
codeforces/957/f.in
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
8
|
||||
6 4
|
||||
2 3 6 2 1 2
|
||||
9 100000
|
||||
50000 25000 12500 6250 3125 2 4 8 16
|
||||
5 2
|
||||
1 1 1 1 1
|
||||
8 6
|
||||
4 3 4 3 4 3 4 3
|
||||
7 12
|
||||
6 11 1 3 11 10 2
|
||||
10 5
|
||||
2 4 4 2 4 4 4 3 1 1
|
||||
7 8
|
||||
4 6 5 1 2 4 1
|
||||
8 27
|
||||
3 9 17 26 2 20 9 3
|
||||
11
codeforces/957/f.out
Normal file
11
codeforces/957/f.out
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
5
|
||||
5
|
||||
5
|
||||
5
|
||||
5
|
||||
5
|
||||
5
|
||||
5
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.038 ms
|
||||
9
codeforces/996/.clang-format
Normal file
9
codeforces/996/.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
|
||||
8
codeforces/996/.clangd
Normal file
8
codeforces/996/.clangd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
- -std=c++23
|
||||
- -Wall
|
||||
- -Wextra
|
||||
- -Wpedantic
|
||||
- -Wshadow
|
||||
- -Wno-unknown-pragmas
|
||||
84
codeforces/996/a.cc
Normal file
84
codeforces/996/a.cc
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename 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);
|
||||
}
|
||||
|
||||
[[nodiscard]] static int sz(auto &&x) {
|
||||
return static_cast<int>(x.size());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend() // }}}
|
||||
|
||||
#define FORI(a, b, c) for (int a = (b); a < (c); ++a)
|
||||
#define ROFI(a, b, c) for (int a = (b); a > (c); --a)
|
||||
#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a)
|
||||
#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a)
|
||||
|
||||
void solve() {
|
||||
string a;
|
||||
cin >> a;
|
||||
if (!(a.size() > 2)) {
|
||||
std::println("NO");
|
||||
return;
|
||||
}
|
||||
if (!(a[0] == '1' && a[1] == '0')) {
|
||||
std::println("NO");
|
||||
return;
|
||||
}
|
||||
|
||||
int x = sz(a);
|
||||
|
||||
if (stoi(a.substr(2, a.size())) < 2 || a[2] == '0') {
|
||||
std::println("NO");
|
||||
} else {
|
||||
std::println("YES");
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
} //}}}
|
||||
8
codeforces/996/a.in
Normal file
8
codeforces/996/a.in
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
7
|
||||
100
|
||||
1010
|
||||
101
|
||||
105
|
||||
2033
|
||||
1019
|
||||
1002
|
||||
10
codeforces/996/a.out
Normal file
10
codeforces/996/a.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
NO
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.1806 ms
|
||||
96
codeforces/996/b.cc
Normal file
96
codeforces/996/b.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;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
|
||||
#define FORI(a, b, c) for (int a = (b); a < (c); ++a)
|
||||
#define ROFI(a, b, c) for (int a = (b); a > (c); --a)
|
||||
#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a)
|
||||
#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) // }}}
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
int a;
|
||||
cin >> a;
|
||||
int l = a, r = a;
|
||||
bool done = false;
|
||||
while (--n) {
|
||||
cin >> a;
|
||||
if (!(a == l - 1 || a == r + 1)) {
|
||||
done = true;
|
||||
}
|
||||
l = min(l, a);
|
||||
r = max(r, a);
|
||||
}
|
||||
|
||||
if (done)
|
||||
prln("NO");
|
||||
else
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
} //}}}
|
||||
9
codeforces/996/b.in
Normal file
9
codeforces/996/b.in
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
4
|
||||
5
|
||||
5 4 2 1 3
|
||||
3
|
||||
2 3 1
|
||||
4
|
||||
2 3 1 4
|
||||
5
|
||||
1 2 3 5 4
|
||||
11
codeforces/996/b.out
Normal file
11
codeforces/996/b.out
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
n=5
|
||||
NO
|
||||
n=3
|
||||
YES
|
||||
n=4
|
||||
YES
|
||||
n=5
|
||||
NO
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.2283 ms
|
||||
210
codeforces/996/c.cc
Normal file
210
codeforces/996/c.cc
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename 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());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
|
||||
#define FORI(a, b, c) for (int a = (b); a < (c); ++a)
|
||||
#define ROFI(a, b, c) for (int a = (b); a > (c); --a)
|
||||
#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a)
|
||||
#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) // }}}
|
||||
|
||||
#include <ext/pb_ds/assoc_container.hpp>
|
||||
#include <ext/pb_ds/tree_policy.hpp>
|
||||
|
||||
using namespace __gnu_pbds;
|
||||
|
||||
// https://mirror.codeforces.com/blog/entry/124683
|
||||
|
||||
namespace hashing {
|
||||
using i64 = std::int64_t;
|
||||
using u64 = std::uint64_t;
|
||||
static const u64 FIXED_RANDOM =
|
||||
std::chrono::steady_clock::now().time_since_epoch().count();
|
||||
|
||||
#if USE_AES
|
||||
std::mt19937 rd(FIXED_RANDOM);
|
||||
const __m128i KEY1{(i64)rd(), (i64)rd()};
|
||||
const __m128i KEY2{(i64)rd(), (i64)rd()};
|
||||
#endif
|
||||
|
||||
template <class T, class D = void>
|
||||
struct custom_hash {};
|
||||
|
||||
template <class T>
|
||||
inline void hash_combine(u64 &seed, T const &v) {
|
||||
custom_hash<T> hasher;
|
||||
seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct custom_hash<T,
|
||||
typename std::enable_if<std::is_integral<T>::value>::type> {
|
||||
u64 operator()(T _x) const {
|
||||
u64 x = _x;
|
||||
#if USE_AES
|
||||
__m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM};
|
||||
__m128i y = _mm_aesenc_si128(m, KEY1);
|
||||
__m128i z = _mm_aesenc_si128(y, KEY2);
|
||||
return z[0];
|
||||
#else
|
||||
x += 0x9e3779b97f4a7c15 + FIXED_RANDOM;
|
||||
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
|
||||
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
|
||||
return x ^ (x >> 31);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct custom_hash<T, std::void_t<decltype(std::begin(std::declval<T>()))>> {
|
||||
u64 operator()(T const &a) const {
|
||||
u64 value = FIXED_RANDOM;
|
||||
for (auto &x : a)
|
||||
hash_combine(value, x);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
template <class... T>
|
||||
struct custom_hash<std::tuple<T...>> {
|
||||
u64 operator()(const std::tuple<T...> &a) const {
|
||||
u64 value = FIXED_RANDOM;
|
||||
std::apply(
|
||||
[&value](T const &...args) {
|
||||
(hash_combine(value, args), ...);
|
||||
},
|
||||
a);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct custom_hash<std::pair<T, U>> {
|
||||
u64 operator()(std::pair<T, U> const &a) const {
|
||||
u64 value = FIXED_RANDOM;
|
||||
hash_combine(value, a.first);
|
||||
hash_combine(value, a.second);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}; // namespace hashing
|
||||
|
||||
#ifdef PB_DS_ASSOC_CNTNR_HPP
|
||||
template <class Key, class Value = null_type>
|
||||
using hashtable = gp_hash_table<
|
||||
Key, Value, hashing::custom_hash<Key>, std::equal_to<Key>,
|
||||
direct_mask_range_hashing<>, linear_probe_fn<>,
|
||||
hash_standard_resize_policy<hash_exponential_size_policy<>,
|
||||
hash_load_check_resize_trigger<>, true>>;
|
||||
|
||||
#endif
|
||||
#ifdef PB_DS_TREE_POLICY_HPP
|
||||
template <typename T>
|
||||
using multiset = tree<T, null_type, std::less_equal<T>, rb_tree_tag,
|
||||
tree_order_statistics_node_update>;
|
||||
template <class Key, class Value = null_type>
|
||||
using rbtree = tree<Key, Value, std::less<Key>, rb_tree_tag,
|
||||
tree_order_statistics_node_update>;
|
||||
#endif
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
vec<int> a(n);
|
||||
for (auto &e : a)
|
||||
cin >> e;
|
||||
int m;
|
||||
cin >> m;
|
||||
|
||||
hashtable<int, int> a2s, s2a;
|
||||
|
||||
while (m--) {
|
||||
string s;
|
||||
cin >> s;
|
||||
if (s.size() != a.size()) {
|
||||
prln("NO");
|
||||
continue;
|
||||
}
|
||||
bool done = false;
|
||||
FORI(i, 0, sz<int>(a)) {
|
||||
if (a2s.find(a[i]) == a2s.end() && s2a.find(s[i]) == s2a.end()) {
|
||||
a2s[a[i]] = s[i];
|
||||
s2a[s[i]] = a[i];
|
||||
} else if (a2s[a[i]] != s[i] || s2a[s[i]] != a[i]) {
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (done)
|
||||
prln("NO");
|
||||
else
|
||||
prln("YES");
|
||||
a2s.clear();
|
||||
s2a.clear();
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
} //}}}
|
||||
19
codeforces/996/c.in
Normal file
19
codeforces/996/c.in
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
3
|
||||
5
|
||||
3 5 2 1 3
|
||||
2
|
||||
abfda
|
||||
afbfa
|
||||
2
|
||||
1 2
|
||||
3
|
||||
ab
|
||||
abc
|
||||
aa
|
||||
4
|
||||
5 -3 5 -3
|
||||
4
|
||||
aaaa
|
||||
bcbc
|
||||
aba
|
||||
cbcb
|
||||
12
codeforces/996/c.out
Normal file
12
codeforces/996/c.out
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.55689 ms
|
||||
5
codeforces/996/compile_flags.txt
Normal file
5
codeforces/996/compile_flags.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
-std=c++23
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
103
codeforces/996/d.cc
Normal file
103
codeforces/996/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;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
|
||||
#define FORI(a, b, c) for (int a = (b); a < (c); ++a)
|
||||
#define ROFI(a, b, c) for (int a = (b); a > (c); --a)
|
||||
#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a)
|
||||
#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) // }}}
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
vec<ll> a(n);
|
||||
vec<ll> prefix(n + 1, 0);
|
||||
FORI(i, 0, n) {
|
||||
cin >> a[i];
|
||||
prefix[i + 1] = prefix[i] + a[i];
|
||||
}
|
||||
string s;
|
||||
cin >> s;
|
||||
|
||||
int l = 0, r = n - 1;
|
||||
ll ans = 0;
|
||||
|
||||
while (l < r) {
|
||||
if (s[l] == 'L' && s[r] == 'R') {
|
||||
ans += prefix[r + 1] - prefix[l];
|
||||
++l;
|
||||
--r;
|
||||
} else if (s[r] == 'L') {
|
||||
--r;
|
||||
} else {
|
||||
++l;
|
||||
}
|
||||
}
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
} //}}}
|
||||
16
codeforces/996/d.in
Normal file
16
codeforces/996/d.in
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
5
|
||||
3
|
||||
-1 -1 -1
|
||||
LLR
|
||||
6
|
||||
3 5 1 4 3 2
|
||||
LRLLLR
|
||||
2
|
||||
2 8
|
||||
LR
|
||||
2
|
||||
3 9
|
||||
RL
|
||||
5
|
||||
1 2 3 4 5
|
||||
LRLRR
|
||||
8
codeforces/996/d.out
Normal file
8
codeforces/996/d.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
0
|
||||
18
|
||||
10
|
||||
0
|
||||
22
|
||||
|
||||
[code]: 0
|
||||
[time]: 10.4334 ms
|
||||
145
codeforces/996/e.cc
Normal file
145
codeforces/996/e.cc
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename 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());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
|
||||
#define FORI(a, b, c) for (int a = (b); a < (c); ++a)
|
||||
#define ROFI(a, b, c) for (int a = (b); a > (c); --a)
|
||||
#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a)
|
||||
#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) // }}}
|
||||
|
||||
void fill(vec<vec<ll>>& matrix, vec<int>& a, int k) {
|
||||
int n = matrix.size();
|
||||
int m = matrix[0].size();
|
||||
|
||||
vec<vec<int>> extra(n, vec<int>(m));
|
||||
|
||||
FORI(i, 0, n) {
|
||||
FORI(j, 0, m) {
|
||||
int top = max(0, i - (k - 1));
|
||||
int left = max(0, j - (k - 1));
|
||||
int bottom = min(n - k, i);
|
||||
int right = min(m - k, j);
|
||||
extra[i][j] = (bottom - top + 1) * (right - left + 1);
|
||||
}
|
||||
}
|
||||
|
||||
vec<pair<int, pair<int, int>>> cells;
|
||||
FORI(i, 0, n) {
|
||||
FORI(j, 0, m) {
|
||||
cells.push_back({extra[i][j], {i, j}});
|
||||
}
|
||||
}
|
||||
|
||||
sort(rall(cells));
|
||||
|
||||
FORI(i, 0, min(n * m, sz<int>(a))) {
|
||||
auto [x, y] = cells[i].ss;
|
||||
matrix[x][y] = a[i];
|
||||
}
|
||||
}
|
||||
|
||||
long long sums(vector<vector<ll>>& matrix, int k) {
|
||||
int n = matrix.size(), m = matrix[0].size();
|
||||
|
||||
vec<vec<ll>> prefix(n + 1, vec<ll>(m + 1, 0));
|
||||
FORI(i, 1, n + 1) {
|
||||
FORI(j, 1, m + 1) {
|
||||
prefix[i][j] = matrix[i - 1][j - 1] + prefix[i - 1][j] +
|
||||
prefix[i][j - 1] - prefix[i - 1][j - 1];
|
||||
}
|
||||
}
|
||||
auto get = [&](int r1, int c1, int r2, int c2) -> ll {
|
||||
return prefix[r2 + 1][c2 + 1] - prefix[r2 + 1][c1] - prefix[r1][c2 + 1] +
|
||||
prefix[r1][c1];
|
||||
};
|
||||
ll ans = 0;
|
||||
FORI(i, 0, n - k + 1) {
|
||||
FORI(j, 0, m - k + 1) {
|
||||
ans += get(i, j, i + k - 1, j + k - 1);
|
||||
}
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
void solve() {
|
||||
int n, m, k;
|
||||
cin >> n >> m >> k;
|
||||
int w;
|
||||
cin >> w;
|
||||
vec<int> a(w);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
sort(rall(a));
|
||||
|
||||
vector<vector<ll>> matrix(n, vector<ll>(m, 0));
|
||||
|
||||
fill(matrix, a, k);
|
||||
|
||||
prln("{}", sums(matrix, k));
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
} //}}}
|
||||
16
codeforces/996/e.in
Normal file
16
codeforces/996/e.in
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
5
|
||||
3 4 2
|
||||
9
|
||||
1 1 1 1 1 1 1 1 1
|
||||
2 1 1
|
||||
2
|
||||
5 7
|
||||
20 15 7
|
||||
9
|
||||
4 1 4 5 6 1 1000000000 898 777
|
||||
1984 1 1
|
||||
4
|
||||
5 4 1499 2004
|
||||
9 5 5
|
||||
6
|
||||
6 7 14 16 16 6
|
||||
8
codeforces/996/e.out
Normal file
8
codeforces/996/e.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
21
|
||||
12
|
||||
49000083104
|
||||
3512
|
||||
319
|
||||
|
||||
[code]: 0
|
||||
[time]: 13.2093 ms
|
||||
106
codeforces/996/f.cc
Normal file
106
codeforces/996/f.cc
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
|
||||
#define FORI(a, b, c) for (int a = (b); a < (c); ++a)
|
||||
#define ROFI(a, b, c) for (int a = (b); a > (c); --a)
|
||||
#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a)
|
||||
#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) // }}}
|
||||
|
||||
void solve() {
|
||||
int n, k;
|
||||
cin >> n >> k;
|
||||
|
||||
vec<pair<ll, ll>> recs;
|
||||
FORI(i, 0, n) {
|
||||
cin >> recs[i].ff >> recs[i].ss;
|
||||
}
|
||||
|
||||
vec<vec<ll>> dp(n + 1, vec<ll>(k + 1, MAX<ll>));
|
||||
FORI(i, 0, n + 1) {
|
||||
dp[i][0] = 0;
|
||||
}
|
||||
|
||||
FORLL(i, 1, n + 1) {
|
||||
FORLL(j, 1, k + 1) {
|
||||
int x = recs[i - 1].ff, y = recs[i - 1].ss;
|
||||
int cost = 0;
|
||||
FORLL(take, 0, min(j, recs[i - 1].ff + recs[i - 1].ss) + 1) {
|
||||
if (dp[i - 1][j - take] != MAX<ll>)
|
||||
dp[i][j] = min(dp[i][j], dp[i - 1][j - take] + cost);
|
||||
if (x > y)
|
||||
swap(x, y);
|
||||
cost += x;
|
||||
y--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << (dp[n][k] == MAX<ll> ? -1 : dp[n][k]) << '\n';
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
} //}}}
|
||||
27
codeforces/996/f.in
Normal file
27
codeforces/996/f.in
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
7
|
||||
1 4
|
||||
6 3
|
||||
1 5
|
||||
4 4
|
||||
5 10
|
||||
1 1
|
||||
1 1
|
||||
1 1
|
||||
1 1
|
||||
1 1
|
||||
2 100
|
||||
1 2
|
||||
5 6
|
||||
3 11
|
||||
2 2
|
||||
3 3
|
||||
4 4
|
||||
3 25
|
||||
9 2
|
||||
4 3
|
||||
8 10
|
||||
4 18
|
||||
5 4
|
||||
8 5
|
||||
8 3
|
||||
6 2
|
||||
3
codeforces/996/f.out
Normal file
3
codeforces/996/f.out
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
[code]: 15 (SIGTERM)
|
||||
[time]: 98.3179 ms
|
||||
Loading…
Add table
Add a link
Reference in a new issue