Skip to content

Commit c9f3f3e

Browse files
committed
Add Codeforces Round 653-Div 3
1 parent 34d8c93 commit c9f3f3e

4 files changed

Lines changed: 242 additions & 0 deletions

File tree

‎codeforces/653_Div3/a.cpp‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
36+
int main() {
37+
fast_cin();
38+
int t;
39+
cin >> t;
40+
while(t--) {
41+
int x,y,n;
42+
cin >> x >> y >> n;
43+
int tmp = n/x;
44+
int tmp2 = tmp*x + y;
45+
if(tmp2<=n)
46+
cout << tmp2 << ln;
47+
else
48+
cout << tmp2-x << ln;
49+
}
50+
return 0;
51+
}

‎codeforces/653_Div3/b.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+
36+
void err() {
37+
cout << -1 << ln;
38+
}
39+
40+
void solve() {
41+
int n;
42+
cin >> n;
43+
44+
if(n==1) {
45+
cout << 0 << ln;
46+
return;
47+
}
48+
49+
int p2=0, p3=0;
50+
while(n%2==0) {
51+
n/=2;
52+
p2++;
53+
}
54+
while(n%3==0) {
55+
n/=3;
56+
p3++;
57+
}
58+
59+
if(n!=1) {err(); return;}
60+
if(p2>p3) {err(); return;}
61+
62+
cout << 2*p3-p2 << 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/653_Div3/c.cpp‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
36+
int main() {
37+
fast_cin();
38+
int t;
39+
cin >> t;
40+
while(t--) {
41+
int n;
42+
string s;
43+
cin >> n >> s;
44+
int o=0,c=0,tot=0;
45+
for(auto ch:s) {
46+
if(ch=='(') o++;
47+
else {
48+
if(c>o) tot++;
49+
else c++;
50+
}
51+
}
52+
cout << tot << ln;
53+
}
54+
return 0;
55+
}

‎codeforces/653_Div3/d.cpp‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
36+
int main() {
37+
fast_cin();
38+
int t;
39+
cin >> t;
40+
while(t--) {
41+
int n,k;
42+
cin >> n >> k;
43+
int a,tmp,mx=0,mx_idx;
44+
map<int,int> m;
45+
forn(i,n) {
46+
cin >> a;
47+
tmp = a%k;
48+
if(tmp!=0) {
49+
tmp = k - tmp;
50+
m[tmp]++;
51+
mx=max(mx, m[tmp]);
52+
}
53+
}
54+
55+
ll ans = 0;
56+
for(auto [key, val] : m) {
57+
if(val==mx)
58+
ans = k*1ll*(val-1) + key + 1;
59+
}
60+
cout << ans << ln;
61+
}
62+
return 0;
63+
}

0 commit comments

Comments
 (0)