Skip to content

Commit 920be45

Browse files
committed
AtCoder 329 solutions.
1 parent 93547d5 commit 920be45

File tree

7 files changed

+155
-1
lines changed

7 files changed

+155
-1
lines changed

AtCoder/A_Spread.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
string S;
9+
cin >> S;
10+
for (int i = 0; i < S.size(); i++) {
11+
cout << S[i] << " ";
12+
}
13+
cout << endl;
14+
return 0;
15+
}

AtCoder/B_Next.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
int N;
9+
cin >> N;
10+
set<int> A;
11+
for (int i = 0; i < N; i++) {
12+
int X;
13+
cin >> X;
14+
A.insert(X);
15+
}
16+
cout << *prev(prev(A.end())) << endl;
17+
return 0;
18+
}

AtCoder/C_Count_xxx.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
int N;
9+
cin >> N;
10+
string S;
11+
cin >> S;
12+
vector<int> longest(26, 0);
13+
int block = 1;
14+
for (int i = 0; i < N; i++) {
15+
if (i && S[i] == S[i-1]) {
16+
block++;
17+
} else {
18+
block = 1;
19+
}
20+
longest[S[i] - 'a'] = max(longest[S[i] - 'a'], block);
21+
}
22+
int ans = 0;
23+
for (int i = 0; i < 26; i++) {
24+
ans += longest[i];
25+
}
26+
cout << ans << endl;
27+
return 0;
28+
}

AtCoder/D_Election_Quick_Report.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
int N, M;
9+
cin >> N >> M;
10+
vector<int> votes(N);
11+
priority_queue<pair<int, int>> pq;
12+
for (int i = 0; i < M; i++) {
13+
int C;
14+
cin >> C;
15+
C--;
16+
votes[C]++;
17+
pq.push({ votes[C], -C });
18+
auto [votes, c] = pq.top();
19+
cout << -c + 1 << endl;
20+
}
21+
return 0;
22+
}

AtCoder/E_Stamp.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
int N, M;
9+
cin >> N >> M;
10+
string S, T;
11+
cin >> S >> T;
12+
13+
vector<vector<int>> dp(N + 1, vector<int>(2, 0));
14+
for (int i = 0; i < N - M + 1; i++) {
15+
int l = 0;
16+
for (int j = 0; j < M; j++) {
17+
if (S[i+j] == T[j]) l++;
18+
else break;
19+
}
20+
21+
if (i == 0 || dp[i-1][0]) for (int k = 0; k < l; k++) dp[i+k][0] = max(dp[i+k][0], k+1);
22+
if ((i == 0 || dp[i-1][0] || dp[i-1][1]) && l == M) {
23+
dp[i][1] = 1;
24+
}
25+
26+
for (int j = 1; j < M; j++) {
27+
int last = i + j - M;
28+
if (last >= 0 && (dp[last][1] || dp[i+j-1][0] == M)) {
29+
for (int k = j; k < M; k++) {
30+
if (S[i+k] == T[k]) {
31+
dp[i+k][0] = max(dp[i+k][0], k+1);
32+
} else {
33+
break;
34+
}
35+
}
36+
}
37+
}
38+
}
39+
cout << ((dp[N-1][0] == M || dp[N-M][1]) ? "Yes" : "No") << endl;
40+
return 0;
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl '\n'
4+
5+
using namespace std;
6+
7+
int main() {
8+
int N, Q;
9+
cin >> N >> Q;
10+
vector<set<int>> boxes(N);
11+
for (int i = 0; i < N; i++) {
12+
int X;
13+
cin >> X;
14+
boxes[i].insert(X);
15+
}
16+
for (int i = 0; i < Q; i++) {
17+
int a, b;
18+
cin >> a >> b;
19+
a--; b--;
20+
if (boxes[a].size() > boxes[b].size()) {
21+
boxes[a].swap(boxes[b]);
22+
}
23+
for (auto el: boxes[a]) {
24+
boxes[b].insert(el);
25+
}
26+
boxes[a].clear();
27+
cout << boxes[b].size() << endl;
28+
}
29+
return 0;
30+
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Competitive Programming Problems and Solutions
22

3-
![](https://img.shields.io/static/v1?label=Solutions&message=1157&color=brightgreen)
3+
![](https://img.shields.io/static/v1?label=Solutions&message=1163&color=brightgreen)
44

55
This repository is meant as a public place to store my competitive programming solutions to various of competitive programming problems on sites such as:
66
- CodeForces

0 commit comments

Comments
 (0)