more cf
This commit is contained in:
parent
5fbc6203d0
commit
e9d0bc91a8
123 changed files with 3730 additions and 0 deletions
9
codeforces/1006/.clang-format
Normal file
9
codeforces/1006/.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/1006/.clangd
Normal file
8
codeforces/1006/.clangd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
- -Wall
|
||||
- -Wextra
|
||||
- -Wpedantic
|
||||
- -Wshadow
|
||||
- -DLOCAL
|
||||
- -Wno-unknown-pragmas
|
||||
101
codeforces/1006/a.cc
Normal file
101
codeforces/1006/a.cc
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
#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);
|
||||
}
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) prln(...)
|
||||
#define dbg(...) pr(...)
|
||||
#endif
|
||||
|
||||
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, k, p;
|
||||
cin >> n >> k >> p;
|
||||
|
||||
k = abs(k);
|
||||
|
||||
int ans = k / p;
|
||||
k -= p * ans;
|
||||
if (k) {
|
||||
++ans;
|
||||
}
|
||||
|
||||
cout << (ans > n ? -1 : ans) << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
9
codeforces/1006/a.in
Normal file
9
codeforces/1006/a.in
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
8
|
||||
21 100 10
|
||||
9 -420 42
|
||||
5 -7 2
|
||||
13 37 7
|
||||
10 0 49
|
||||
1 10 9
|
||||
7 -7 7
|
||||
20 31 1
|
||||
11
codeforces/1006/a.out
Normal file
11
codeforces/1006/a.out
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
10
|
||||
-1
|
||||
4
|
||||
6
|
||||
0
|
||||
-1
|
||||
1
|
||||
-1
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.3668 ms
|
||||
102
codeforces/1006/b.cc
Normal file
102
codeforces/1006/b.cc
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto &&x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto &&x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
void prln() {
|
||||
std::println();
|
||||
}
|
||||
|
||||
void prln(auto const &t) {
|
||||
std::println("{}", t);
|
||||
}
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) prln(...)
|
||||
#define dbg(...) pr(...)
|
||||
#endif
|
||||
|
||||
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;
|
||||
ll hyphen = 0, underscore = 0;
|
||||
for (auto c : s) {
|
||||
hyphen += c == '-';
|
||||
underscore += c != '-';
|
||||
}
|
||||
|
||||
ll left = hyphen / 2, right = hyphen / 2 + (hyphen & 1);
|
||||
|
||||
cout << left * right * underscore << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
17
codeforces/1006/b.in
Normal file
17
codeforces/1006/b.in
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
8
|
||||
3
|
||||
--_
|
||||
5
|
||||
__-__
|
||||
9
|
||||
--__-_---
|
||||
4
|
||||
_--_
|
||||
10
|
||||
_-_-_-_-_-
|
||||
7
|
||||
_------
|
||||
1
|
||||
-
|
||||
2
|
||||
_-
|
||||
11
codeforces/1006/b.out
Normal file
11
codeforces/1006/b.out
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
1
|
||||
0
|
||||
27
|
||||
2
|
||||
30
|
||||
9
|
||||
0
|
||||
0
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.301 ms
|
||||
130
codeforces/1006/c.cc
Normal file
130
codeforces/1006/c.cc
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
#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);
|
||||
}
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) prln(...)
|
||||
#define dbg(...) pr(...)
|
||||
#endif
|
||||
|
||||
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, x;
|
||||
cin >> n >> x;
|
||||
|
||||
ll cur = 0;
|
||||
|
||||
bool broken = false;
|
||||
if (n > 1) {
|
||||
cout << 0 << ' ';
|
||||
} else {
|
||||
cout << x << endl;
|
||||
return;
|
||||
}
|
||||
int a = 0;
|
||||
for (int i = 0; i < n - 2; ++i) {
|
||||
++cur;
|
||||
|
||||
if (broken || (cur | x) > x) {
|
||||
broken = true;
|
||||
}
|
||||
|
||||
if (broken) {
|
||||
cout << x;
|
||||
a |= x;
|
||||
} else {
|
||||
cout << cur;
|
||||
a |= cur;
|
||||
}
|
||||
cout << ' ';
|
||||
}
|
||||
|
||||
++cur;
|
||||
|
||||
if (broken) {
|
||||
cout << x;
|
||||
} else {
|
||||
if ((cur | x) <= x && (a | cur) == x) {
|
||||
cout << cur;
|
||||
} else
|
||||
cout << x;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
10
codeforces/1006/c.in
Normal file
10
codeforces/1006/c.in
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
9
|
||||
1 69
|
||||
7 7
|
||||
5 7
|
||||
7 3
|
||||
8 7
|
||||
3 52
|
||||
9 11
|
||||
6 15
|
||||
2 3
|
||||
12
codeforces/1006/c.out
Normal file
12
codeforces/1006/c.out
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
69
|
||||
0 1 2 3 4 5 6
|
||||
0 1 2 3 4
|
||||
0 1 2 3 3 3 3
|
||||
0 1 2 3 4 5 6 7
|
||||
0 52 52
|
||||
0 1 2 3 11 11 11 11 11
|
||||
0 1 2 3 4 15
|
||||
0 3
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.3029 ms
|
||||
6
codeforces/1006/compile_flags.txt
Normal file
6
codeforces/1006/compile_flags.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-DLOCAL
|
||||
-std=c++23
|
||||
108
codeforces/1006/d.cc
Normal file
108
codeforces/1006/d.cc
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
#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);
|
||||
}
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) prln(...)
|
||||
#define dbg(...) pr(...)
|
||||
#endif
|
||||
|
||||
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;
|
||||
vec<ll> a(n);
|
||||
for (auto &e : a) {
|
||||
cin >> e;
|
||||
}
|
||||
|
||||
arr<int, 3> ans{0, 0, 0};
|
||||
|
||||
for (int l = 0; l < sz<int>(a); ++l) {
|
||||
ll delta = 0;
|
||||
for (int r = l + 1; r < sz<int>(a); ++r) {
|
||||
delta += a[l] < a[r];
|
||||
delta -= a[l] > a[r];
|
||||
ans = min(ans, {delta, l, r});
|
||||
}
|
||||
}
|
||||
|
||||
prln("{} {}", ans[1] + 1, ans[2] + 1);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
19
codeforces/1006/d.in
Normal file
19
codeforces/1006/d.in
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
9
|
||||
7
|
||||
1 4 3 2 5 3 3
|
||||
6
|
||||
1 4 3 2 5 3
|
||||
8
|
||||
7 6 5 8 4 3 2 1
|
||||
10
|
||||
1 1 1 5 1 1 5 6 7 8
|
||||
2
|
||||
1337 69
|
||||
4
|
||||
2 1 2 1
|
||||
3
|
||||
998 244 353
|
||||
3
|
||||
1 2 1
|
||||
9
|
||||
1 1 2 3 5 8 13 21 34
|
||||
12
codeforces/1006/d.out
Normal file
12
codeforces/1006/d.out
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
2 7
|
||||
2 6
|
||||
1 8
|
||||
4 7
|
||||
1 2
|
||||
1 4
|
||||
1 3
|
||||
2 3
|
||||
1 2
|
||||
|
||||
[code]: 0
|
||||
[time]: 3.81064 ms
|
||||
115
codeforces/1006/e.cc
Normal file
115
codeforces/1006/e.cc
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
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);
|
||||
}
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) prln(...)
|
||||
#define dbg(...) pr(...)
|
||||
#endif
|
||||
|
||||
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 k;
|
||||
cin >> k;
|
||||
ll y = 0, x = 0;
|
||||
vec<pair<ll, ll>> ans;
|
||||
|
||||
while (k) {
|
||||
ll count = 0;
|
||||
|
||||
while (count * (count - 1) / 2 <= k) {
|
||||
++count;
|
||||
}
|
||||
|
||||
--count;
|
||||
|
||||
k -= count * (count - 1) / 2;
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
ans.eb(x, y++);
|
||||
}
|
||||
++x;
|
||||
}
|
||||
|
||||
cout << ans.size() << endl;
|
||||
for (auto [a, b] : ans) {
|
||||
cout << a << ' ' << b << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
4
codeforces/1006/e.in
Normal file
4
codeforces/1006/e.in
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
3
|
||||
1
|
||||
2
|
||||
3
|
||||
15
codeforces/1006/e.out
Normal file
15
codeforces/1006/e.out
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
2
|
||||
0 0
|
||||
0 1
|
||||
4
|
||||
0 0
|
||||
0 1
|
||||
1 2
|
||||
1 3
|
||||
3
|
||||
0 0
|
||||
0 1
|
||||
0 2
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.3349 ms
|
||||
9
cses/introductory-problems/.clang-format
Normal file
9
cses/introductory-problems/.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
cses/introductory-problems/.clangd
Normal file
8
cses/introductory-problems/.clangd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
- -Wall
|
||||
- -Wextra
|
||||
- -Wpedantic
|
||||
- -Wshadow
|
||||
- -DLOCAL
|
||||
- -Wno-unknown-pragmas
|
||||
67
cses/introductory-problems/apple-division.cc
Normal file
67
cses/introductory-problems/apple-division.cc
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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;
|
||||
vec<ll> a(n);
|
||||
for (auto& e : a) {
|
||||
cin >> e;
|
||||
}
|
||||
|
||||
auto rec = [&](auto&& self, int i, ll l, ll r) {
|
||||
if (i == n) {
|
||||
return abs(r - l);
|
||||
}
|
||||
|
||||
return min(self(self, i + 1, l + a[i], r), self(self, i + 1, l, r + a[i]));
|
||||
};
|
||||
|
||||
cout << rec(rec, 0, 0, 0);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
2
cses/introductory-problems/apple-division.in
Normal file
2
cses/introductory-problems/apple-division.in
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
3
|
||||
7 7 100
|
||||
3
cses/introductory-problems/apple-division.out
Normal file
3
cses/introductory-problems/apple-division.out
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
86
|
||||
[code]: 0
|
||||
[time]: 3.65114 ms
|
||||
98
cses/introductory-problems/chessboard-and-queens.cc
Normal file
98
cses/introductory-problems/chessboard-and-queens.cc
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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()
|
||||
// }}}
|
||||
|
||||
constexpr static int N = 8;
|
||||
|
||||
vec<string> board(N);
|
||||
|
||||
// SC: O(n) for recursive space + queens
|
||||
// TC: O(n*n*n) - every row every col check all queens
|
||||
|
||||
// NOTE: pruning
|
||||
ll backtrack(vec<int> &queens) {
|
||||
if (queens.size() == N) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
ll r = queens.size();
|
||||
ll ans = 0;
|
||||
for (int C = 0; C < N; ++C) {
|
||||
if (board[r][C] == '*')
|
||||
continue;
|
||||
bool bad = false;
|
||||
for (int qr = 0; qr < sz<int>(queens); ++qr) {
|
||||
int qc = queens[qr];
|
||||
// Q: does it fall on the DIAGONAL?
|
||||
// for each line, is there an integer sol'n?
|
||||
// y - qr = x - qc -> x - qc + qr <- n queens
|
||||
// or y - qr = -x + qc -> y = -x + qc + qr
|
||||
if (qc == C || abs(r - qr) == abs(C - qc)) {
|
||||
bad = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (bad)
|
||||
continue;
|
||||
queens.eb(C);
|
||||
ans += backtrack(queens);
|
||||
queens.pop_back();
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
void solve() {
|
||||
for (int i = 0; i < N; ++i) {
|
||||
cin >> board[i];
|
||||
}
|
||||
|
||||
vec<int> queens;
|
||||
ll ans = backtrack(queens);
|
||||
|
||||
cout << ans << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
8
cses/introductory-problems/chessboard-and-queens.in
Normal file
8
cses/introductory-problems/chessboard-and-queens.in
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
........
|
||||
........
|
||||
..*.....
|
||||
........
|
||||
........
|
||||
.....**.
|
||||
...*....
|
||||
........
|
||||
4
cses/introductory-problems/chessboard-and-queens.out
Normal file
4
cses/introductory-problems/chessboard-and-queens.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
65
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.8713 ms
|
||||
58
cses/introductory-problems/coin-piles.cc
Normal file
58
cses/introductory-problems/coin-piles.cc
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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 a, b;
|
||||
cin >> a >> b;
|
||||
|
||||
cout << (((a + b) % 3 == 0) && 2 * min(a, b) >= max(a, b) ? "YES\n" : "NO\n");
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
5
cses/introductory-problems/coin-piles.in
Normal file
5
cses/introductory-problems/coin-piles.in
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
4
|
||||
2 1
|
||||
2 2
|
||||
3 3
|
||||
11 4
|
||||
7
cses/introductory-problems/coin-piles.out
Normal file
7
cses/introductory-problems/coin-piles.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.4977 ms
|
||||
6
cses/introductory-problems/compile_flags.txt
Normal file
6
cses/introductory-problems/compile_flags.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-DLOCAL
|
||||
-std=c++20
|
||||
85
cses/introductory-problems/creating-strings.cc
Normal file
85
cses/introductory-problems/creating-strings.cc
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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 backtrack(vec<int>& freq, string& cur, vector<string>& ans, int len) {
|
||||
if (sz<int>(cur) == len) {
|
||||
ans.eb(cur);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < sz<int>(freq); ++i) {
|
||||
if (freq[i] == 0)
|
||||
continue;
|
||||
|
||||
--freq[i];
|
||||
|
||||
cur.push_back(i + 'a');
|
||||
backtrack(freq, cur, ans, len);
|
||||
cur.pop_back();
|
||||
|
||||
++freq[i];
|
||||
}
|
||||
}
|
||||
|
||||
void solve() {
|
||||
string s;
|
||||
cin >> s;
|
||||
|
||||
vec<int> m(26, 0);
|
||||
int len = s.size();
|
||||
for (auto c : s)
|
||||
++m[c - 'a'];
|
||||
|
||||
string cur = "";
|
||||
vec<string> ans;
|
||||
backtrack(m, cur, ans, len);
|
||||
cout << ans.size() << endl;
|
||||
for (auto& S : ans) {
|
||||
cout << S << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
1
cses/introductory-problems/creating-strings.in
Normal file
1
cses/introductory-problems/creating-strings.in
Normal file
|
|
@ -0,0 +1 @@
|
|||
abc
|
||||
10
cses/introductory-problems/creating-strings.out
Normal file
10
cses/introductory-problems/creating-strings.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
6
|
||||
abc
|
||||
acb
|
||||
bac
|
||||
bca
|
||||
cab
|
||||
cba
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.6973 ms
|
||||
85
cses/introductory-problems/digit-queries.cc
Normal file
85
cses/introductory-problems/digit-queries.cc
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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 q;
|
||||
cin >> q;
|
||||
while (q--) {
|
||||
ll k;
|
||||
cin >> k;
|
||||
if (k <= 9) {
|
||||
cout << k << endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
ll exp = 1;
|
||||
while (true) {
|
||||
ll numbers_in_band = 9 * powl(10, exp - 1);
|
||||
ll per = numbers_in_band * exp;
|
||||
|
||||
if (k <= per)
|
||||
break;
|
||||
|
||||
k -= per;
|
||||
exp++;
|
||||
}
|
||||
|
||||
ll i = (k - 1) / exp;
|
||||
ll index = k % exp;
|
||||
if (index == 0)
|
||||
index = exp;
|
||||
ll ans = powl(10, exp - 1) + i;
|
||||
ll offset = exp - index;
|
||||
while (offset--) {
|
||||
ans /= 10;
|
||||
}
|
||||
|
||||
cout << ans % 10 << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
8
cses/introductory-problems/digit-queries.in
Normal file
8
cses/introductory-problems/digit-queries.in
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
7
|
||||
5
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
10
cses/introductory-problems/digit-queries.out
Normal file
10
cses/introductory-problems/digit-queries.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
5
|
||||
1
|
||||
0
|
||||
1
|
||||
1
|
||||
1
|
||||
2
|
||||
|
||||
[code]: 0
|
||||
[time]: 10.8669 ms
|
||||
71
cses/introductory-problems/gray-code.cc
Normal file
71
cses/introductory-problems/gray-code.cc
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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()
|
||||
// }}}
|
||||
|
||||
vec<string> f(int n) {
|
||||
vec<string> gray{"0", "1"};
|
||||
|
||||
while (--n) {
|
||||
vec<string> copy(gray);
|
||||
reverse(all(copy));
|
||||
gray.insert(gray.end(), all(copy));
|
||||
for (int i = 0; i < sz<int>(gray); ++i)
|
||||
gray[i].push_back('0' + (i >= sz<int>(gray) >> 1));
|
||||
}
|
||||
return gray;
|
||||
}
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
vec<string> gray = f(n);
|
||||
for (auto s : gray) {
|
||||
cout << s << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
1
cses/introductory-problems/gray-code.in
Normal file
1
cses/introductory-problems/gray-code.in
Normal file
|
|
@ -0,0 +1 @@
|
|||
2
|
||||
8
cses/introductory-problems/gray-code.out
Normal file
8
cses/introductory-problems/gray-code.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
4
|
||||
00
|
||||
10
|
||||
11
|
||||
01
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.6062 ms
|
||||
108
cses/introductory-problems/grid-paths.cc
Normal file
108
cses/introductory-problems/grid-paths.cc
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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()
|
||||
// }}}
|
||||
|
||||
bitset<7 * 7 + 1> seen;
|
||||
|
||||
vec<pair<int, int>> dirs;
|
||||
unordered_map<char, pair<int, int>> dir_map{
|
||||
{'U', {-1, 0}}, {'D', {1, 0}}, {'L', {0, -1}}, {'R', {0, 1}}};
|
||||
|
||||
ll ans = 0;
|
||||
|
||||
string s;
|
||||
|
||||
void dfs(int r, int c, int i) {
|
||||
if (min(r, c) < 0 || max(r, c) > 6 || seen[r * 7 + c]) {
|
||||
return;
|
||||
}
|
||||
if (r == 6 && c == 0) {
|
||||
ans += i == 48;
|
||||
return;
|
||||
}
|
||||
seen[r * 7 + c] = true;
|
||||
bool up = (r > 0 && !seen[(r - 1) * 7 + c]);
|
||||
bool down = (r < 6 && !seen[(r + 1) * 7 + c]);
|
||||
bool left = (c > 0 && !seen[r * 7 + (c - 1)]);
|
||||
bool right = (c < 6 && !seen[r * 7 + (c + 1)]);
|
||||
|
||||
if ((up && down && !left && !right) || (!up && !down && left && right)) {
|
||||
seen[r * 7 + c] = false;
|
||||
return;
|
||||
}
|
||||
int open_count = up + down + left + right;
|
||||
if (open_count == 1) {
|
||||
if (up) dfs(r - 1, c, i + 1);
|
||||
else if (down) dfs(r + 1, c, i + 1);
|
||||
else if (left) dfs(r, c - 1, i + 1);
|
||||
else if (right) dfs(r, c + 1, i + 1);
|
||||
|
||||
seen[r * 7 + c] = false;
|
||||
return;
|
||||
}
|
||||
if (s[i] == '?') {
|
||||
for (auto& [dr, dc] : dirs) {
|
||||
dfs(r + dr, c + dc, i + 1);
|
||||
}
|
||||
} else {
|
||||
dfs(r + dir_map[s[i]].ff, c + dir_map[s[i]].ss, i + 1);
|
||||
}
|
||||
seen[r * 7 + c] = false;
|
||||
}
|
||||
|
||||
void solve() {
|
||||
dirs.eb(1, 0);
|
||||
dirs.eb(0, 1);
|
||||
dirs.eb(-1, 0);
|
||||
dirs.eb(0, -1);
|
||||
cin >> s;
|
||||
|
||||
dfs(0, 0, 0);
|
||||
|
||||
cout << ans << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
1
cses/introductory-problems/grid-paths.in
Normal file
1
cses/introductory-problems/grid-paths.in
Normal file
|
|
@ -0,0 +1 @@
|
|||
??????R??????U??????????????????????????LD????D?
|
||||
4
cses/introductory-problems/grid-paths.out
Normal file
4
cses/introductory-problems/grid-paths.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
5986
|
||||
|
||||
[code]: 0
|
||||
[time]: 557.243 ms
|
||||
65
cses/introductory-problems/increasing-array.cc
Normal file
65
cses/introductory-problems/increasing-array.cc
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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 ans = 0;
|
||||
int n;
|
||||
cin >> n;
|
||||
ll last = 0;
|
||||
while (n--) {
|
||||
ll x;
|
||||
cin >> x;
|
||||
if (last != 0 && last > x) {
|
||||
ans += last - x;
|
||||
x += last - x;
|
||||
}
|
||||
last = x;
|
||||
}
|
||||
cout << ans << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
2
cses/introductory-problems/increasing-array.in
Normal file
2
cses/introductory-problems/increasing-array.in
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
10
|
||||
1000000000 1 1 1 1 1 1 1 1 1
|
||||
4
cses/introductory-problems/increasing-array.out
Normal file
4
cses/introductory-problems/increasing-array.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
8999999991
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.4868 ms
|
||||
65
cses/introductory-problems/missing-number.cc
Normal file
65
cses/introductory-problems/missing-number.cc
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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;
|
||||
vec<bool> seen(n + 1, false);
|
||||
while (--n) {
|
||||
int x;
|
||||
cin >> x;
|
||||
seen[x] = true;
|
||||
}
|
||||
for (int i = 1; i < sz<int>(seen); ++i) {
|
||||
if (!seen[i]) {
|
||||
cout << i << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
2
cses/introductory-problems/missing-number.in
Normal file
2
cses/introductory-problems/missing-number.in
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
5
|
||||
2 3 1 5
|
||||
4
cses/introductory-problems/missing-number.out
Normal file
4
cses/introductory-problems/missing-number.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
4
|
||||
|
||||
[code]: 0
|
||||
[time]: 3.88908 ms
|
||||
62
cses/introductory-problems/number-spiral.cc
Normal file
62
cses/introductory-problems/number-spiral.cc
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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 x, y;
|
||||
cin >> y >> x;
|
||||
ll base = max(x, y);
|
||||
ll ans = base * base;
|
||||
if (ans & 1)
|
||||
swap(x, y);
|
||||
ans -= x - 1 + base - y;
|
||||
cout << ans << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
5
cses/introductory-problems/number-spiral.in
Normal file
5
cses/introductory-problems/number-spiral.in
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
4
|
||||
2 3
|
||||
1 1
|
||||
4 2
|
||||
2 4
|
||||
7
cses/introductory-problems/number-spiral.out
Normal file
7
cses/introductory-problems/number-spiral.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
8
|
||||
1
|
||||
15
|
||||
11
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.26793 ms
|
||||
81
cses/introductory-problems/palindrome-reorder.cc
Normal file
81
cses/introductory-problems/palindrome-reorder.cc
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
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() {
|
||||
string s;
|
||||
cin >> s;
|
||||
|
||||
unordered_map<char, int> m;
|
||||
for (auto c : s)
|
||||
++m[c];
|
||||
|
||||
int odd = 0;
|
||||
|
||||
string ans(s.size(), 'A');
|
||||
|
||||
int l = 0;
|
||||
|
||||
for (auto& [k, v] : m) {
|
||||
if (v & 1) {
|
||||
if (++odd == 2) {
|
||||
cout << "NO SOLUTION";
|
||||
return;
|
||||
}
|
||||
ans[ans.size() / 2] = k;
|
||||
--v;
|
||||
}
|
||||
while (v) {
|
||||
ans[l++] = k;
|
||||
ans[ans.size() - l] = k;
|
||||
v -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
cout << ans << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
1
cses/introductory-problems/palindrome-reorder.in
Normal file
1
cses/introductory-problems/palindrome-reorder.in
Normal file
|
|
@ -0,0 +1 @@
|
|||
AAABBB
|
||||
3
cses/introductory-problems/palindrome-reorder.out
Normal file
3
cses/introductory-problems/palindrome-reorder.out
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
NO SOLUTION
|
||||
[code]: 0
|
||||
[time]: 12.1081 ms
|
||||
76
cses/introductory-problems/permutations.cc
Normal file
76
cses/introductory-problems/permutations.cc
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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;
|
||||
/*
|
||||
n= 5;
|
||||
1 4 2 5 3
|
||||
1 4 2 5 3 6
|
||||
1 7 2 6 3 5 4
|
||||
|
||||
|
||||
41325
|
||||
*/
|
||||
|
||||
if (n == 1) {
|
||||
cout << 1 << endl;
|
||||
} else if (n <= 3) {
|
||||
cout << "NO SOLUTION\n";
|
||||
} else {
|
||||
for (int cur = n & 1 ? n - 1 : n; cur > 4; cur -= 2) {
|
||||
cout << cur << ' ';
|
||||
}
|
||||
cout << "2 4";
|
||||
for (int cur = 1; cur <= n; cur += 2) {
|
||||
cout << ' ' << cur;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
1
cses/introductory-problems/permutations.in
Normal file
1
cses/introductory-problems/permutations.in
Normal file
|
|
@ -0,0 +1 @@
|
|||
1
|
||||
4
cses/introductory-problems/permutations.out
Normal file
4
cses/introductory-problems/permutations.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
1
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.06551 ms
|
||||
60
cses/introductory-problems/repetitions.cc
Normal file
60
cses/introductory-problems/repetitions.cc
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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() {
|
||||
string s;
|
||||
cin >> s;
|
||||
|
||||
ll streak = 0, ans = 0;
|
||||
char last = ' ';
|
||||
for (auto c : s) {
|
||||
if (last == ' ' || last == c) {
|
||||
++streak;
|
||||
ans = max(ans, streak);
|
||||
} else {
|
||||
streak = 1;
|
||||
}
|
||||
last = c;
|
||||
}
|
||||
cout << ans << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
1
cses/introductory-problems/repetitions.in
Normal file
1
cses/introductory-problems/repetitions.in
Normal file
|
|
@ -0,0 +1 @@
|
|||
ABCDEF
|
||||
4
cses/introductory-problems/repetitions.out
Normal file
4
cses/introductory-problems/repetitions.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
1
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.20523 ms
|
||||
68
cses/introductory-problems/tower-of-hanoi.cc
Normal file
68
cses/introductory-problems/tower-of-hanoi.cc
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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;
|
||||
vec<pair<int, int>> ans;
|
||||
auto hanoi = [&](auto&& self, int src, int dest, int aux, int x) {
|
||||
if (x == 1) {
|
||||
ans.eb(src, dest);
|
||||
return;
|
||||
}
|
||||
self(self, src, aux, dest, x - 1);
|
||||
ans.eb(src, dest);
|
||||
self(self, aux, dest, src, x - 1);
|
||||
};
|
||||
hanoi(hanoi, 1, 3, 2, n);
|
||||
cout << ans.size() << endl;
|
||||
for (auto& [a, b] : ans) {
|
||||
cout << a << ' ' << b << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
1
cses/introductory-problems/tower-of-hanoi.in
Normal file
1
cses/introductory-problems/tower-of-hanoi.in
Normal file
|
|
@ -0,0 +1 @@
|
|||
2
|
||||
7
cses/introductory-problems/tower-of-hanoi.out
Normal file
7
cses/introductory-problems/tower-of-hanoi.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
3
|
||||
1 2
|
||||
1 3
|
||||
2 3
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.8749 ms
|
||||
72
cses/introductory-problems/trailing-zeroes.cc
Normal file
72
cses/introductory-problems/trailing-zeroes.cc
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/*
|
||||
every time 10 goes into it, + 1
|
||||
|
||||
1 * 2 * 3 * 4 * 5 <- 1
|
||||
|
||||
6 * 7 * 8 * 9 * 10
|
||||
|
||||
11 12 13 14 15
|
||||
16 17 18 19 20
|
||||
*/
|
||||
|
||||
int ans = 0;
|
||||
int b = 5;
|
||||
while (n / b) {
|
||||
ans += n / b;
|
||||
b *= 5;
|
||||
}
|
||||
cout << ans << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
1
cses/introductory-problems/trailing-zeroes.in
Normal file
1
cses/introductory-problems/trailing-zeroes.in
Normal file
|
|
@ -0,0 +1 @@
|
|||
239
|
||||
4
cses/introductory-problems/trailing-zeroes.out
Normal file
4
cses/introductory-problems/trailing-zeroes.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
57
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.5106 ms
|
||||
64
cses/introductory-problems/weird-algorithm.cc
Normal file
64
cses/introductory-problems/weird-algorithm.cc
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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;
|
||||
cin >> n;
|
||||
|
||||
while (n != 1) {
|
||||
cout << n << ' ';
|
||||
if (n & 1) {
|
||||
n = n * 3 + 1;
|
||||
} else {
|
||||
n /= 2;
|
||||
}
|
||||
}
|
||||
cout << 1 << endl;
|
||||
}
|
||||
|
||||
// {{{
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
1
cses/introductory-problems/weird-algorithm.in
Normal file
1
cses/introductory-problems/weird-algorithm.in
Normal file
|
|
@ -0,0 +1 @@
|
|||
3
|
||||
4
cses/introductory-problems/weird-algorithm.out
Normal file
4
cses/introductory-problems/weird-algorithm.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
3 10 5 16 8 4 2 1
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.0214 ms
|
||||
9
cses/sorting-and-searching/.clang-format
Normal file
9
cses/sorting-and-searching/.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
cses/sorting-and-searching/.clangd
Normal file
8
cses/sorting-and-searching/.clangd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
- -Wall
|
||||
- -Wextra
|
||||
- -Wpedantic
|
||||
- -Wshadow
|
||||
- -DLOCAL
|
||||
- -Wno-unknown-pragmas
|
||||
75
cses/sorting-and-searching/apartments.cc
Normal file
75
cses/sorting-and-searching/apartments.cc
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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, m, k;
|
||||
cin >> n >> m >> k;
|
||||
vec<ll> requests(n);
|
||||
for (auto& e : requests)
|
||||
cin >> e;
|
||||
vec<ll> sizes(m);
|
||||
for (auto& e : sizes)
|
||||
cin >> e;
|
||||
sort(all(requests));
|
||||
sort(all(sizes));
|
||||
|
||||
ll ans = 0;
|
||||
int size = 0;
|
||||
for (int request = 0; request < n && size < m; ++request) {
|
||||
while (size < m && sizes[size] + k < requests[request]) {
|
||||
++size;
|
||||
}
|
||||
if (sizes[size] - k <= requests[request] &&
|
||||
requests[request] <= sizes[size] + k) {
|
||||
++ans;
|
||||
++size;
|
||||
}
|
||||
}
|
||||
cout << ans << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
3
cses/sorting-and-searching/apartments.in
Normal file
3
cses/sorting-and-searching/apartments.in
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
10 10 10
|
||||
90 41 20 39 49 21 35 31 74 86
|
||||
14 24 24 7 82 85 82 4 60 95
|
||||
4
cses/sorting-and-searching/apartments.out
Normal file
4
cses/sorting-and-searching/apartments.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
6
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.7234 ms
|
||||
72
cses/sorting-and-searching/collecting-numbers.cc
Normal file
72
cses/sorting-and-searching/collecting-numbers.cc
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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()
|
||||
// }}}
|
||||
|
||||
int n;
|
||||
void solve() {
|
||||
cin >> n;
|
||||
vec<pair<ll, int>> a(n);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cin >> a[i].ff;
|
||||
a[i].ss = i;
|
||||
}
|
||||
sort(all(a), [](auto& l, auto& r) {
|
||||
return l.ff < r.ff;
|
||||
});
|
||||
ll ans = 1;
|
||||
int last_i = a[0].ss;
|
||||
|
||||
for (int i = 1; i < sz<int>(a); ++i) {
|
||||
if (a[i].ss < last_i) {
|
||||
++ans;
|
||||
}
|
||||
last_i = a[i].ss;
|
||||
}
|
||||
|
||||
cout << ans << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
2
cses/sorting-and-searching/collecting-numbers.in
Normal file
2
cses/sorting-and-searching/collecting-numbers.in
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
5
|
||||
4 2 1 5 3
|
||||
4
cses/sorting-and-searching/collecting-numbers.out
Normal file
4
cses/sorting-and-searching/collecting-numbers.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
3
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.512 ms
|
||||
6
cses/sorting-and-searching/compile_flags.txt
Normal file
6
cses/sorting-and-searching/compile_flags.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-DLOCAL
|
||||
-std=c++20
|
||||
172
cses/sorting-and-searching/concert-tickets.cc
Normal file
172
cses/sorting-and-searching/concert-tickets.cc
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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 multitree = 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<ll> a(n);
|
||||
for (auto &e : a)
|
||||
cin >> e;
|
||||
|
||||
multitree<ll> mm(all(a));
|
||||
|
||||
while (m--) {
|
||||
ll x;
|
||||
cin >> x;
|
||||
|
||||
auto i = mm.order_of_key(x + 1);
|
||||
if (i == 0)
|
||||
cout << -1 << endl;
|
||||
else {
|
||||
auto it = mm.find_by_order(i - 1);
|
||||
cout << *it << endl;
|
||||
mm.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
3
cses/sorting-and-searching/concert-tickets.in
Normal file
3
cses/sorting-and-searching/concert-tickets.in
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
5 3
|
||||
5 3 7 8 5
|
||||
4 8 3
|
||||
6
cses/sorting-and-searching/concert-tickets.out
Normal file
6
cses/sorting-and-searching/concert-tickets.out
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
3
|
||||
8
|
||||
-1
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.20356 ms
|
||||
162
cses/sorting-and-searching/distinct-numbers.cc
Normal file
162
cses/sorting-and-searching/distinct-numbers.cc
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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;
|
||||
cin >> n;
|
||||
ll x;
|
||||
ll ans = 0;
|
||||
set<ll> seen;
|
||||
while (n--) {
|
||||
cin >> x;
|
||||
if (seen.find(x) == seen.end())
|
||||
++ans;
|
||||
seen.insert(x);
|
||||
}
|
||||
cout << ans << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
2
cses/sorting-and-searching/distinct-numbers.in
Normal file
2
cses/sorting-and-searching/distinct-numbers.in
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
5
|
||||
2 3 2 2 3
|
||||
4
cses/sorting-and-searching/distinct-numbers.out
Normal file
4
cses/sorting-and-searching/distinct-numbers.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
2
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.4255 ms
|
||||
68
cses/sorting-and-searching/ferris-wheel.cc
Normal file
68
cses/sorting-and-searching/ferris-wheel.cc
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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, x;
|
||||
cin >> n >> x;
|
||||
vec<ll> a(n);
|
||||
for (auto &e : a)
|
||||
cin >> e;
|
||||
sort(all(a));
|
||||
int l = 0, r = sz<int>(a) - 1;
|
||||
|
||||
ll ans = n;
|
||||
while (l < r) {
|
||||
if (a[l] + a[r] <= x) {
|
||||
--ans;
|
||||
++l;
|
||||
}
|
||||
--r;
|
||||
}
|
||||
cout << ans << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
2
cses/sorting-and-searching/ferris-wheel.in
Normal file
2
cses/sorting-and-searching/ferris-wheel.in
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
4 10
|
||||
7 2 3 9
|
||||
4
cses/sorting-and-searching/ferris-wheel.out
Normal file
4
cses/sorting-and-searching/ferris-wheel.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
3
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.009 ms
|
||||
66
cses/sorting-and-searching/maximum-subarray-sum.cc
Normal file
66
cses/sorting-and-searching/maximum-subarray-sum.cc
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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()
|
||||
// }}}
|
||||
|
||||
ll n;
|
||||
void solve() {
|
||||
cin >> n;
|
||||
vec<ll> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
ll ans = a[0];
|
||||
ll cur = a[0];
|
||||
|
||||
for (int i = 1; i < n; ++i) {
|
||||
cur = max(cur + a[i], a[i]);
|
||||
ans = max(ans, cur);
|
||||
}
|
||||
|
||||
cout << ans << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
2
cses/sorting-and-searching/maximum-subarray-sum.in
Normal file
2
cses/sorting-and-searching/maximum-subarray-sum.in
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
8
|
||||
-1 3 -2 5 3 -5 2 2
|
||||
4
cses/sorting-and-searching/maximum-subarray-sum.out
Normal file
4
cses/sorting-and-searching/maximum-subarray-sum.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
9
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.0552 ms
|
||||
66
cses/sorting-and-searching/missing-coin-sum.cc
Normal file
66
cses/sorting-and-searching/missing-coin-sum.cc
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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()
|
||||
// }}}
|
||||
|
||||
int n;
|
||||
void solve() {
|
||||
cin >> n;
|
||||
vec<ll> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
sort(all(a));
|
||||
ll ans = 1;
|
||||
|
||||
for (auto x : a) {
|
||||
if (x > ans) {
|
||||
break;
|
||||
}
|
||||
ans += x;
|
||||
}
|
||||
cout << ans << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
2
cses/sorting-and-searching/missing-coin-sum.in
Normal file
2
cses/sorting-and-searching/missing-coin-sum.in
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
5
|
||||
2 9 1 2 7
|
||||
4
cses/sorting-and-searching/missing-coin-sum.out
Normal file
4
cses/sorting-and-searching/missing-coin-sum.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
6
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.3503 ms
|
||||
70
cses/sorting-and-searching/movie-festival.cc
Normal file
70
cses/sorting-and-searching/movie-festival.cc
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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;
|
||||
vec<pair<ll, ll>> a(n);
|
||||
for (auto& [A, b] : a)
|
||||
cin >> A >> b;
|
||||
sort(all(a), [](auto& l, auto& r) {
|
||||
return l.ss < r.ss;
|
||||
});
|
||||
|
||||
ll t = a[0].ss;
|
||||
ll ans = 1;
|
||||
for (auto& [l, r] : a) {
|
||||
if (l < t) {
|
||||
continue;
|
||||
}
|
||||
t = r;
|
||||
++ans;
|
||||
}
|
||||
cout << ans << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
4
cses/sorting-and-searching/movie-festival.in
Normal file
4
cses/sorting-and-searching/movie-festival.in
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
3
|
||||
3 5
|
||||
4 9
|
||||
5 8
|
||||
4
cses/sorting-and-searching/movie-festival.out
Normal file
4
cses/sorting-and-searching/movie-festival.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
2
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.569 ms
|
||||
74
cses/sorting-and-searching/restaurant-customers.cc
Normal file
74
cses/sorting-and-searching/restaurant-customers.cc
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
vec<pair<int, int>> events(2 * n);
|
||||
|
||||
for (int i = 0; i < 2 * n; i += 2) {
|
||||
int x;
|
||||
cin >> x;
|
||||
events[i] = {x, 1};
|
||||
cin >> x;
|
||||
events[i + 1] = {x, -1};
|
||||
}
|
||||
|
||||
sort(all(events));
|
||||
|
||||
ll ans = 0, cum = 0;
|
||||
|
||||
for (auto& [i, e] : events) {
|
||||
cum += e;
|
||||
ans = max(ans, cum);
|
||||
}
|
||||
|
||||
cout << ans << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
4
cses/sorting-and-searching/restaurant-customers.in
Normal file
4
cses/sorting-and-searching/restaurant-customers.in
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
3
|
||||
5 8
|
||||
2 4
|
||||
3 9
|
||||
4
cses/sorting-and-searching/restaurant-customers.out
Normal file
4
cses/sorting-and-searching/restaurant-customers.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
2
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.1048 ms
|
||||
64
cses/sorting-and-searching/stick-lengths.cc
Normal file
64
cses/sorting-and-searching/stick-lengths.cc
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
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()
|
||||
// }}}
|
||||
|
||||
int n;
|
||||
void solve() {
|
||||
cin >> n;
|
||||
vec<ll> sticks(n);
|
||||
for (auto& stick : sticks)
|
||||
cin >> stick;
|
||||
|
||||
sort(all(sticks));
|
||||
|
||||
ll median = sticks[sticks.size() / 2];
|
||||
|
||||
cout << accumulate(all(sticks), 0LL, [&](ll acc, ll i) {
|
||||
return acc + abs(median - i);
|
||||
});
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue