895
This commit is contained in:
parent
94383fbaf7
commit
26f66e43d8
97 changed files with 5337 additions and 42 deletions
9
codeforces/871/.clang-format
Normal file
9
codeforces/871/.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/871/.clangd
Normal file
8
codeforces/871/.clangd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
- -Wall
|
||||
- -Wextra
|
||||
- -Wpedantic
|
||||
- -Wshadow
|
||||
- -DLOCAL
|
||||
- -Wno-unknown-pragmas
|
||||
103
codeforces/871/a.cc
Normal file
103
codeforces/871/a.cc
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
[[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 codeforces = "codeforces";
|
||||
int ans = 0;
|
||||
char c;
|
||||
for (int i = 0; i < sz<int>(codeforces); ++i) {
|
||||
cin >> c;
|
||||
ans += c != codeforces[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;
|
||||
}
|
||||
// }}}
|
||||
6
codeforces/871/a.in
Normal file
6
codeforces/871/a.in
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
5
|
||||
coolforsez
|
||||
cadafurcie
|
||||
codeforces
|
||||
paiuforces
|
||||
forcescode
|
||||
10
codeforces/871/a.out
Normal file
10
codeforces/871/a.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
4
|
||||
5
|
||||
0
|
||||
4
|
||||
9
|
||||
|
||||
[code]: 0
|
||||
[code]: 0
|
||||
|
||||
[time]: 11.1115 ms[time]: 11.1079 ms
|
||||
110
codeforces/871/b.cc
Normal file
110
codeforces/871/b.cc
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
#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;
|
||||
int cur = 0;
|
||||
int ans = 0;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cin >> x;
|
||||
if (x == 1) {
|
||||
ans = max(ans, cur);
|
||||
cur = 0;
|
||||
} else
|
||||
++cur;
|
||||
}
|
||||
|
||||
ans = max(ans, cur);
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
11
codeforces/871/b.in
Normal file
11
codeforces/871/b.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
5
|
||||
5
|
||||
1 0 0 1 0
|
||||
4
|
||||
0 1 1 1
|
||||
1
|
||||
0
|
||||
3
|
||||
1 1 1
|
||||
9
|
||||
1 0 0 0 1 0 0 0 1
|
||||
8
codeforces/871/b.out
Normal file
8
codeforces/871/b.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
2
|
||||
1
|
||||
1
|
||||
0
|
||||
3
|
||||
|
||||
[code]: 0
|
||||
[time]: 13.2267 ms
|
||||
116
codeforces/871/c.cc
Normal file
116
codeforces/871/c.cc
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
#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;
|
||||
int m;
|
||||
int s;
|
||||
int best_both = 1e6, best_first = 1e6, best_second = 1e6;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cin >> m >> s;
|
||||
if (s == 11) {
|
||||
best_both = min(best_both, m);
|
||||
}
|
||||
if (s & 1) {
|
||||
best_first = min(best_first, m);
|
||||
}
|
||||
if (s > 9) {
|
||||
best_second = min(best_second, m);
|
||||
}
|
||||
}
|
||||
|
||||
int ans = min(best_both, best_first + best_second);
|
||||
|
||||
prln("{}", ans >= 1e6 ? -1 : ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
30
codeforces/871/c.in
Normal file
30
codeforces/871/c.in
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
6
|
||||
4
|
||||
2 00
|
||||
3 10
|
||||
4 01
|
||||
4 00
|
||||
5
|
||||
3 01
|
||||
3 01
|
||||
5 01
|
||||
2 10
|
||||
9 10
|
||||
1
|
||||
5 11
|
||||
3
|
||||
9 11
|
||||
8 01
|
||||
7 10
|
||||
6
|
||||
4 01
|
||||
6 01
|
||||
7 01
|
||||
8 00
|
||||
9 01
|
||||
1 00
|
||||
4
|
||||
8 00
|
||||
9 10
|
||||
9 11
|
||||
8 11
|
||||
9
codeforces/871/c.out
Normal file
9
codeforces/871/c.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
7
|
||||
5
|
||||
5
|
||||
9
|
||||
-1
|
||||
8
|
||||
|
||||
[code]: 0
|
||||
[time]: 15.1625 ms
|
||||
6
codeforces/871/compile_flags.txt
Normal file
6
codeforces/871/compile_flags.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-DLOCAL
|
||||
-std=c++23
|
||||
112
codeforces/871/d.cc
Normal file
112
codeforces/871/d.cc
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
#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()
|
||||
// }}}
|
||||
|
||||
bool recurse(int N, int M) {
|
||||
if (M == N)
|
||||
return true;
|
||||
if (M > N || N % 3)
|
||||
return false;
|
||||
return recurse(N / 3, M) || recurse(N / 3 * 2, M);
|
||||
// NOTE: recurrence relation knowledge weak, wasn't convinced
|
||||
// + mathematical derivation completely broke
|
||||
}
|
||||
|
||||
void solve() {
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
if (recurse(n, m)) {
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
12
codeforces/871/d.in
Normal file
12
codeforces/871/d.in
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
11
|
||||
6 4
|
||||
9 4
|
||||
4 2
|
||||
18 27
|
||||
27 4
|
||||
27 2
|
||||
27 10
|
||||
1 1
|
||||
3 1
|
||||
5 1
|
||||
746001 2984004
|
||||
14
codeforces/871/d.out
Normal file
14
codeforces/871/d.out
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
YES
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.9371 ms
|
||||
164
codeforces/871/e.cc
Normal file
164
codeforces/871/e.cc
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
#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()
|
||||
// }}}
|
||||
|
||||
ve<pa<int, int>> dxdy = {{-1, 0}, {0, 1}, {0, -1}, {1, 0}};
|
||||
|
||||
template <typename T>
|
||||
struct union_find {
|
||||
public:
|
||||
explicit union_find(size_t capacity)
|
||||
: par(capacity, 0), rank(capacity, 0), sums(capacity, 0) {
|
||||
std::iota(par.begin(), par.end(), 0);
|
||||
};
|
||||
|
||||
void join(T u, T v) noexcept {
|
||||
u = find(u), v = find(v);
|
||||
|
||||
if (u == v)
|
||||
return;
|
||||
|
||||
if (rank[u] < rank[v])
|
||||
std::swap(u, v);
|
||||
|
||||
if (rank[u] == rank[v])
|
||||
++rank[u];
|
||||
|
||||
// NOTE the double counting + joining before collecting value in the union find
|
||||
sums[u] += sums[v];
|
||||
|
||||
par[v] = u;
|
||||
}
|
||||
|
||||
void insert(T const& u, T const& val) {
|
||||
sums[u] = val;
|
||||
}
|
||||
|
||||
[[nodiscard]] T find(T const& u) noexcept {
|
||||
if (u != par[u])
|
||||
par[u] = find(par[u]);
|
||||
return par[u];
|
||||
}
|
||||
|
||||
std::vector<T> par;
|
||||
std::vector<int> rank;
|
||||
std::vector<int> sums;
|
||||
};
|
||||
|
||||
void solve() {
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
union_find<int> uf(n * m);
|
||||
ve<ve<int>> grid(n, ve<int>(m));
|
||||
auto index = [&](int r, int c) {
|
||||
return r * m + c;
|
||||
};
|
||||
for (int r = 0; r < n; ++r) {
|
||||
for (int c = 0; c < m; ++c) {
|
||||
cin >> grid[r][c];
|
||||
uf.insert(index(r, c), grid[r][c]);
|
||||
}
|
||||
}
|
||||
for (int r = 0; r < n; ++r) {
|
||||
for (int c = 0; c < m; ++c) {
|
||||
if (grid[r][c]) {
|
||||
for (auto& [dr, dc] : dxdy) {
|
||||
auto nr = r + dr, nc = c + dc;
|
||||
if (min(nr, nc) >= 0 && nr < n && nc < m && grid[nr][nc]) {
|
||||
uf.join(index(r, c), index(nr, nc));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
prln("{}", *max_element(all(uf.sums)));
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
23
codeforces/871/e.in
Normal file
23
codeforces/871/e.in
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
5
|
||||
3 3
|
||||
1 2 0
|
||||
3 4 0
|
||||
0 0 5
|
||||
1 1
|
||||
0
|
||||
3 3
|
||||
0 1 1
|
||||
1 0 1
|
||||
1 1 1
|
||||
5 5
|
||||
1 1 1 1 1
|
||||
1 0 0 0 1
|
||||
1 0 5 0 1
|
||||
1 0 0 0 1
|
||||
1 1 1 1 1
|
||||
5 5
|
||||
1 1 1 1 1
|
||||
1 0 0 0 1
|
||||
1 1 4 0 1
|
||||
1 0 0 0 1
|
||||
1 1 1 1 1
|
||||
8
codeforces/871/e.out
Normal file
8
codeforces/871/e.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
10
|
||||
0
|
||||
7
|
||||
16
|
||||
21
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.769 ms
|
||||
121
codeforces/871/f.cc
Normal file
121
codeforces/871/f.cc
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
#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, m;
|
||||
cin >> n >> m;
|
||||
ve<int> out(n + 1, 0);
|
||||
ve<ve<int>> G(n + 1);
|
||||
while (m--) {
|
||||
int u, v;
|
||||
cin >> u >> v;
|
||||
++out[u];
|
||||
++out[v];
|
||||
G[u].eb(v);
|
||||
G[v].eb(u);
|
||||
}
|
||||
|
||||
for (int u = 1; u <= n; ++u) {
|
||||
if (out[u] == 1) {
|
||||
int v = G[u][0];
|
||||
int y = out[v] - 1;
|
||||
for (auto w : G[v]) {
|
||||
if (out[w] > 1) {
|
||||
int x = out[w];
|
||||
prln("{} {}", x, y);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
38
codeforces/871/f.in
Normal file
38
codeforces/871/f.in
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
3
|
||||
21 20
|
||||
21 20
|
||||
5 20
|
||||
13 20
|
||||
1 3
|
||||
11 3
|
||||
10 3
|
||||
4 8
|
||||
19 8
|
||||
14 8
|
||||
9 7
|
||||
12 7
|
||||
17 7
|
||||
18 6
|
||||
16 6
|
||||
2 6
|
||||
6 15
|
||||
7 15
|
||||
8 15
|
||||
20 15
|
||||
3 15
|
||||
7 6
|
||||
1 2
|
||||
1 3
|
||||
2 4
|
||||
2 5
|
||||
3 6
|
||||
3 7
|
||||
9 8
|
||||
9 3
|
||||
3 6
|
||||
6 2
|
||||
2 1
|
||||
5 2
|
||||
2 7
|
||||
4 3
|
||||
3 8
|
||||
6
codeforces/871/f.out
Normal file
6
codeforces/871/f.out
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
5 3
|
||||
2 2
|
||||
2 3
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.9485 ms
|
||||
124
codeforces/871/g.cc
Normal file
124
codeforces/871/g.cc
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
#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;
|
||||
ll l = 1, r = 1e6;
|
||||
while (l <= r) {
|
||||
ll m = l + (r - l) / 2;
|
||||
if (m * (m + 1) / 2 >= n) {
|
||||
r = m - 1;
|
||||
} else {
|
||||
l = m + 1;
|
||||
}
|
||||
}
|
||||
auto sumsq = [](ll x) {
|
||||
return x * (x + 1) * (2 * x + 1) / 6;
|
||||
};
|
||||
ll level = l;
|
||||
ll ans = 0;
|
||||
l = r = level - (level * (level + 1) / 2 - n) - 1;
|
||||
while (level > 0) {
|
||||
l = max(0LL, l);
|
||||
r = min(r, level - 1);
|
||||
|
||||
auto left = level * (level + 1) / 2 - level + 1;
|
||||
ans -= sumsq(left + l - 1);
|
||||
ans += sumsq(left + r);
|
||||
|
||||
--l;
|
||||
--level;
|
||||
}
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
11
codeforces/871/g.in
Normal file
11
codeforces/871/g.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
10
|
||||
9
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
10
|
||||
1434
|
||||
1000000
|
||||
13
codeforces/871/g.out
Normal file
13
codeforces/871/g.out
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
156
|
||||
1
|
||||
5
|
||||
10
|
||||
21
|
||||
39
|
||||
46
|
||||
146
|
||||
63145186
|
||||
58116199242129511
|
||||
|
||||
[code]: 0
|
||||
[time]: 15.1484 ms
|
||||
Loading…
Add table
Add a link
Reference in a new issue