Submission #3013460
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int NMAX = 2005; const int INF = 1000000000; int n, a[NMAX], b[NMAX], mma[2 * NMAX][NMAX], mmb[2 * NMAX][NMAX], dp[NMAX][NMAX]; int main() { cin >> n; for (int i = 1; i <= 2 * n; i++) { char c; int x; cin >> c >> x; c == 'W' ? a[x] = i : b[x] = i; for (int j = 0; j < n; j++) { mma[i][j] = mma[i - 1][j]; mmb[i][j] = mmb[i - 1][j]; c == 'W' ? mma[i][j] += x > j : mmb[i][j] += x > j; } } for (int j = 1; j <= n; j++) dp[0][j] = INF; for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) { if (i) dp[i][j] = dp[i - 1][j] + mma[a[i]][i] + mmb[a[i]][j]; if (j) dp[i][j] = min(dp[i][j], dp[i][j - 1] + mma[b[j]][i] + mmb[b[j]][j]); } cout << dp[n][n]; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Sorted and Sorted |
User | lauran |
Language | C++14 (GCC 5.4.1) |
Score | 600 |
Code Size | 909 Byte |
Status | AC |
Exec Time | 70 ms |
Memory | 78720 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 600 / 600 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 2 ms | 4352 KB |
0_001.txt | AC | 1 ms | 4352 KB |
0_002.txt | AC | 1 ms | 4352 KB |
1_003.txt | AC | 1 ms | 4352 KB |
1_004.txt | AC | 2 ms | 4352 KB |
1_005.txt | AC | 1 ms | 4352 KB |
1_006.txt | AC | 2 ms | 4352 KB |
1_007.txt | AC | 2 ms | 4352 KB |
1_008.txt | AC | 2 ms | 4352 KB |
1_009.txt | AC | 1 ms | 4352 KB |
1_010.txt | AC | 2 ms | 4352 KB |
1_011.txt | AC | 1 ms | 4352 KB |
1_012.txt | AC | 1 ms | 4352 KB |
1_013.txt | AC | 2 ms | 4352 KB |
1_014.txt | AC | 55 ms | 73984 KB |
1_015.txt | AC | 12 ms | 30720 KB |
1_016.txt | AC | 42 ms | 63744 KB |
1_017.txt | AC | 20 ms | 43264 KB |
1_018.txt | AC | 2 ms | 6912 KB |
1_019.txt | AC | 9 ms | 26496 KB |
1_020.txt | AC | 48 ms | 69888 KB |
1_021.txt | AC | 23 ms | 43264 KB |
1_022.txt | AC | 13 ms | 32768 KB |
1_023.txt | AC | 42 ms | 63744 KB |
1_024.txt | AC | 65 ms | 78080 KB |
1_025.txt | AC | 68 ms | 78720 KB |
1_026.txt | AC | 67 ms | 78720 KB |
1_027.txt | AC | 68 ms | 78720 KB |
1_028.txt | AC | 67 ms | 78720 KB |
1_029.txt | AC | 67 ms | 78720 KB |
1_030.txt | AC | 68 ms | 78720 KB |
1_031.txt | AC | 68 ms | 78720 KB |
1_032.txt | AC | 70 ms | 78720 KB |
1_033.txt | AC | 67 ms | 78720 KB |
1_034.txt | AC | 68 ms | 78720 KB |
1_035.txt | AC | 68 ms | 78720 KB |