Skip to content

Commit 8c5a5ea

Browse files
committed
add CSES, EDU-CF and realloc some files
1 parent 48fc032 commit 8c5a5ea

File tree

188 files changed

+8300
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+8300
-5
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
5+
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
6+
7+
typedef long long ll;
8+
typedef long double ld;
9+
typedef pair<int,int> pii;
10+
11+
#define optimize ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
12+
#define endl "\n"
13+
14+
#define fi first
15+
#define se second
16+
#define pb push_back
17+
18+
#define all(x) x.begin(),x.end()
19+
#define ms(x,a) memset(x,a,sizeof(x))
20+
21+
#define INF 0x3f3f3f3f
22+
#define INFLL 0x3f3f3f3f3f3f3f3f
23+
24+
#define mod 1000000007LL
25+
#define MAXN 200010
26+
27+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
28+
29+
//#define _DEBUG
30+
// #ifdef _DEBUG
31+
// #endif
32+
33+
/* -------------------------------- Solution starts below -------------------------------- */
34+
35+
ll T,N,M,K;
36+
int A[MAXN], B[MAXN];
37+
38+
void solve() {
39+
40+
cin >> N;
41+
42+
for(int i = 0; i < N; i++) cin >> A[i];
43+
44+
sort(A, A + N);
45+
46+
int i = 0;
47+
48+
for(int j = 0; j < N; i++, j+=2) B[j] = A[i];
49+
for(int j = 1; j < N; i++, j+=2) B[j] = A[i];
50+
51+
bool ok = true;
52+
53+
for(int i = 1; i < N; i+=2) {
54+
if(B[i] <= B[i - 1] || B[i] <= B[i + 1]) ok = false;
55+
}
56+
57+
if(ok) cout << "Yes\n";
58+
else cout << "No\n";
59+
}
60+
61+
int main() {
62+
63+
//optimize;
64+
65+
T = 1;
66+
67+
//cin >> T;
68+
69+
while(T--) {
70+
solve();
71+
}
72+
73+
return 0;
74+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
5+
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
6+
7+
typedef long long ll;
8+
typedef long double ld;
9+
typedef pair<int,int> pii;
10+
11+
#define optimize ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
12+
#define endl "\n"
13+
14+
#define fi first
15+
#define se second
16+
#define pb push_back
17+
18+
#define all(x) x.begin(),x.end()
19+
#define ms(x,a) memset(x,a,sizeof(x))
20+
21+
#define INF 0x3f3f3f3f
22+
#define INFLL 0x3f3f3f3f3f3f3f3f
23+
24+
#define mod 1000000007LL
25+
#define MAXN 200010
26+
27+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
28+
29+
//#define _DEBUG
30+
// #ifdef _DEBUG
31+
// #endif
32+
33+
/* -------------------------------- Solution starts below -------------------------------- */
34+
35+
ll T,N,M,K;
36+
37+
void solve() {
38+
39+
cin >> N;
40+
41+
if(N < 7) {
42+
cout << -1 << endl;
43+
return;
44+
}
45+
46+
if(__builtin_popcountll(N) == 1) {
47+
N--;
48+
}
49+
else if(__builtin_popcountll(N) == 2) {
50+
ll desc = 0;
51+
52+
if( (N & (1LL << 0)) || (N & (1LL << 1)) ) {
53+
desc += (N & (1LL << 0));
54+
desc += (N & (1LL << 1));
55+
56+
desc += 1;
57+
}
58+
else {
59+
desc = 1;
60+
}
61+
62+
N -= desc;
63+
}
64+
65+
ll i = 0;
66+
while(__builtin_popcountll(N) > 3) {
67+
if(N & (1LL << i)) {
68+
N^= (1LL << i);
69+
}
70+
i++;
71+
}
72+
73+
cout << N << endl;
74+
}
75+
76+
int main() {
77+
78+
optimize;
79+
80+
T = 1;
81+
82+
cin >> T;
83+
84+
while(T--) {
85+
solve();
86+
}
87+
88+
return 0;
89+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
5+
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
6+
7+
typedef long long ll;
8+
typedef long double ld;
9+
typedef pair<int,int> pii;
10+
11+
#define optimize ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
12+
#define endl "\n"
13+
14+
#define fi first
15+
#define se second
16+
#define pb push_back
17+
18+
#define all(x) x.begin(),x.end()
19+
#define ms(x,a) memset(x,a,sizeof(x))
20+
21+
#define INF 0x3f3f3f3f
22+
#define INFLL 0x3f3f3f3f3f3f3f3f
23+
24+
#define mod 1000000007LL
25+
#define MAXN 200010
26+
27+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
28+
29+
//#define _DEBUG
30+
// #ifdef _DEBUG
31+
// #endif
32+
33+
/* -------------------------------- Solution starts below -------------------------------- */
34+
35+
ll T,N,M,K;
36+
string s, t;
37+
bool ok;
38+
39+
void dfs(int u, int p, vector<vector<int>> & adj) {
40+
41+
int k = 0, f = 0;
42+
43+
for(int v: adj[u]) {
44+
if(v != p) {
45+
dfs(v, u, adj);
46+
47+
if(t[v] == s[u]) k++;
48+
f++;
49+
}
50+
}
51+
52+
// Raiz
53+
if(u == 0) {
54+
// Raiz ou é definida pelos filhos ou pode ser qualquer coisa ou é inválida
55+
if(2 * k < f) {
56+
ok = false;
57+
}
58+
}
59+
else { // Outros
60+
if(2 * k > f) {
61+
if(t[u] == '0') t[u] = s[p];
62+
}
63+
else if(2 * k == f) {
64+
if(t[p] != '0' && t[p] != s[u]) ok = false;
65+
66+
t[p] = s[u];
67+
68+
if(t[u] == '0') t[u] = s[p];
69+
}
70+
else {
71+
ok = false;
72+
}
73+
}
74+
}
75+
76+
void solve() {
77+
78+
cin >> N;
79+
80+
vector<vector<int>> adj(N);
81+
t.assign(N, '0');
82+
ok = true;
83+
84+
for(int i = 0, u, v; i < N - 1; i++) {
85+
cin >> u >> v;
86+
87+
u--, v--;
88+
89+
adj[u].push_back(v);
90+
adj[v].push_back(u);
91+
}
92+
93+
cin >> s;
94+
95+
dfs(0, -1, adj);
96+
97+
if(t[0] == '0') t[0] = 'B';
98+
99+
if(ok) cout << t << endl;
100+
else cout << -1 << endl;
101+
}
102+
103+
int main() {
104+
105+
optimize;
106+
107+
T = 1;
108+
109+
cin >> T;
110+
111+
while(T--) {
112+
solve();
113+
}
114+
115+
return 0;
116+
}

Atcoder/AtCoder Regular Contest 162/.vscode/settings.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

CSES/ReadingBooks_1631.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
5+
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
6+
7+
typedef long long ll;
8+
typedef long double ld;
9+
typedef pair<int,int> pii;
10+
11+
#define optimize ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
12+
#define endl "\n"
13+
14+
#define fi first
15+
#define se second
16+
#define pb push_back
17+
18+
#define all(x) x.begin(),x.end()
19+
#define ms(x,a) memset(x,a,sizeof(x))
20+
21+
#define INF 0x3f3f3f3f
22+
#define INFLL 0x3f3f3f3f3f3f3f3f
23+
24+
#define mod 1000000007LL
25+
#define MAXN 200010
26+
27+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
28+
29+
//#define _DEBUG
30+
// #ifdef _DEBUG
31+
// #endif
32+
33+
/* -------------------------------- Solution starts below -------------------------------- */
34+
35+
ll T,N,M,K;
36+
37+
vector<ll> nums;
38+
39+
void solve(){
40+
41+
ll ans = 0;
42+
43+
sort(all(nums));
44+
45+
for(auto &i : nums) ans += i;
46+
47+
if(ans - nums.back() < nums.back()) ans += nums.back() - (ans - nums.back());
48+
49+
cout << ans << endl;
50+
}
51+
52+
int main(){
53+
54+
optimize;
55+
56+
cin >> N;
57+
58+
nums.resize(N);
59+
60+
for(int i = 0; i < N; i++){
61+
cin >> nums[i];
62+
}
63+
64+
solve();
65+
66+
return 0;
67+
}

0 commit comments

Comments
 (0)