938 g
This commit is contained in:
parent
1214b129a5
commit
90c9c70260
24 changed files with 1284 additions and 0 deletions
9
codeforces/938/.clang-format
Normal file
9
codeforces/938/.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/938/.clangd
Normal file
8
codeforces/938/.clangd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
- -std=c++23
|
||||
- -Wall
|
||||
- -Wextra
|
||||
- -Wpedantic
|
||||
- -Wshadow
|
||||
- -Wno-unknown-pragmas
|
||||
99
codeforces/938/a.cc
Normal file
99
codeforces/938/a.cc
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
#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>;
|
||||
template <typename T, size_t N>
|
||||
using arr = std::array<T, N>;
|
||||
|
||||
#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, a, b;
|
||||
cin >> n >> a >> b;
|
||||
|
||||
int ans = MAX<int>;
|
||||
for (int i = 0; i <= 100; ++i) {
|
||||
for (int j = 0; j <= 100; ++j) {
|
||||
int spent = i * a + j * b;
|
||||
int bought = i + 2 * j;
|
||||
if (bought == n) {
|
||||
ans = min(ans, spent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
5
codeforces/938/a.in
Normal file
5
codeforces/938/a.in
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
4
|
||||
2 5 9
|
||||
3 5 9
|
||||
3 5 11
|
||||
4 5 11
|
||||
7
codeforces/938/a.out
Normal file
7
codeforces/938/a.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
9
|
||||
14
|
||||
15
|
||||
20
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.37689 ms
|
||||
219
codeforces/938/b.cc
Normal file
219
codeforces/938/b.cc
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
#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>;
|
||||
template <typename T, size_t N>
|
||||
using arr = std::array<T, N>;
|
||||
|
||||
#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()
|
||||
// }}}
|
||||
|
||||
#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, c, d;
|
||||
cin >> n >> c >> d;
|
||||
|
||||
hashtable<int, int> b;
|
||||
int first = MAX<int>;
|
||||
for (int i = 0; i < n * n; ++i) {
|
||||
int x;
|
||||
cin >> x;
|
||||
first = min(first, x);
|
||||
++b[x];
|
||||
}
|
||||
|
||||
int col = first - c;
|
||||
|
||||
for (int i = 0; i < n; ++i) {
|
||||
if (b[col + c] == 0) {
|
||||
prln("NO");
|
||||
return;
|
||||
}
|
||||
col += c;
|
||||
--b[col];
|
||||
int last = col;
|
||||
for (int j = 0; j < n - 1; ++j) {
|
||||
int next = last + d;
|
||||
if (b[next] == 0) {
|
||||
prln("NO");
|
||||
return;
|
||||
}
|
||||
--b[next];
|
||||
last = next;
|
||||
}
|
||||
if (i == n - 1)
|
||||
break;
|
||||
}
|
||||
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
11
codeforces/938/b.in
Normal file
11
codeforces/938/b.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
5
|
||||
3 2 3
|
||||
3 9 6 5 7 1 10 4 8
|
||||
3 2 3
|
||||
3 9 6 5 7 1 11 4 8
|
||||
2 100 100
|
||||
400 300 400 500
|
||||
3 2 3
|
||||
3 9 6 6 5 1 11 4 8
|
||||
4 4 4
|
||||
15 27 7 19 23 23 11 15 7 3 19 23 11 15 11 15
|
||||
12
codeforces/938/b.out
Normal file
12
codeforces/938/b.out
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
NO
|
||||
YES
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
|
||||
[code]: 0
|
||||
[code]: 0
|
||||
[time]: 6.98614 ms
|
||||
[code]: 0
|
||||
[time]: 2.65217 ms
|
||||
[time]: 3.42894 ms
|
||||
127
codeforces/938/c.cc
Normal file
127
codeforces/938/c.cc
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
#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>;
|
||||
template <typename T, size_t N>
|
||||
using arr = std::array<T, N>;
|
||||
|
||||
#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, k;
|
||||
cin >> n >> k;
|
||||
ll ans = 0;
|
||||
vec<ll> a(n);
|
||||
for (auto& e : a) {
|
||||
cin >> e;
|
||||
}
|
||||
|
||||
ll left = ceil(k / 2.0);
|
||||
for (int i = 0; i < sz<int>(a) && left > 0; ++i) {
|
||||
int take = min(a[i], left);
|
||||
a[i] -= take;
|
||||
left -= take;
|
||||
if (a[i] == 0)
|
||||
++ans;
|
||||
}
|
||||
|
||||
ll right = k / 2;
|
||||
|
||||
for (int i = sz<int>(a) - 1; i >= 0 && a[i] > 0 && right > 0; --i) {
|
||||
int take = min(a[i], right);
|
||||
a[i] -= take;
|
||||
right -= take;
|
||||
if (a[i] == 0)
|
||||
++ans;
|
||||
}
|
||||
|
||||
prln("{}", ans);
|
||||
|
||||
// prln("{} left attacks and {} right", left, right);
|
||||
// for (auto x : prefix)
|
||||
// pr("{} ", x);
|
||||
// prln();
|
||||
// for (auto x : postfix)
|
||||
// pr("{} ", x);
|
||||
// prln();
|
||||
|
||||
// ll left_sunk = distance(prefix.begin(), upper_bound(all(prefix), left)) -
|
||||
// 1; ll right_sunk =
|
||||
// distance(postfix.begin(), upper_bound(all(postfix), right)) - 1;
|
||||
|
||||
// prln("{} {} {}", left_sunk, right_sunk, left_sunk + right_sunk);
|
||||
// prln("{}", left_sunk + right_sunk);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
13
codeforces/938/c.in
Normal file
13
codeforces/938/c.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
4 5
|
||||
1 2 4 3
|
||||
4 6
|
||||
1 2 4 3
|
||||
5 20
|
||||
2 7 1 8 2
|
||||
2 2
|
||||
3 2
|
||||
2 15
|
||||
1 5
|
||||
2 7
|
||||
5 2
|
||||
9
codeforces/938/c.out
Normal file
9
codeforces/938/c.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
2
|
||||
3
|
||||
5
|
||||
0
|
||||
2
|
||||
2
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.8582 ms
|
||||
5
codeforces/938/compile_flags.txt
Normal file
5
codeforces/938/compile_flags.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
-std=c++23
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
230
codeforces/938/d.cc
Normal file
230
codeforces/938/d.cc
Normal file
|
|
@ -0,0 +1,230 @@
|
|||
#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>;
|
||||
template <typename T, size_t N>
|
||||
using arr = std::array<T, N>;
|
||||
|
||||
#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()
|
||||
// }}}
|
||||
|
||||
#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() {
|
||||
ll n, m, k;
|
||||
|
||||
cin >> n >> m >> k;
|
||||
|
||||
vec<ll> a(n);
|
||||
hashtable<ll, ll> to_match;
|
||||
for (auto &e : a)
|
||||
cin >> e;
|
||||
for (int i = 0; i < m; ++i) {
|
||||
ll x;
|
||||
cin >> x;
|
||||
++to_match[x];
|
||||
}
|
||||
|
||||
hashtable<ll, ll> window;
|
||||
ll match_count = 0;
|
||||
ll ans = 0;
|
||||
|
||||
for (int i = 0; i < m - 1; ++i) {
|
||||
// prln("adding {} to starting iwndow", a[i]);
|
||||
if (++window[a[i]] <= to_match[a[i]] &&
|
||||
to_match.find(a[i]) != to_match.end()) {
|
||||
++match_count;
|
||||
}
|
||||
}
|
||||
|
||||
int l = 0;
|
||||
for (int r = m - 1; r < n; ++r) {
|
||||
// prln("adding {} to w", a[r]);
|
||||
if (to_match.find(a[r]) != to_match.end() &&
|
||||
++window[a[r]] <= to_match[a[r]]) {
|
||||
++match_count;
|
||||
}
|
||||
|
||||
// prln("{}", match_count);
|
||||
|
||||
if (match_count >= k) {
|
||||
++ans;
|
||||
}
|
||||
|
||||
if (window.find(a[l]) != window.end() && --window[a[l]] < to_match[a[l]]) {
|
||||
--match_count;
|
||||
}
|
||||
++l;
|
||||
}
|
||||
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
16
codeforces/938/d.in
Normal file
16
codeforces/938/d.in
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
5
|
||||
7 4 2
|
||||
4 1 2 3 4 5 6
|
||||
1 2 3 4
|
||||
7 4 3
|
||||
4 1 2 3 4 5 6
|
||||
1 2 3 4
|
||||
7 4 4
|
||||
4 1 2 3 4 5 6
|
||||
1 2 3 4
|
||||
11 5 3
|
||||
9 9 2 2 10 9 7 6 3 6 3
|
||||
6 9 7 8 10
|
||||
4 1 1
|
||||
4 1 5 6
|
||||
6
|
||||
8
codeforces/938/d.out
Normal file
8
codeforces/938/d.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
4
|
||||
3
|
||||
2
|
||||
4
|
||||
1
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.46129 ms
|
||||
119
codeforces/938/e.cc
Normal file
119
codeforces/938/e.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);
|
||||
}
|
||||
|
||||
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>;
|
||||
template <typename T, size_t N>
|
||||
using arr = std::array<T, N>;
|
||||
|
||||
#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;
|
||||
string s;
|
||||
cin >> s;
|
||||
|
||||
int ans = 1;
|
||||
|
||||
for (int k = sz<int>(s); k >= 2; --k) {
|
||||
string S = s;
|
||||
vec<int> toggle(S.size(), 0);
|
||||
|
||||
int cumulative = 0;
|
||||
for (int i = 0; i < sz<int>(S) - k; ++i) {
|
||||
cumulative += toggle[i];
|
||||
int actual = (S[i] - '0') ^ (cumulative & 1);
|
||||
if (actual == 0) {
|
||||
++cumulative;
|
||||
++toggle[i + k];
|
||||
}
|
||||
}
|
||||
|
||||
int zeroes = 0;
|
||||
for (int j = sz<int>(S) - k; j < sz<int>(S); ++j) {
|
||||
cumulative += toggle[j];
|
||||
int actual = (S[j] - '0') ^ (cumulative & 1);
|
||||
zeroes += actual == 0;
|
||||
}
|
||||
|
||||
if (zeroes == 0 || zeroes == k) {
|
||||
ans = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
11
codeforces/938/e.in
Normal file
11
codeforces/938/e.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
5
|
||||
5
|
||||
00100
|
||||
5
|
||||
01000
|
||||
7
|
||||
1011101
|
||||
3
|
||||
000
|
||||
2
|
||||
10
|
||||
10
codeforces/938/e.out
Normal file
10
codeforces/938/e.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
3
|
||||
2
|
||||
4
|
||||
3
|
||||
1
|
||||
|
||||
[code]: 0
|
||||
[code]: 0
|
||||
[time]: 8.4703 ms
|
||||
[time]: 2.82001 ms
|
||||
95
codeforces/938/f.cc
Normal file
95
codeforces/938/f.cc
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
#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>;
|
||||
template <typename T, size_t N>
|
||||
using arr = std::array<T, N>;
|
||||
|
||||
#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 ones, twos, threes, fours;
|
||||
cin >> ones >> twos >> threes >> fours;
|
||||
|
||||
ll ans = 0;
|
||||
|
||||
if (ones & 1 && twos & 1 && threes & 1)
|
||||
++ans;
|
||||
|
||||
ans += ones / 2 + twos / 2 + threes / 2 + fours / 2;
|
||||
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
6
codeforces/938/f.in
Normal file
6
codeforces/938/f.in
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
5
|
||||
1 1 1 0
|
||||
1 0 1 2
|
||||
2 2 2 0
|
||||
3 3 2 0
|
||||
0 9 9 9
|
||||
8
codeforces/938/f.out
Normal file
8
codeforces/938/f.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
1
|
||||
1
|
||||
3
|
||||
3
|
||||
12
|
||||
31783 ms
|
||||
[code]: 0
|
||||
[time]: 4.47631 ms
|
||||
240
codeforces/938/g.cc
Normal file
240
codeforces/938/g.cc
Normal file
|
|
@ -0,0 +1,240 @@
|
|||
#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>;
|
||||
template <typename T, size_t N>
|
||||
using arr = std::array<T, N>;
|
||||
|
||||
#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()
|
||||
// }}}
|
||||
|
||||
#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, m;
|
||||
cin >> n >> m;
|
||||
|
||||
vec<vec<int>> grid(n, vec<int>(m));
|
||||
|
||||
for (auto &row : grid) {
|
||||
for (auto &cell : row)
|
||||
cin >> cell;
|
||||
}
|
||||
|
||||
int x = gcd(grid[n - 1][m - 1], grid[0][0]);
|
||||
|
||||
vec<int> one, two;
|
||||
for (int i = 1; i * i <= x; ++i) {
|
||||
if (x % i == 0) {
|
||||
one.eb(i);
|
||||
if (i != x / i) {
|
||||
two.eb(x / i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vec<vec<bool>> dp(n, vec<bool>(m, false));
|
||||
|
||||
auto DP = [&](int factor) -> bool {
|
||||
for (int i = 0; i < sz<int>(dp); ++i)
|
||||
dp[i].assign(m, false);
|
||||
dp[0][0] = grid[0][0] % factor == 0;
|
||||
|
||||
for (int i = 0; i < n; ++i) {
|
||||
for (int j = 0; j < m; ++j) {
|
||||
if (grid[i][j] % factor) {
|
||||
continue;
|
||||
}
|
||||
if (j)
|
||||
dp[i][j] = dp[i][j] || dp[i][j - 1];
|
||||
if (i)
|
||||
dp[i][j] = dp[i][j] || dp[i - 1][j];
|
||||
}
|
||||
}
|
||||
|
||||
return dp[n - 1][m - 1];
|
||||
};
|
||||
|
||||
for (auto it = two.begin(); it != two.end(); ++it) {
|
||||
if (DP(*it)) {
|
||||
prln("{}", *it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = one.rbegin(); it != one.rend(); ++it) {
|
||||
if (DP(*it)) {
|
||||
prln("{}", *it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
11
codeforces/938/g.in
Normal file
11
codeforces/938/g.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
3
|
||||
2 3
|
||||
30 20 30
|
||||
15 25 40
|
||||
3 3
|
||||
12 4 9
|
||||
3 12 2
|
||||
8 3 12
|
||||
2 4
|
||||
2 4 6 8
|
||||
1 3 6 9
|
||||
6
codeforces/938/g.out
Normal file
6
codeforces/938/g.out
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
10
|
||||
3
|
||||
1
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.7426 ms
|
||||
Loading…
Add table
Add a link
Reference in a new issue