895
This commit is contained in:
parent
94383fbaf7
commit
26f66e43d8
97 changed files with 5337 additions and 42 deletions
9
codeforces/898/.clang-format
Normal file
9
codeforces/898/.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/898/.clangd
Normal file
8
codeforces/898/.clangd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
- -Wall
|
||||
- -Wextra
|
||||
- -Wpedantic
|
||||
- -Wshadow
|
||||
- -DLOCAL
|
||||
- -Wno-unknown-pragmas
|
||||
102
codeforces/898/a.cc
Normal file
102
codeforces/898/a.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>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return 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());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#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;
|
||||
|
||||
if (s == "abc" || s == "cba" || s == "acb" || s == "bac")
|
||||
YES();
|
||||
else
|
||||
NO();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
7
codeforces/898/a.in
Normal file
7
codeforces/898/a.in
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
6
|
||||
abc
|
||||
acb
|
||||
bac
|
||||
bca
|
||||
cab
|
||||
cba
|
||||
109
codeforces/898/b.cc
Normal file
109
codeforces/898/b.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>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return 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());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#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;
|
||||
|
||||
ve<int> a(n);
|
||||
ll ans = 1;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cin >> a[i];
|
||||
ans *= a[i];
|
||||
}
|
||||
sort(all(a));
|
||||
ll a2 = 1;
|
||||
for (int i = 1; i < n; ++i)
|
||||
a2 *= a[i];
|
||||
prln("{}", a2 + ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
9
codeforces/898/b.in
Normal file
9
codeforces/898/b.in
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
4
|
||||
4
|
||||
2 2 1 2
|
||||
3
|
||||
0 1 2
|
||||
5
|
||||
4 3 2 3 4
|
||||
9
|
||||
9 9 9 9 9 9 9 9 9
|
||||
7
codeforces/898/b.out
Normal file
7
codeforces/898/b.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
16
|
||||
2
|
||||
432
|
||||
430467210
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.507 ms
|
||||
111
codeforces/898/c.cc
Normal file
111
codeforces/898/c.cc
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
#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>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return 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());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#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() {
|
||||
char C;
|
||||
ll ans = 0;
|
||||
for (int r = 0; r < 10; ++r) {
|
||||
for (int c = 0; c < 10; ++c) {
|
||||
cin >> C;
|
||||
if (C == 'X') {
|
||||
int row = min(r, c), col = max(r, c);
|
||||
if (col > 4)
|
||||
col = 4 - (col - 5);
|
||||
if (row > 4)
|
||||
row = 4 - (row - 5);
|
||||
ans += min(row, col) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
41
codeforces/898/c.in
Normal file
41
codeforces/898/c.in
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
4
|
||||
X.........
|
||||
..........
|
||||
.......X..
|
||||
.....X....
|
||||
......X...
|
||||
..........
|
||||
.........X
|
||||
..X.......
|
||||
..........
|
||||
.........X
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
....X.....
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
XXXXXXXXXX
|
||||
XXXXXXXXXX
|
||||
XXXXXXXXXX
|
||||
XXXXXXXXXX
|
||||
XXXXXXXXXX
|
||||
XXXXXXXXXX
|
||||
XXXXXXXXXX
|
||||
XXXXXXXXXX
|
||||
XXXXXXXXXX
|
||||
XXXXXXXXXX
|
||||
7
codeforces/898/c.out
Normal file
7
codeforces/898/c.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
17
|
||||
0
|
||||
5
|
||||
220
|
||||
|
||||
[code]: 0
|
||||
[time]: 5.24926 ms
|
||||
6
codeforces/898/compile_flags.txt
Normal file
6
codeforces/898/compile_flags.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-DLOCAL
|
||||
-std=c++23
|
||||
109
codeforces/898/d.cc
Normal file
109
codeforces/898/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>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return 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());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#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, k;
|
||||
cin >> n >> k;
|
||||
string s;
|
||||
cin >> s;
|
||||
int i = 0;
|
||||
int ans = 0;
|
||||
while (i < n) {
|
||||
if (s[i] == 'B') {
|
||||
++ans;
|
||||
i = min(n, i + k);
|
||||
} else
|
||||
++i;
|
||||
}
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
17
codeforces/898/d.in
Normal file
17
codeforces/898/d.in
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
8
|
||||
6 3
|
||||
WBWWWB
|
||||
7 3
|
||||
WWBWBWW
|
||||
5 4
|
||||
BWBWB
|
||||
5 5
|
||||
BBBBB
|
||||
8 2
|
||||
BWBWBBBB
|
||||
10 2
|
||||
WBBWBBWBBW
|
||||
4 1
|
||||
BBBB
|
||||
3 2
|
||||
WWW
|
||||
11
codeforces/898/d.out
Normal file
11
codeforces/898/d.out
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
2
|
||||
1
|
||||
2
|
||||
1
|
||||
4
|
||||
3
|
||||
4
|
||||
0
|
||||
|
||||
[code]: 0
|
||||
[time]: 13.9532 ms
|
||||
122
codeforces/898/e.cc
Normal file
122
codeforces/898/e.cc
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
#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>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return 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());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#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, x;
|
||||
cin >> n >> x;
|
||||
ve<ll> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
ll l = 1, r = 2'000'000'007;
|
||||
|
||||
auto can = [&](int A) {
|
||||
ll total = 0;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
total += max(0LL, A - a[i]);
|
||||
}
|
||||
return total <= x;
|
||||
};
|
||||
|
||||
while (l <= r) {
|
||||
ll m = l + (r - l) / 2;
|
||||
|
||||
if (can(m)) {
|
||||
l = m + 1;
|
||||
} else {
|
||||
r = m - 1;
|
||||
}
|
||||
}
|
||||
|
||||
prln("{}", r);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
11
codeforces/898/e.in
Normal file
11
codeforces/898/e.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
5
|
||||
7 9
|
||||
3 1 2 4 6 2 5
|
||||
3 10
|
||||
1 1 1
|
||||
4 1
|
||||
1 4 3 4
|
||||
6 1984
|
||||
2 6 5 9 1 8
|
||||
1 1000000000
|
||||
1
|
||||
8
codeforces/898/e.out
Normal file
8
codeforces/898/e.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
4
|
||||
4
|
||||
2
|
||||
335
|
||||
1000000001
|
||||
|
||||
[code]: 0
|
||||
[time]: 13.1681 ms
|
||||
115
codeforces/898/f.cc
Normal file
115
codeforces/898/f.cc
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return 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());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#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, k;
|
||||
cin >> n >> k;
|
||||
ve<ll> a(n), h(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
for (auto& e : h)
|
||||
cin >> e;
|
||||
|
||||
int ans = 0;
|
||||
int l = 0, fruits = 0;
|
||||
for (int r = 0; r < n; ++r) {
|
||||
fruits += a[r];
|
||||
while (l <= r &&
|
||||
(fruits > k || (l < r && (h[l] % h[l + 1] || h[r - 1] % h[r])))) {
|
||||
fruits -= a[l];
|
||||
++l;
|
||||
}
|
||||
ans = max(ans, r - l + 1);
|
||||
}
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
16
codeforces/898/f.in
Normal file
16
codeforces/898/f.in
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
5
|
||||
5 12
|
||||
3 2 4 1 8
|
||||
4 4 2 4 1
|
||||
4 8
|
||||
5 4 1 2
|
||||
6 2 3 1
|
||||
3 12
|
||||
7 9 10
|
||||
2 2 4
|
||||
1 10
|
||||
11
|
||||
1
|
||||
7 10
|
||||
2 6 3 1 5 10 6
|
||||
72 24 24 12 4 4 2
|
||||
8
codeforces/898/f.out
Normal file
8
codeforces/898/f.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
3
|
||||
2
|
||||
1
|
||||
0
|
||||
3
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.9457 ms
|
||||
118
codeforces/898/g.cc
Normal file
118
codeforces/898/g.cc
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
#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>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return 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());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#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;
|
||||
|
||||
int ans = 0;
|
||||
int as = s[0] == 'A', bs = s[0] == 'B';
|
||||
for (int i = 1; i < sz<int>(s); ++i) {
|
||||
if (s[i] == 'B') {
|
||||
ans += as;
|
||||
if (s[i - 1] != 'B')
|
||||
bs = 0;
|
||||
for (int j = i - as; j <= i; ++j)
|
||||
s[j] = 'C';
|
||||
as = 0;
|
||||
}
|
||||
|
||||
as += s[i] == 'A';
|
||||
bs += s[i] == 'B';
|
||||
}
|
||||
|
||||
for (int i = 1; i < sz<int>(s); ++i) {
|
||||
ans += s[i] == 'A' && s[i - 1] == 'B';
|
||||
}
|
||||
prln("{}, {}", ans, s);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
9
codeforces/898/g.in
Normal file
9
codeforces/898/g.in
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
8
|
||||
ABBA
|
||||
ABA
|
||||
BAABA
|
||||
ABB
|
||||
AAAAAAB
|
||||
BABA
|
||||
B
|
||||
AAA
|
||||
11
codeforces/898/g.out
Normal file
11
codeforces/898/g.out
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
1, CCCA
|
||||
1, CCA
|
||||
2, BCCCA
|
||||
1, CCC
|
||||
6, CCCCCCC
|
||||
1, BCCA
|
||||
0, B
|
||||
0, AAA
|
||||
|
||||
[code]: 0
|
||||
[time]: 13.6178 ms
|
||||
100
codeforces/898/h.cc
Normal file
100
codeforces/898/h.cc
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
void YES() {
|
||||
cout << "YES\n";
|
||||
}
|
||||
void NO() {
|
||||
cout << "NO\n";
|
||||
}
|
||||
|
||||
void solve() {
|
||||
int n, a, b;
|
||||
cin >> n >> a >> b;
|
||||
vector<vector<int>> graph(n + 1);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
int u, v;
|
||||
cin >> u >> v;
|
||||
graph[u].push_back(v);
|
||||
graph[v].push_back(u);
|
||||
}
|
||||
|
||||
vector<int> parent(n + 1, -1);
|
||||
vector<int> visited(n + 1, 0);
|
||||
int cycle_start = -1, cycle_end = -1;
|
||||
function<bool(int, int)> dfs_cycle = [&](int u, int par) {
|
||||
visited[u] = 1;
|
||||
for (int v : graph[u]) {
|
||||
if (v == par)
|
||||
continue;
|
||||
if (visited[v] == 1) {
|
||||
cycle_start = v;
|
||||
cycle_end = u;
|
||||
return true;
|
||||
}
|
||||
parent[v] = u;
|
||||
if (dfs_cycle(v, u))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
dfs_cycle(1, -1);
|
||||
|
||||
vector<int> cycle_nodes;
|
||||
if (cycle_start != -1) {
|
||||
for (int u = cycle_end; u != cycle_start; u = parent[u]) {
|
||||
cycle_nodes.push_back(u);
|
||||
}
|
||||
cycle_nodes.push_back(cycle_start);
|
||||
}
|
||||
|
||||
unordered_set<int> cycle(cycle_nodes.begin(), cycle_nodes.end());
|
||||
|
||||
auto bfs_dist = [&](int start) -> vector<int> {
|
||||
vector<int> dist(n + 1, -1);
|
||||
queue<int> q;
|
||||
dist[start] = 0;
|
||||
q.push(start);
|
||||
while (!q.empty()) {
|
||||
int u = q.front();
|
||||
q.pop();
|
||||
for (int v : graph[u]) {
|
||||
if (dist[v] == -1) {
|
||||
dist[v] = dist[u] + 1;
|
||||
q.push(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
return dist;
|
||||
};
|
||||
|
||||
vector<int> dist_a = bfs_dist(a);
|
||||
vector<int> dist_b = bfs_dist(b);
|
||||
|
||||
bool can_avoid = false;
|
||||
for (int node : cycle_nodes) {
|
||||
if (dist_b[node] < dist_a[node]) {
|
||||
can_avoid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (can_avoid) {
|
||||
YES();
|
||||
} else {
|
||||
NO();
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios_base::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
43
codeforces/898/h.in
Normal file
43
codeforces/898/h.in
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
6
|
||||
3 2 1
|
||||
2 1
|
||||
3 2
|
||||
1 3
|
||||
4 1 4
|
||||
1 4
|
||||
1 2
|
||||
1 3
|
||||
2 3
|
||||
4 1 2
|
||||
1 2
|
||||
2 3
|
||||
2 4
|
||||
3 4
|
||||
7 1 1
|
||||
4 1
|
||||
2 1
|
||||
5 3
|
||||
4 6
|
||||
4 2
|
||||
7 5
|
||||
3 4
|
||||
8 5 3
|
||||
8 3
|
||||
5 1
|
||||
2 6
|
||||
6 8
|
||||
1 2
|
||||
4 8
|
||||
5 7
|
||||
6 7
|
||||
10 6 1
|
||||
1 2
|
||||
4 3
|
||||
5 8
|
||||
7 8
|
||||
10 4
|
||||
1 9
|
||||
2 4
|
||||
8 1
|
||||
6 2
|
||||
3 1
|
||||
9
codeforces/898/h.out
Normal file
9
codeforces/898/h.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 14.8737 ms
|
||||
Loading…
Add table
Add a link
Reference in a new issue