File tree Expand file tree Collapse file tree 3 files changed +84
-0
lines changed Expand file tree Collapse file tree 3 files changed +84
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments