Skip to content

Commit 001732b

Browse files
committed
Problem A, B, C - CR 684, 685
1 parent e7b4474 commit 001732b

File tree

7 files changed

+460
-0
lines changed

7 files changed

+460
-0
lines changed

Codeforces/1451A.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <bits/stdc++.h>
2+
3+
#define range(a,b,c) for(int a=b; a<c; a++)
4+
#define MX 1e4+5
5+
6+
using namespace std;
7+
8+
typedef pair<int, int> pii;
9+
typedef vector<int> vi;
10+
typedef vector<pii> vii;
11+
typedef vector<vi> vvi;
12+
13+
14+
15+
16+
void solve() {
17+
//
18+
int n;
19+
cin >> n;
20+
21+
if(n == 1)
22+
cout << "0\n";
23+
else if(n == 2)
24+
cout << "1\n";
25+
else if(n == 3)
26+
cout << "2\n";
27+
else
28+
cout << 2 + n%2 << "\n";
29+
}
30+
31+
32+
int main() {
33+
//
34+
ios_base::sync_with_stdio(false);
35+
int T;
36+
cin >> T;
37+
while(T--)
38+
solve();
39+
40+
return 0;
41+
}

Codeforces/1451B.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <bits/stdc++.h>
2+
3+
#define range(a,b,c) for(int a=b; a<c; a++)
4+
#define MX 1e4+5
5+
6+
using namespace std;
7+
8+
typedef pair<int, int> pii;
9+
typedef vector<int> vi;
10+
typedef vector<pii> vii;
11+
typedef vector<vi> vvi;
12+
13+
14+
15+
16+
void solve() {
17+
//
18+
int n, q;
19+
cin >> n >> q;
20+
21+
string s;
22+
cin >> s;
23+
24+
range(i, 0, q) {
25+
int l, r;
26+
cin >> l >> r;
27+
l--;
28+
r--;
29+
30+
bool flag = false;
31+
char last = s[r];
32+
for(int j = r+1; j < n; j++)
33+
if(s[j] == last) {
34+
cout << "YES\n";
35+
flag = true;
36+
break;
37+
}
38+
if(!flag) {
39+
char first = s[l];
40+
for(int j = l-1; j >= 0; j--)
41+
if(s[j] == first) {
42+
cout << "YES\n";
43+
flag = true;
44+
break;
45+
}
46+
}
47+
if(!flag)
48+
cout << "NO\n";
49+
}
50+
}
51+
52+
53+
int main() {
54+
//
55+
ios_base::sync_with_stdio(false);
56+
int T;
57+
cin >> T;
58+
while(T--)
59+
solve();
60+
61+
return 0;
62+
}

Codeforces/1451C.cpp

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include <bits/stdc++.h>
2+
3+
#define range(a,b,c) for(int a=b; a<c; a++)
4+
#define MX 1e4+5
5+
6+
using namespace std;
7+
8+
typedef pair<int, int> pii;
9+
typedef vector<int> vi;
10+
typedef vector<pii> vii;
11+
typedef vector<vi> vvi;
12+
13+
14+
15+
16+
void solve() {
17+
//
18+
int n, k;
19+
cin >> n >> k;
20+
21+
string a;
22+
cin >> a;
23+
24+
vi ac(26, 0);
25+
for(char ch: a) {
26+
int i = int(ch - 'a');
27+
ac[i]++;
28+
}
29+
30+
string b;
31+
cin >> b;
32+
33+
vi bc(26, 0);
34+
for(char ch: b) {
35+
int i = int(ch - 'a');
36+
bc[i]++;
37+
}
38+
39+
vi have(n, 0);
40+
range(i, 0, n) {
41+
int id = int(b[i] - 'a');
42+
if(ac[id]) {
43+
ac[id]--;
44+
have[i] = 1;
45+
}
46+
}
47+
48+
range(i, 0, n) {
49+
if(have[i])
50+
continue;
51+
52+
char ch = b[i];
53+
//cout << "ch: " << i << " " << ch << " \n";
54+
int id = int(b[i] - 'a');
55+
range(j, i+1, i+k) {
56+
if(ch != b[j]) {
57+
//cout << "bj " << j << " " << b[j] << "\n";
58+
cout << "No\n";
59+
return;
60+
}
61+
}
62+
63+
range(j, 0, id+1) {
64+
if(ac[j] >= k) {
65+
cout << "salam: " << a[j] << "\n";
66+
ac[j] -= max(0,k);
67+
range(ii, i, i+k)
68+
have[ii] = 1;
69+
}
70+
}
71+
72+
cout << "HV: ";
73+
for(int x: have)
74+
cout << x << " ";
75+
cout << "\n";
76+
}
77+
78+
cout << "AC: ";
79+
for(int x: ac)
80+
cout << x << " ";
81+
cout << "\n";
82+
83+
cout << "HV: ";
84+
for(int x: have)
85+
cout << x << " ";
86+
cout << "\n";
87+
88+
cout << "Yes\n";
89+
return;
90+
91+
}
92+
93+
94+
int main() {
95+
//
96+
ios_base::sync_with_stdio(false);
97+
int T;
98+
cin >> T;
99+
while(T--)
100+
solve();
101+
102+
return 0;
103+
}

