Skip to content

Commit 2f45903

Browse files
committed
Merge branch 'master' of https://github.com/Macesuted/Code
2 parents b9b3042 + 353e273 commit 2f45903

1 file changed

Lines changed: 53 additions & 53 deletions

File tree

Codeforces/2107F1.cpp

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,56 @@
77
*
88
*/
99

10-
#include <bits/stdc++.h>
11-
using namespace std;
12-
13-
#ifndef LOCAL
14-
#define endl '\n'
15-
#endif
16-
17-
bool mem1;
18-
19-
#define maxn 5005
20-
21-
int a[maxn], b[maxn];
22-
23-
void solve(void) {
24-
int n;
25-
cin >> n;
26-
for (int i = 1; i <= n; i++) cin >> b[i];
27-
28-
int64_t ans = INT64_MAX;
29-
for (int x = 1; x <= n; x++) {
30-
for (int i = 1; i <= n; i++) a[i] = b[i];
31-
int64_t cur = 0;
32-
if (x < n) swap(a[x], a[n]), cur += n - x;
33-
cur += a[n];
34-
for (int i = n - 1; i; i--) {
35-
if (a[i] > a[i + 1]) cur++, swap(a[i], a[i + 1]);
36-
cur += a[i];
37-
}
38-
ans = min(ans, cur);
39-
}
40-
41-
cout << ans << endl;
42-
43-
return;
44-
}
45-
46-
bool mem2;
47-
48-
int main() {
49-
ios::sync_with_stdio(false), cin.tie(nullptr);
50-
#ifdef LOCAL
51-
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
52-
#endif
53-
54-
int _ = 1;
55-
cin >> _;
56-
while (_--) solve();
57-
58-
#ifdef LOCAL
59-
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
60-
#endif
61-
return 0;
62-
}
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#ifndef LOCAL
14+
#define endl '\n'
15+
#endif
16+
17+
bool mem1;
18+
19+
#define maxn 5005
20+
21+
int a[maxn], b[maxn];
22+
23+
void solve(void) {
24+
int n;
25+
cin >> n;
26+
for (int i = 1; i <= n; i++) cin >> b[i];
27+
28+
int64_t ans = INT64_MAX;
29+
for (int x = 1; x <= n; x++) {
30+
for (int i = 1; i <= n; i++) a[i] = b[i];
31+
int64_t cur = 0;
32+
if (x < n) swap(a[x], a[n]), cur += n - x;
33+
cur += a[n];
34+
for (int i = n - 1; i; i--) {
35+
if (a[i] > a[i + 1]) cur++, swap(a[i], a[i + 1]);
36+
cur += a[i];
37+
}
38+
ans = min(ans, cur);
39+
}
40+
41+
cout << ans << endl;
42+
43+
return;
44+
}
45+
46+
bool mem2;
47+
48+
int main() {
49+
ios::sync_with_stdio(false), cin.tie(nullptr);
50+
#ifdef LOCAL
51+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
52+
#endif
53+
54+
int _ = 1;
55+
cin >> _;
56+
while (_--) solve();
57+
58+
#ifdef LOCAL
59+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
60+
#endif
61+
return 0;
62+
}

0 commit comments

Comments
 (0)