more cf
This commit is contained in:
parent
5fbc6203d0
commit
e9d0bc91a8
123 changed files with 3730 additions and 0 deletions
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue