Skip to content

Commit 127887e

Browse files
committed
Add some CF files
1 parent 09ce2e5 commit 127887e

9 files changed

Lines changed: 547 additions & 56 deletions

File tree

‎codeforces/636_Div3/A.cpp‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#pragma GCC optimize ("-O3")
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
typedef long long int ll;
6+
typedef long long unsigned lluu;
7+
typedef long double ld;
8+
typedef pair<int,int> p32;
9+
typedef pair<ll,ll> p64;
10+
typedef pair<double,double> pdd;
11+
typedef vector<ll> v64;
12+
typedef vector<int> v32;
13+
typedef vector<vector<int> > vv32;
14+
typedef vector<vector<ll> > vv64;
15+
typedef vector<p64> vp64;
16+
typedef vector<p32> vp32;
17+
ll MOD = 998244353;
18+
ll NUM = 1e9+7;
19+
#define forn(i,e) for(ll i = 0; i < e; i++)
20+
#define forsn(i,s,e) for(ll i = s; i < e; i++)
21+
#define rforn(i,s) for(ll i = s; i >= 0; i--)
22+
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
23+
#define ln "\n"
24+
#define dbg(x) cout<<#x<<" = "<<x<<ln
25+
#define mp make_pair
26+
#define pb push_back
27+
#define ff first
28+
#define ss second
29+
#define INF 1e18
30+
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
31+
#define all(x) (x).begin(), (x).end()
32+
#define sz(x) ((ll)(x).size())
33+
#define zer ll(0)
34+
#define printarr(arr,n) forn(i,n) cout << arr[i] << " "
35+
#define input(arr,n) forn(i,n) cin >> arr[i]
36+
37+
void solve() {
38+
ll n;
39+
cin >> n;
40+
ll mul=4;
41+
while(true) {
42+
if (n%(mul-1) == 0) {
43+
cout << n/(mul-1) << ln;
44+
return;
45+
}
46+
mul*=2;
47+
}
48+
}
49+
50+
int main() {
51+
fast_cin();
52+
int t;
53+
cin >> t;
54+
while(t--) {
55+
solve();
56+
}
57+
return 0;
58+
}

‎codeforces/636_Div3/B.cpp‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#pragma GCC optimize ("-O3")
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
typedef long long int ll;
6+
typedef long long unsigned lluu;
7+
typedef long double ld;
8+
typedef pair<int,int> p32;
9+
typedef pair<ll,ll> p64;
10+
typedef pair<double,double> pdd;
11+
typedef vector<ll> v64;
12+
typedef vector<int> v32;
13+
typedef vector<vector<int> > vv32;
14+
typedef vector<vector<ll> > vv64;
15+
typedef vector<p64> vp64;
16+
typedef vector<p32> vp32;
17+
ll MOD = 998244353;
18+
ll NUM = 1e9+7;
19+
#define forn(i,e) for(ll i = 0; i < e; i++)
20+
#define forsn(i,s,e) for(ll i = s; i < e; i++)
21+
#define rforn(i,s) for(ll i = s; i >= 0; i--)
22+
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
23+
#define ln "\n"
24+
#define dbg(x) cout<<#x<<" = "<<x<<ln
25+
#define mp make_pair
26+
#define pb push_back
27+
#define ff first
28+
#define ss second
29+
#define INF 1e18
30+
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
31+
#define all(x) (x).begin(), (x).end()
32+
#define sz(x) ((ll)(x).size())
33+
#define zer ll(0)
34+
#define printarr(arr,n) forn(i,n) cout << arr[i] << " "
35+
#define input(arr,n) forn(i,n) cin >> arr[i]
36+
37+
void solve() {
38+
int n;
39+
cin >> n;
40+
if (n%4!=0) {
41+
cout << "NO" << ln;
42+
return;
43+
}
44+
cout << "YES" << ln;
45+
int even=4, odd=5;
46+
for(int i=0; i<n/4; i++) {
47+
cout << even-2 << " " << even << " ";
48+
even+=6;
49+
}
50+
for(int i=0; i<n/4; i++) {
51+
cout << odd-4 << " " << odd << " ";
52+
odd+=6;
53+
}
54+
cout << ln;
55+
}
56+
57+
int main() {
58+
fast_cin();
59+
int t;
60+
cin >> t;
61+
while(t--) {
62+
solve();
63+
}
64+
return 0;
65+
}

‎codeforces/636_Div3/C.cpp‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#pragma GCC optimize ("-O3")
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
typedef long long int ll;
6+
typedef long long unsigned lluu;
7+
typedef long double ld;
8+
typedef pair<int,int> p32;
9+
typedef pair<ll,ll> p64;
10+
typedef pair<double,double> pdd;
11+
typedef vector<ll> v64;
12+
typedef vector<int> v32;
13+
typedef vector<vector<int> > vv32;
14+
typedef vector<vector<ll> > vv64;
15+
typedef vector<p64> vp64;
16+
typedef vector<p32> vp32;
17+
ll MOD = 998244353;
18+
ll NUM = 1e9+7;
19+
#define forn(i,e) for(ll i = 0; i < e; i++)
20+
#define forsn(i,s,e) for(ll i = s; i < e; i++)
21+
#define rforn(i,s) for(ll i = s; i >= 0; i--)
22+
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
23+
#define ln "\n"
24+
#define dbg(x) cout<<#x<<" = "<<x<<ln
25+
#define mp make_pair
26+
#define pb push_back
27+
#define ff first
28+
#define ss second
29+
#define INF 1e18
30+
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
31+
#define all(x) (x).begin(), (x).end()
32+
#define sz(x) ((ll)(x).size())
33+
#define zer ll(0)
34+
#define printarr(arr,n) forn(i,n) cout << arr[i] << " "
35+
#define input(arr,n) forn(i,n) cin >> arr[i]
36+
37+
bool issame(int a, int b) {
38+
return ((a>0 && b>0) || (a<0 && b<0));
39+
}
40+
41+
void solve() {
42+
int n;
43+
cin >> n;
44+
v32 v(n);
45+
input(v,n);
46+
47+
ll tot=0;
48+
int i=0,j=0,curr_max=INT_MIN;
49+
50+
while(i<n && j<n) {
51+
curr_max = INT_MIN;
52+
53+
while(j<n && issame(v[i], v[j])) {
54+
curr_max = max(curr_max, v[j]);
55+
j++;
56+
}
57+
58+
tot+=curr_max;
59+
i=j;
60+
}
61+
cout << tot << ln;
62+
}
63+
64+
int main() {
65+
fast_cin();
66+
int t;
67+
cin >> t;
68+
while(t--) {
69+
solve();
70+
}
71+
return 0;
72+
}

‎codeforces/636_Div3/D.cpp‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#pragma GCC optimize ("-O3")
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
typedef long long int ll;
6+
typedef long long unsigned lluu;
7+
typedef long double ld;
8+
typedef pair<int,int> p32;
9+
typedef pair<ll,ll> p64;
10+
typedef pair<double,double> pdd;
11+
typedef vector<ll> v64;
12+
typedef vector<int> v32;
13+
typedef vector<vector<int> > vv32;
14+
typedef vector<vector<ll> > vv64;
15+
typedef vector<p64> vp64;
16+
typedef vector<p32> vp32;
17+
ll MOD = 998244353;
18+
ll NUM = 1e9+7;
19+
#define forn(i,e) for(ll i = 0; i < e; i++)
20+
#define forsn(i,s,e) for(ll i = s; i < e; i++)
21+
#define rforn(i,s) for(ll i = s; i >= 0; i--)
22+
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
23+
#define ln "\n"
24+
#define dbg(x) cout<<#x<<" = "<<x<<ln
25+
#define mp make_pair
26+
#define pb push_back
27+
#define ff first
28+
#define ss second
29+
#define INF 1e18
30+
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
31+
#define all(x) (x).begin(), (x).end()
32+
#define sz(x) ((ll)(x).size())
33+
#define zer ll(0)
34+
#define printarr(arr,n) forn(i,n) cout << arr[i] << " "
35+
#define input(arr,n) forn(i,n) cin >> arr[i]
36+
37+
void solve() {
38+
int n,k;
39+
cin >> n >> k;
40+
41+
v32 v(n);
42+
input(v,n);
43+
44+
int min_cnt=INT_MAX;
45+
46+
for(int x=2; x<=2*k; x++) {
47+
int cnt=0;
48+
for(int i=0; i<n/2; i++) {
49+
if ( (v[i]+v[n-i-1]) != x) {
50+
if ((x-v[i]<=k && x-v[i]>=1) || (x-v[n-i-1]<=k && x-v[n-i-1]>=1) )
51+
cnt++;
52+
else
53+
cnt+=2;
54+
}
55+
}
56+
57+
// dbg(x);
58+
// dbg(cnt);
59+
min_cnt = min(min_cnt, cnt);
60+
61+
}
62+
cout << min_cnt << ln;
63+
}
64+
65+
int main() {
66+
// fast_cin();
67+
int t;
68+
cin >> t;
69+
while(t--) {
70+
solve();
71+
}
72+
return 0;
73+
}

‎codeforces/668_Div2/C.cpp‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,56 @@ ll NUM = 1e9+7;
3434
#define printarr(arr,n) forn(i,n) cout << arr[i] << " "
3535
#define input(arr,n) forn(i,n) cin >> arr[i]
3636

37+
void yes() { cout << "YES" << ln; }
38+
void no() {cout << "NO" << ln;}
39+
3740
void solve() {
41+
int n,K;
42+
cin >> n >> K;
43+
string s;
44+
cin >> s;
45+
46+
for(int i=0; i<K; i++) {
47+
int j=i, is01=-1;
48+
if (s[i]!='?') is01=s[i]-'0';
49+
50+
while(j<n) {
51+
if (s[j]!='?') {
52+
if (is01==-1)
53+
is01 = s[j]-'0';
54+
else {
55+
if (is01 != s[j]-'0') {
56+
no();
57+
return;
58+
}
59+
}
60+
}
61+
62+
j+=K;
63+
}
64+
65+
if (s[i]=='?' && is01!=-1)
66+
s[i]='0'+is01;
67+
}
68+
69+
// dbg(s);
70+
int c0=0,c1=0;
71+
72+
for(int i=0; i<K; i++) {
73+
if (s[i]=='0') c0++;
74+
else if (s[i]=='1') c1++;
75+
}
76+
77+
if (c0>K/2 || c1>K/2) {
78+
no(); return;
79+
}
80+
81+
yes();
3882

3983
}
4084

4185
int main() {
42-
fast_cin();
86+
// fast_cin();
4387
int t;
4488
cin >> t;
4589
while(t--) {

0 commit comments

Comments
 (0)