Skip to content

Commit d68f2a8

Browse files
authored
Merge pull request #399 from xirc/atcoder/abc009
AtCoder/ABC009
2 parents 94a196c + bae7130 commit d68f2a8

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

atcoder/abc009/A/main.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int main() {
8+
ios_base::sync_with_stdio(false);
9+
cin.tie(0); cout.tie(0);
10+
11+
int N;
12+
cin >> N;
13+
cout << (N + 1) / 2 << endl;
14+
15+
return 0;
16+
}

atcoder/abc009/B/main.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int main() {
8+
ios_base::sync_with_stdio(false);
9+
cin.tie(0); cout.tie(0);
10+
11+
int N;
12+
vector<int> A;
13+
14+
cin >> N;
15+
A.assign(N, 0);
16+
for (auto &a : A) cin >> a;
17+
18+
sort(A.begin(), A.end());
19+
auto it = unique(A.begin(), A.end());
20+
A.erase(it, A.end());
21+
reverse(A.begin(), A.end());
22+
cout << A[1] << endl;
23+
24+
return 0;
25+
}

atcoder/abc009/C/main.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int diff(string const& S, string const& R) {
8+
assert(S.size() == R.size());
9+
int count = 0;
10+
for (int i = 0; i < (int)S.size(); ++i) {
11+
count += S[i] != R[i] ? 1 : 0;
12+
}
13+
return count;
14+
}
15+
16+
string solve(int const N, int const K, string const& S) {
17+
string L = S;
18+
for (int i = 0; i < N; ++i) {
19+
int j = i;
20+
for (int k = i + 1; k < N; ++k) {
21+
if (L[k] >= L[j]) continue;
22+
string R = L;
23+
swap(R[i], R[k]);
24+
if (diff(S, R) <= K) {
25+
j = k;
26+
}
27+
}
28+
swap(L[i], L[j]);
29+
}
30+
return L;
31+
}
32+
33+
int main() {
34+
ios_base::sync_with_stdio(false);
35+
cin.tie(0); cout.tie(0);
36+
37+
int N, K;
38+
string S;
39+
cin >> N >> K >> S;
40+
cout << solve(N, K, S) << endl;
41+
42+
return 0;
43+
}

0 commit comments

Comments
 (0)