feat(cf): 952
This commit is contained in:
parent
0cb0d11ba9
commit
ceda5687f2
30 changed files with 1302 additions and 12 deletions
9
codeforces/952/.clang-format
Normal file
9
codeforces/952/.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/952/.clangd
Normal file
8
codeforces/952/.clangd
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
CompileFlags:
|
||||||
|
Add:
|
||||||
|
- -std=c++20
|
||||||
|
- -Wall
|
||||||
|
- -Wextra
|
||||||
|
- -Wpedantic
|
||||||
|
- -Wshadow
|
||||||
|
- -Wno-unknown-pragmas
|
||||||
99
codeforces/952/a.cc
Normal file
99
codeforces/952/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... Args>
|
||||||
|
void dbg(std::string const &str, Args &&...args) {
|
||||||
|
std::cout << std::vformat(str, std::make_format_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void dbg(T const &t) {
|
||||||
|
std::cout << t;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <std::ranges::range T>
|
||||||
|
void dbgln(T const &t) {
|
||||||
|
if constexpr (std::is_convertible_v<T, char const *>) {
|
||||||
|
std::cout << t << '\n';
|
||||||
|
} else {
|
||||||
|
for (auto const &e : t) {
|
||||||
|
std::cout << e << ' ';
|
||||||
|
}
|
||||||
|
std::cout << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbgln() {
|
||||||
|
std::cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
void dbgln(std::string const &str, Args &&...args) {
|
||||||
|
dbg(str, std::forward<Args>(args)...);
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void dbgln(T const &t) {
|
||||||
|
dbg(t);
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static T sc(auto &&x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ff first
|
||||||
|
#define ss second
|
||||||
|
#define eb emplace_back
|
||||||
|
#define ll long long
|
||||||
|
#define ld long double
|
||||||
|
#define vec vector
|
||||||
|
#define endl '\n'
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (r).rbegin(), (x).rend()
|
||||||
|
#define sz(x) static_cast<int>((x).size())
|
||||||
|
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
|
||||||
|
#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a))
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
string a, b;
|
||||||
|
cin >> a >> b;
|
||||||
|
dbg(b[0]);
|
||||||
|
FOR(i, 1, sz(a)) {
|
||||||
|
dbg(a[i]);
|
||||||
|
}
|
||||||
|
dbg(' ');
|
||||||
|
dbg(a[0]);
|
||||||
|
FOR(i, 1, sz(b)) {
|
||||||
|
dbg(b[i]);
|
||||||
|
}
|
||||||
|
dbgln();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
|
||||||
|
int t = 1;
|
||||||
|
cin >> t;
|
||||||
|
|
||||||
|
while (t--) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
7
codeforces/952/a.in
Normal file
7
codeforces/952/a.in
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
6
|
||||||
|
bit set
|
||||||
|
cat dog
|
||||||
|
hot dog
|
||||||
|
uwu owo
|
||||||
|
cat cat
|
||||||
|
zzz zzz
|
||||||
9
codeforces/952/a.out
Normal file
9
codeforces/952/a.out
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
sit bet
|
||||||
|
dat cog
|
||||||
|
dot hog
|
||||||
|
owu uwo
|
||||||
|
cat cat
|
||||||
|
zzz zzz
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 4.55022 ms
|
||||||
106
codeforces/952/b.cc
Normal file
106
codeforces/952/b.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... Args>
|
||||||
|
void dbg(std::string const &str, Args &&...args) {
|
||||||
|
std::cout << std::vformat(str, std::make_format_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void dbg(T const &t) {
|
||||||
|
std::cout << t;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <std::ranges::range T>
|
||||||
|
void dbgln(T const &t) {
|
||||||
|
if constexpr (std::is_convertible_v<T, char const *>) {
|
||||||
|
std::cout << t << '\n';
|
||||||
|
} else {
|
||||||
|
for (auto const &e : t) {
|
||||||
|
std::cout << e << ' ';
|
||||||
|
}
|
||||||
|
std::cout << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbgln() {
|
||||||
|
std::cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
void dbgln(std::string const &str, Args &&...args) {
|
||||||
|
dbg(str, std::forward<Args>(args)...);
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void dbgln(T const &t) {
|
||||||
|
dbg(t);
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static T sc(auto &&x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ff first
|
||||||
|
#define ss second
|
||||||
|
#define eb emplace_back
|
||||||
|
#define ll long long
|
||||||
|
#define ld long double
|
||||||
|
#define vec vector
|
||||||
|
#define endl '\n'
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (r).rbegin(), (x).rend()
|
||||||
|
#define sz(x) static_cast<int>((x).size())
|
||||||
|
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
|
||||||
|
#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a))
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
int n;
|
||||||
|
cin >> n;
|
||||||
|
|
||||||
|
int ans = 0, big = 0;
|
||||||
|
|
||||||
|
FOR(x, 2, n + 1) {
|
||||||
|
int total = 0;
|
||||||
|
int k = 1;
|
||||||
|
while (k * x <= n) {
|
||||||
|
total += k * x;
|
||||||
|
++k;
|
||||||
|
}
|
||||||
|
if (total > big) {
|
||||||
|
big = total;
|
||||||
|
ans = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dbgln(ans);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
|
||||||
|
int t = 1;
|
||||||
|
cin >> t;
|
||||||
|
|
||||||
|
while (t--) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
3
codeforces/952/b.in
Normal file
3
codeforces/952/b.in
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
2
|
||||||
|
3
|
||||||
|
15
|
||||||
5
codeforces/952/b.out
Normal file
5
codeforces/952/b.out
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
3
|
||||||
|
2
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 4.70328 ms
|
||||||
209
codeforces/952/c.cc
Normal file
209
codeforces/952/c.cc
Normal file
|
|
@ -0,0 +1,209 @@
|
||||||
|
#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... Args>
|
||||||
|
void dbg(std::string const &str, Args &&...args) {
|
||||||
|
std::cout << std::vformat(str, std::make_format_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void dbg(T const &t) {
|
||||||
|
std::cout << t;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <std::ranges::range T>
|
||||||
|
void dbgln(T const &t) {
|
||||||
|
if constexpr (std::is_convertible_v<T, char const *>) {
|
||||||
|
std::cout << t << '\n';
|
||||||
|
} else {
|
||||||
|
for (auto const &e : t) {
|
||||||
|
std::cout << e << ' ';
|
||||||
|
}
|
||||||
|
std::cout << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbgln() {
|
||||||
|
std::cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
void dbgln(std::string const &str, Args &&...args) {
|
||||||
|
dbg(str, std::forward<Args>(args)...);
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void dbgln(T const &t) {
|
||||||
|
dbg(t);
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static T sc(auto &&x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ff first
|
||||||
|
#define ss second
|
||||||
|
#define eb emplace_back
|
||||||
|
#define ll long long
|
||||||
|
#define ld long double
|
||||||
|
#define vec vector
|
||||||
|
#define endl '\n'
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (r).rbegin(), (x).rend()
|
||||||
|
#define sz(x) static_cast<int>((x).size())
|
||||||
|
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
|
||||||
|
#define ROF(a, b, c) for (int(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>
|
||||||
|
using hashmap = 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>>;
|
||||||
|
template <class Key>
|
||||||
|
using hashset = gp_hash_table<
|
||||||
|
Key, null_type, 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;
|
||||||
|
|
||||||
|
ll ans = 0;
|
||||||
|
|
||||||
|
ll prefix = 0;
|
||||||
|
hashset<ll> seen;
|
||||||
|
|
||||||
|
FOR(i, 0, n) {
|
||||||
|
ll x;
|
||||||
|
cin >> x;
|
||||||
|
prefix += x;
|
||||||
|
seen.insert(x);
|
||||||
|
ans += (prefix % 2 == 0) && seen.find(prefix / 2) != seen.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
dbgln(ans);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
|
||||||
|
int t = 1;
|
||||||
|
cin >> t;
|
||||||
|
|
||||||
|
while (t--) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
15
codeforces/952/c.in
Normal file
15
codeforces/952/c.in
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
7
|
||||||
|
1
|
||||||
|
0
|
||||||
|
1
|
||||||
|
1
|
||||||
|
4
|
||||||
|
1 1 2 0
|
||||||
|
5
|
||||||
|
0 1 2 1 4
|
||||||
|
7
|
||||||
|
1 1 0 3 5 2 12
|
||||||
|
7
|
||||||
|
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 294967296
|
||||||
|
10
|
||||||
|
0 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 589934592
|
||||||
10
codeforces/952/c.out
Normal file
10
codeforces/952/c.out
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
1
|
||||||
|
0
|
||||||
|
3
|
||||||
|
3
|
||||||
|
4
|
||||||
|
1
|
||||||
|
2
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 4.12488 ms
|
||||||
5
codeforces/952/compile_flags.txt
Normal file
5
codeforces/952/compile_flags.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
-std=c++20
|
||||||
|
-Wall
|
||||||
|
-Wextra
|
||||||
|
-Wpedantic
|
||||||
|
-Wshadow
|
||||||
107
codeforces/952/d.cc
Normal file
107
codeforces/952/d.cc
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
void dbg(std::string const &str, Args &&...args) {
|
||||||
|
std::cout << std::vformat(str, std::make_format_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void dbg(T const &t) {
|
||||||
|
std::cout << t;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <std::ranges::range T>
|
||||||
|
void dbgln(T const &t) {
|
||||||
|
if constexpr (std::is_convertible_v<T, char const *>) {
|
||||||
|
std::cout << t << '\n';
|
||||||
|
} else {
|
||||||
|
for (auto const &e : t) {
|
||||||
|
std::cout << e << ' ';
|
||||||
|
}
|
||||||
|
std::cout << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbgln() {
|
||||||
|
std::cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
void dbgln(std::string const &str, Args &&...args) {
|
||||||
|
dbg(str, std::forward<Args>(args)...);
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void dbgln(T const &t) {
|
||||||
|
dbg(t);
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static T sc(auto &&x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ff first
|
||||||
|
#define ss second
|
||||||
|
#define eb emplace_back
|
||||||
|
#define ll long long
|
||||||
|
#define ld long double
|
||||||
|
#define vec vector
|
||||||
|
#define endl '\n'
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (r).rbegin(), (x).rend()
|
||||||
|
#define sz(x) static_cast<int>((x).size())
|
||||||
|
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
|
||||||
|
#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a))
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
int n, m;
|
||||||
|
cin >> n >> m;
|
||||||
|
int bot = -1, top;
|
||||||
|
int left = -1, right;
|
||||||
|
FOR(r, 0, n) {
|
||||||
|
string s;
|
||||||
|
cin >> s;
|
||||||
|
FOR(c, 0, m) {
|
||||||
|
if (s[c] == '#') {
|
||||||
|
if (bot == -1)
|
||||||
|
bot = r;
|
||||||
|
top = r;
|
||||||
|
if (left == -1)
|
||||||
|
left = c;
|
||||||
|
right = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dbgln("{} {}", bot + (top - bot) / 2 + 1, left + (right - left) / 2 + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
|
||||||
|
int t = 1;
|
||||||
|
cin >> t;
|
||||||
|
|
||||||
|
while (t--) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
30
codeforces/952/d.in
Normal file
30
codeforces/952/d.in
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
6
|
||||||
|
5 5
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
..#..
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
5 5
|
||||||
|
..#..
|
||||||
|
.###.
|
||||||
|
#####
|
||||||
|
.###.
|
||||||
|
..#..
|
||||||
|
5 6
|
||||||
|
......
|
||||||
|
......
|
||||||
|
.#....
|
||||||
|
###...
|
||||||
|
.#....
|
||||||
|
1 1
|
||||||
|
#
|
||||||
|
5 6
|
||||||
|
...#..
|
||||||
|
..###.
|
||||||
|
.#####
|
||||||
|
..###.
|
||||||
|
...#..
|
||||||
|
2 10
|
||||||
|
..........
|
||||||
|
...#......
|
||||||
9
codeforces/952/d.out
Normal file
9
codeforces/952/d.out
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
3 3
|
||||||
|
3 3
|
||||||
|
4 2
|
||||||
|
1 1
|
||||||
|
3 4
|
||||||
|
2 4
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 4.17209 ms
|
||||||
111
codeforces/952/e.cc
Normal file
111
codeforces/952/e.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... Args>
|
||||||
|
void dbg(std::string const &str, Args &&...args) {
|
||||||
|
std::cout << std::vformat(str, std::make_format_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void dbg(T const &t) {
|
||||||
|
std::cout << t;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <std::ranges::range T>
|
||||||
|
void dbgln(T const &t) {
|
||||||
|
if constexpr (std::is_convertible_v<T, char const *>) {
|
||||||
|
std::cout << t << '\n';
|
||||||
|
} else {
|
||||||
|
for (auto const &e : t) {
|
||||||
|
std::cout << e << ' ';
|
||||||
|
}
|
||||||
|
std::cout << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbgln() {
|
||||||
|
std::cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
void dbgln(std::string const &str, Args &&...args) {
|
||||||
|
dbg(str, std::forward<Args>(args)...);
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void dbgln(T const &t) {
|
||||||
|
dbg(t);
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static T sc(auto &&x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ff first
|
||||||
|
#define ss second
|
||||||
|
#define eb emplace_back
|
||||||
|
#define ll long long
|
||||||
|
#define ld long double
|
||||||
|
#define vec vector
|
||||||
|
#define endl '\n'
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (r).rbegin(), (x).rend()
|
||||||
|
#define sz(x) static_cast<int>((x).size())
|
||||||
|
#define FOR(a, b, c) for (ll(a) = (b); (a) < (c); ++(a))
|
||||||
|
#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a))
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
ll x, y, z, k;
|
||||||
|
cin >> x >> y >> z >> k;
|
||||||
|
/*
|
||||||
|
vol = k <= x * y * z
|
||||||
|
|
||||||
|
explore all valid box volumes at 0, 0, 0
|
||||||
|
|
||||||
|
a * b * c = k
|
||||||
|
a * b = k / c <-> c = k / (a * b)
|
||||||
|
a=1 -> b * c <= k - bsearch?
|
||||||
|
*/
|
||||||
|
|
||||||
|
ll ans = 0;
|
||||||
|
|
||||||
|
FOR(a, 1, x + 1) {
|
||||||
|
FOR(b, 1, y + 1) {
|
||||||
|
ll total = a * b;
|
||||||
|
if (k % total == 0 && k / total <= z) {
|
||||||
|
ans = max(ans, (x - a + 1) * (y - b + 1) * (z - k / total + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dbgln(ans);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
|
||||||
|
int t = 1;
|
||||||
|
cin >> t;
|
||||||
|
|
||||||
|
while (t--) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
8
codeforces/952/e.in
Normal file
8
codeforces/952/e.in
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
7
|
||||||
|
3 3 3 8
|
||||||
|
3 3 3 18
|
||||||
|
5 1 1 1
|
||||||
|
2 2 2 7
|
||||||
|
3 4 2 12
|
||||||
|
4 3 1 6
|
||||||
|
1800 1800 1800 4913000000
|
||||||
10
codeforces/952/e.out
Normal file
10
codeforces/952/e.out
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
8
|
||||||
|
2
|
||||||
|
5
|
||||||
|
0
|
||||||
|
4
|
||||||
|
4
|
||||||
|
1030301
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 10.1058 ms
|
||||||
120
codeforces/952/f.cc
Normal file
120
codeforces/952/f.cc
Normal file
|
|
@ -0,0 +1,120 @@
|
||||||
|
#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... Args>
|
||||||
|
void dbg(std::string const &str, Args &&...args) {
|
||||||
|
std::cout << std::vformat(str, std::make_format_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void dbg(T const &t) {
|
||||||
|
std::cout << t;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <std::ranges::range T>
|
||||||
|
void dbgln(T const &t) {
|
||||||
|
if constexpr (std::is_convertible_v<T, char const *>) {
|
||||||
|
std::cout << t << '\n';
|
||||||
|
} else {
|
||||||
|
for (auto const &e : t) {
|
||||||
|
std::cout << e << ' ';
|
||||||
|
}
|
||||||
|
std::cout << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbgln() {
|
||||||
|
std::cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
void dbgln(std::string const &str, Args &&...args) {
|
||||||
|
dbg(str, std::forward<Args>(args)...);
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void dbgln(T const &t) {
|
||||||
|
dbg(t);
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
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>
|
||||||
|
static T sc(auto &&x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ff first
|
||||||
|
#define ss second
|
||||||
|
#define eb emplace_back
|
||||||
|
#define ll long long
|
||||||
|
#define ld long double
|
||||||
|
#define vec vector
|
||||||
|
#define endl '\n'
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (r).rbegin(), (x).rend()
|
||||||
|
#define sz(x) static_cast<int>((x).size())
|
||||||
|
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
|
||||||
|
#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a))
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
ll h, n;
|
||||||
|
cin >> h >> n;
|
||||||
|
|
||||||
|
vec<pair<ll, ll>> a(n);
|
||||||
|
|
||||||
|
ll agg = 0;
|
||||||
|
ll maxcooldown = MIN<ll>;
|
||||||
|
|
||||||
|
FOR(i, 0, n) {
|
||||||
|
cin >> a[i].ss;
|
||||||
|
}
|
||||||
|
FOR(i, 0, n) {
|
||||||
|
cin >> a[i].ff;
|
||||||
|
agg += a[i].ss;
|
||||||
|
maxcooldown = max(maxcooldown, a[i].ff);
|
||||||
|
}
|
||||||
|
|
||||||
|
ll l = 0, r = maxcooldown * (ld)h / agg;
|
||||||
|
|
||||||
|
while (l <= r) {
|
||||||
|
ll t = l + (r - l) / 2;
|
||||||
|
ll total = 0;
|
||||||
|
for (auto [C, A] : a) {
|
||||||
|
total += A * (1 + t / C);
|
||||||
|
}
|
||||||
|
if (total >= h) {
|
||||||
|
r = t - 1;
|
||||||
|
} else {
|
||||||
|
l = t + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dbgln(l + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
|
||||||
|
int t = 1;
|
||||||
|
cin >> t;
|
||||||
|
|
||||||
|
while (t--) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
25
codeforces/952/f.in
Normal file
25
codeforces/952/f.in
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
8
|
||||||
|
3 2
|
||||||
|
2 1
|
||||||
|
2 1
|
||||||
|
5 2
|
||||||
|
2 1
|
||||||
|
2 1
|
||||||
|
50 3
|
||||||
|
5 6 7
|
||||||
|
5 6 7
|
||||||
|
50 3
|
||||||
|
2 2 2
|
||||||
|
3 3 3
|
||||||
|
90000 2
|
||||||
|
200000 200000
|
||||||
|
1 1
|
||||||
|
100000 1
|
||||||
|
1
|
||||||
|
200000
|
||||||
|
6 7
|
||||||
|
3 2 3 2 3 1 2
|
||||||
|
6 5 9 5 10 7 7
|
||||||
|
21 6
|
||||||
|
1 1 1 1 1 1
|
||||||
|
5 5 8 10 7 6
|
||||||
11
codeforces/952/f.out
Normal file
11
codeforces/952/f.out
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
1
|
||||||
|
3
|
||||||
|
15
|
||||||
|
25
|
||||||
|
1
|
||||||
|
19999800001
|
||||||
|
1
|
||||||
|
21
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 4.58527 ms
|
||||||
107
codeforces/952/g.cc
Normal file
107
codeforces/952/g.cc
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
void dbg(std::string const &str, Args &&...args) {
|
||||||
|
std::cout << std::vformat(str, std::make_format_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void dbg(T const &t) {
|
||||||
|
std::cout << t;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <std::ranges::range T>
|
||||||
|
void dbgln(T const &t) {
|
||||||
|
if constexpr (std::is_convertible_v<T, char const *>) {
|
||||||
|
std::cout << t << '\n';
|
||||||
|
} else {
|
||||||
|
for (auto const &e : t) {
|
||||||
|
std::cout << e << ' ';
|
||||||
|
}
|
||||||
|
std::cout << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbgln() {
|
||||||
|
std::cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
void dbgln(std::string const &str, Args &&...args) {
|
||||||
|
dbg(str, std::forward<Args>(args)...);
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void dbgln(T const &t) {
|
||||||
|
dbg(t);
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static T sc(auto &&x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ff first
|
||||||
|
#define ss second
|
||||||
|
#define eb emplace_back
|
||||||
|
#define ll long long
|
||||||
|
#define ld long double
|
||||||
|
#define vec vector
|
||||||
|
#define endl '\n'
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (r).rbegin(), (x).rend()
|
||||||
|
#define sz(x) static_cast<int>((x).size())
|
||||||
|
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
|
||||||
|
#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a))
|
||||||
|
|
||||||
|
constexpr int MOD = 1000000007;
|
||||||
|
|
||||||
|
long long power(long long a, long long b) {
|
||||||
|
long long ans = 1;
|
||||||
|
while (b > 0) {
|
||||||
|
if (b & 1)
|
||||||
|
ans = (ans % MOD * a % MOD) % MOD;
|
||||||
|
a = (a % MOD * a % MOD) % MOD;
|
||||||
|
b >>= 1;
|
||||||
|
}
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
// D(n) = sum digits of n
|
||||||
|
// D(k*n) = k*D(n)
|
||||||
|
|
||||||
|
ll l, r, k;
|
||||||
|
cin >> l >> r >> k;
|
||||||
|
|
||||||
|
dbgln((power(1 + 9 / k, r) - power(1 + 9 / k, l) + MOD) % MOD);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
|
||||||
|
int t = 1;
|
||||||
|
cin >> t;
|
||||||
|
|
||||||
|
while (t--) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
7
codeforces/952/g.in
Normal file
7
codeforces/952/g.in
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
6
|
||||||
|
0 1 4
|
||||||
|
0 2 7
|
||||||
|
1 2 1
|
||||||
|
1 2 3
|
||||||
|
582 74663 3
|
||||||
|
0 3 1
|
||||||
9
codeforces/952/g.out
Normal file
9
codeforces/952/g.out
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
2
|
||||||
|
3
|
||||||
|
90
|
||||||
|
12
|
||||||
|
974995667
|
||||||
|
999
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 12.0807 ms
|
||||||
208
codeforces/952/h.cc
Normal file
208
codeforces/952/h.cc
Normal file
|
|
@ -0,0 +1,208 @@
|
||||||
|
#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... Args>
|
||||||
|
void dbg(std::string const &str, Args &&...args) {
|
||||||
|
std::cout << std::vformat(str, std::make_format_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void dbg(T const &t) {
|
||||||
|
std::cout << t;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <std::ranges::range T>
|
||||||
|
void dbgln(T const &t) {
|
||||||
|
if constexpr (std::is_convertible_v<T, char const *>) {
|
||||||
|
std::cout << t << '\n';
|
||||||
|
} else {
|
||||||
|
for (auto const &e : t) {
|
||||||
|
std::cout << e << ' ';
|
||||||
|
}
|
||||||
|
std::cout << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbgln() {
|
||||||
|
std::cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
void dbgln(std::string const &str, Args &&...args) {
|
||||||
|
dbg(str, std::forward<Args>(args)...);
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void dbgln(T const &t) {
|
||||||
|
dbg(t);
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static T sc(auto &&x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ff first
|
||||||
|
#define ss second
|
||||||
|
#define eb emplace_back
|
||||||
|
#define ll long long
|
||||||
|
#define ld long double
|
||||||
|
#define vec vector
|
||||||
|
#define endl '\n'
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (r).rbegin(), (x).rend()
|
||||||
|
#define sz(x) static_cast<int>((x).size())
|
||||||
|
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
|
||||||
|
#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a))
|
||||||
|
|
||||||
|
struct union_find {
|
||||||
|
public:
|
||||||
|
union_find(size_t n) : par(n + 1), rank(n + 1, 0), size(n + 1, 0) {
|
||||||
|
std::iota(par.begin(), par.end(), 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
void join(int u, int v) {
|
||||||
|
u = find(u), v = find(v);
|
||||||
|
|
||||||
|
if (size[u] == 0)
|
||||||
|
size[u] = 1;
|
||||||
|
if (size[v] == 0)
|
||||||
|
size[v] = 1;
|
||||||
|
|
||||||
|
if (u == v)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (rank[u] < rank[v])
|
||||||
|
std::swap(u, v);
|
||||||
|
|
||||||
|
if (rank[u] == rank[v]) {
|
||||||
|
++rank[u];
|
||||||
|
}
|
||||||
|
size[u] += size[v];
|
||||||
|
|
||||||
|
par[v] = u;
|
||||||
|
}
|
||||||
|
|
||||||
|
int find(int u) {
|
||||||
|
if (u != par[u])
|
||||||
|
par[u] = find(par[u]);
|
||||||
|
return par[u];
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t capacity;
|
||||||
|
std::vector<int> par;
|
||||||
|
std::vector<int> rank;
|
||||||
|
std::vector<int> size;
|
||||||
|
};
|
||||||
|
|
||||||
|
vector<pair<int, int>> dirs;
|
||||||
|
|
||||||
|
vec<string> grid;
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
int n, m;
|
||||||
|
cin >> n >> m;
|
||||||
|
vec<bool> seen(n * m + 1, false);
|
||||||
|
|
||||||
|
grid.resize(n);
|
||||||
|
|
||||||
|
union_find uf(m * n);
|
||||||
|
|
||||||
|
auto index = [&m](int r, int c) {
|
||||||
|
return r * m + c;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto valid = [&](int r, int c) {
|
||||||
|
return min(r, c) >= 0 && r < n && c < m;
|
||||||
|
};
|
||||||
|
|
||||||
|
FOR(r, 0, n) {
|
||||||
|
cin >> grid[r];
|
||||||
|
}
|
||||||
|
|
||||||
|
FOR(r, 0, n) {
|
||||||
|
FOR(c, 0, m) {
|
||||||
|
if (grid[r][c] == '#') {
|
||||||
|
uf.join(index(r, c), index(r, c));
|
||||||
|
for (auto [dr, dc] : dirs) {
|
||||||
|
int nr = r + dr, nc = c + dc;
|
||||||
|
if (valid(nr, nc) && grid[nr][nc] == '#') {
|
||||||
|
uf.join(index(r, c), index(nr, nc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ll ans = 0;
|
||||||
|
|
||||||
|
FOR(r, 0, n) {
|
||||||
|
ll cur = 0;
|
||||||
|
seen.assign(sz(seen), false);
|
||||||
|
FOR(c, 0, m) {
|
||||||
|
cur += grid[r][c] == '.';
|
||||||
|
if (grid[r][c] == '.') {
|
||||||
|
FOR(dr, -1, 2) {
|
||||||
|
int nr = r + dr;
|
||||||
|
int i;
|
||||||
|
if (valid(nr, c) && !seen[i = uf.find(index(nr, c))]) {
|
||||||
|
cur += uf.size[i];
|
||||||
|
seen[i] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ans = max(ans, cur);
|
||||||
|
}
|
||||||
|
|
||||||
|
FOR(c, 0, m) {
|
||||||
|
ll cur = 0;
|
||||||
|
seen.assign(sz(seen), false);
|
||||||
|
FOR(r, 0, n) {
|
||||||
|
cur += grid[r][c] == '.';
|
||||||
|
FOR(dc, -1, 2) {
|
||||||
|
int nc = c + dc;
|
||||||
|
int i;
|
||||||
|
if (valid(r, nc) && !seen[i = uf.find(index(r, nc))]) {
|
||||||
|
cur += uf.size[i];
|
||||||
|
seen[i] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ans = max(ans, cur);
|
||||||
|
}
|
||||||
|
|
||||||
|
dbgln(ans);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
|
||||||
|
dirs.emplace_back(1, 0);
|
||||||
|
dirs.emplace_back(-1, 0);
|
||||||
|
dirs.emplace_back(0, 1);
|
||||||
|
dirs.emplace_back(0, -1);
|
||||||
|
|
||||||
|
int t = 1;
|
||||||
|
cin >> t;
|
||||||
|
|
||||||
|
while (t--) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
33
codeforces/952/h.in
Normal file
33
codeforces/952/h.in
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
6
|
||||||
|
1 1
|
||||||
|
.
|
||||||
|
4 2
|
||||||
|
..
|
||||||
|
#.
|
||||||
|
#.
|
||||||
|
.#
|
||||||
|
3 5
|
||||||
|
.#.#.
|
||||||
|
..#..
|
||||||
|
.#.#.
|
||||||
|
5 5
|
||||||
|
#...#
|
||||||
|
....#
|
||||||
|
#...#
|
||||||
|
.....
|
||||||
|
...##
|
||||||
|
6 6
|
||||||
|
.#..#.
|
||||||
|
#..#..
|
||||||
|
.#...#
|
||||||
|
#.#.#.
|
||||||
|
.#.##.
|
||||||
|
###..#
|
||||||
|
6 8
|
||||||
|
..#....#
|
||||||
|
.####.#.
|
||||||
|
###.#..#
|
||||||
|
.##.#.##
|
||||||
|
.#.##.##
|
||||||
|
#..##.#.
|
||||||
|
|
||||||
9
codeforces/952/h.out
Normal file
9
codeforces/952/h.out
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
1
|
||||||
|
6
|
||||||
|
9
|
||||||
|
11
|
||||||
|
15
|
||||||
|
30
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 3.87812 ms
|
||||||
8
codeforces/964/.clangd
Normal file
8
codeforces/964/.clangd
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
CompileFlags:
|
||||||
|
Add:
|
||||||
|
- -std=c++20
|
||||||
|
- -Wall
|
||||||
|
- -Wextra
|
||||||
|
- -Wpedantic
|
||||||
|
- -Wshadow
|
||||||
|
- -Wno-unknown-pragmas
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
14
|
|
||||||
3
|
|
||||||
4
|
|
||||||
7
|
|
||||||
10
|
|
||||||
12
|
|
||||||
1
|
|
||||||
18
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
5
|
6
|
||||||
6
|
6
|
||||||
36
|
36
|
||||||
263
|
324
|
||||||
1635429922
|
1678476632
|
||||||
|
|
||||||
24:10 03/02/25
|
[code]: 0
|
||||||
|
[time]: 11.8585 ms
|
||||||
Loading…
Add table
Add a link
Reference in a new issue