Submission #4669776
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;
using ll = int64_t;
using ld = long double;
const int N = 5228;
ll f[N][N];
int p[N];
const ll INF = (1ll << 60);
int main() {
#ifdef BZ
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);
int n;
ll a, b;
cin >> n >> a >> b;
for (int i = 0; i < n; ++i) {
cin >> p[i];
--p[i];
}
p[n] = n;
for (int i = 0; i <= n + 1; ++i) {
fill(f[i], f[i] + n + 1, INF);
}
f[0][0] = 0;
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
ll cf = f[i][j];
if (p[i] >= j) {
f[i + 1][p[i]] = min(f[i + 1][p[i]], cf);
f[i + 1][j] = min(f[i + 1][j], cf + a);
} else {
f[i + 1][j] = min(f[i + 1][j], cf + b);
}
}
}
cout << f[n + 1][n] << "\n";
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Rotation Sort |
| User | cospleermusora |
| Language | C++14 (GCC 5.4.1) |
| Score | 1000 |
| Code Size | 1056 Byte |
| Status | AC |
| Exec Time | 107 ms |
| Memory | 205056 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 1000 / 1000 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt |
| All | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 0_00.txt | AC | 1 ms | 256 KiB |
| 0_01.txt | AC | 1 ms | 256 KiB |
| 0_02.txt | AC | 1 ms | 256 KiB |
| 0_03.txt | AC | 1 ms | 256 KiB |
| 0_04.txt | AC | 1 ms | 256 KiB |
| 1_00.txt | AC | 1 ms | 256 KiB |
| 1_01.txt | AC | 107 ms | 205056 KiB |
| 1_02.txt | AC | 106 ms | 205056 KiB |
| 1_03.txt | AC | 107 ms | 205056 KiB |
| 1_04.txt | AC | 107 ms | 205056 KiB |
| 1_05.txt | AC | 107 ms | 205056 KiB |
| 1_06.txt | AC | 107 ms | 205056 KiB |
| 1_07.txt | AC | 107 ms | 205056 KiB |
| 1_08.txt | AC | 105 ms | 203008 KiB |
| 1_09.txt | AC | 105 ms | 203008 KiB |
| 1_10.txt | AC | 104 ms | 200960 KiB |
| 1_11.txt | AC | 104 ms | 203008 KiB |
| 1_12.txt | AC | 101 ms | 198912 KiB |
| 1_13.txt | AC | 106 ms | 205056 KiB |
| 1_14.txt | AC | 105 ms | 203008 KiB |
| 1_15.txt | AC | 106 ms | 205056 KiB |
| 1_16.txt | AC | 106 ms | 205056 KiB |
| 1_17.txt | AC | 107 ms | 205056 KiB |
| 1_18.txt | AC | 105 ms | 203008 KiB |
| 1_19.txt | AC | 105 ms | 203008 KiB |
| 1_20.txt | AC | 104 ms | 203136 KiB |
| 1_21.txt | AC | 107 ms | 205056 KiB |
| 1_22.txt | AC | 106 ms | 205056 KiB |
| 1_23.txt | AC | 106 ms | 205056 KiB |
| 1_24.txt | AC | 105 ms | 203008 KiB |
| 1_25.txt | AC | 106 ms | 205056 KiB |
| 1_26.txt | AC | 102 ms | 198912 KiB |
| 1_27.txt | AC | 105 ms | 203008 KiB |
| 1_28.txt | AC | 105 ms | 203008 KiB |
| 1_29.txt | AC | 106 ms | 205056 KiB |
| 1_30.txt | AC | 104 ms | 203008 KiB |
| 1_31.txt | AC | 103 ms | 200960 KiB |
| 1_32.txt | AC | 106 ms | 205056 KiB |
| 1_33.txt | AC | 107 ms | 205056 KiB |
| 1_34.txt | AC | 103 ms | 200960 KiB |
| 1_35.txt | AC | 105 ms | 203008 KiB |
| 1_36.txt | AC | 100 ms | 196864 KiB |
| 1_37.txt | AC | 105 ms | 203008 KiB |
| 1_38.txt | AC | 106 ms | 205056 KiB |
| 1_39.txt | AC | 107 ms | 205056 KiB |