Codeforces/1452B.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <bits/stdc++.h>
2+
3+
#define MX 1e4+5
4+
5+
using namespace std;
6+
7+
typedef pair<int, int> pii;
8+
typedef vector<int> vi;
9+
typedef vector<pii> vii;
10+
typedef vector<vi> vvi;
11+
12+
13+
14+
15+
void solve() {
16+
//
17+
int n;
18+
cin >> n;
19+
20+
vi a(n);
21+
int sum = 0;
22+
int mx = INT_MIN;
23+
for(int i = 0; i < n; i++) {
24+
cin >> a[i];
25+
sum += a[i];
26+
mx = max(mx, a[i]);
27+
}
28+
29+
sum -= mx;
30+
int x = sum / mx;
31+
x++;
32+
//cout << "x: " << x << " " << mx << " " << sum << "\n";
33+
34+
cout << (x * mx - sum) % (n-1) << "\n";
35+
36+
}
37+
38+
39+
int main() {
40+
//
41+
ios_base::sync_with_stdio(false);
42+
int T;
43+
cin >> T;
44+
while(T--)
45+
solve();
46+
47+
return 0;
48+
}

Codeforces/1454A.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <bits/stdc++.h>
2+
3+
#define range(a,b,c) for(int a=b; a<c; a++)
4+
#define MX 1e4+5
5+
6+
using namespace std;
7+
8+
typedef pair<int, int> pii;
9+
typedef vector<int> vi;
10+
typedef vector<pii> vii;
11+
typedef vector<vi> vvi;
12+
13+
14+
15+
16+
void solve() {
17+
//
18+
int n;
19+
cin >> n;
20+
21+
if(n == 1)
22+
cout << "0\n";
23+
else if(n == 2)
24+
cout << "1\n";
25+
else if(n == 3)
26+
cout << "2\n";
27+
else
28+
cout << 2 + n%2 << "\n";
29+
}
30+
31+
32+
int main() {
33+
//
34+
ios_base::sync_with_stdio(false);
35+
int T;
36+
cin >> T;
37+
while(T--)
38+
solve();
39+
40+
return 0;
41+
}

Codeforces/1454B.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <bits/stdc++.h>
2+
3+
#define range(a,b,c) for(int a=b; a<c; a++)
4+
#define MX 1e4+5
5+
6+
using namespace std;
7+
8+
typedef pair<int, int> pii;
9+
typedef vector<int> vi;
10+
typedef vector<pii> vii;
11+
typedef vector<vi> vvi;
12+
13+
14+
15+
16+
void solve() {
17+
//
18+
int n, q;
19+
cin >> n >> q;
20+
21+
string s;
22+
cin >> s;
23+
24+
range(i, 0, q) {
25+
int l, r;
26+
cin >> l >> r;
27+
l--;
28+
r--;
29+
30+
bool flag = false;
31+
char last = s[r];
32+
for(int j = r+1; j < n; j++)
33+
if(s[j] == last) {
34+
cout << "YES\n";
35+
flag = true;
36+
break;
37+
}
38+
if(!flag) {
39+
char first = s[l];
40+
for(int j = l-1; j >= 0; j--)
41+
if(s[j] == first) {
42+
cout << "YES\n";
43+
flag = true;
44+
break;
45+
}
46+
}
47+
if(!flag)
48+
cout << "NO\n";
49+
}
50+
}
51+
52+
53+
int main() {
54+
//
55+
ios_base::sync_with_stdio(false);
56+
int T;
57+
cin >> T;
58+
while(T--)
59+
solve();
60+
61+
return 0;
62+
}

0 commit comments

Comments
 (0)