Submission #3920406
Source Code Expand
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <queue> #include <bitset> #include <set> using namespace std; int dp[2002][2002]; int cnt_white[2002][2002]; int cnt_black[2002][2002]; int main(){ int N; cin >> N; map<int, int> white, black; for(int i=0; i<2*N; i++){ char c; int a; cin >> c >> a; if(c == 'W') white[a] = i+1; else black[a] = i+1; } int aa[2002]; fill_n(aa, 2002, 0); for(int i=N; i>=1; i--){ aa[white[i]] = 1; for(int j=1; j<=2*N; j++) cnt_white[i][j] = cnt_white[i][j-1] + aa[j]; } fill_n(aa, 2002, 0); for(int i=N; i>=1; i--){ aa[black[i]] = 1; for(int j=1; j<=2*N; j++) cnt_black[i][j] = cnt_black[i][j-1] + aa[j]; } for(int i=0; i<=N; i++) for(int j=0; j<=N; j++) dp[i][j] = 1<<30; dp[0][0] = 0; for(int i=0; i<2*N; i++){ for(int w=0; w<=i; w++){ int b = i - w; if(b < 0 || w < 0) continue; if(w < N) dp[w+1][b] = min(dp[w+1][b], dp[w][b] + cnt_white[w+2][white[w+1]] + cnt_black[b+1][white[w+1]]); if(b < N) dp[w][b+1] = min(dp[w][b+1], dp[w][b] + cnt_black[b+2][black[b+1]] + cnt_white[w+1][black[b+1]]); } } cout << dp[N][N] << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Sorted and Sorted |
User | suzume |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1451 Byte |
Status | RE |
Exec Time | 581 ms |
Memory | 47360 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | 2 ms | 4352 KB |
0_002.txt | AC | 2 ms | 4352 KB |
1_003.txt | AC | 2 ms | 4352 KB |
1_004.txt | AC | 2 ms | 4352 KB |
1_005.txt | AC | 2 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 | 2 ms | 4352 KB |
1_010.txt | AC | 2 ms | 4352 KB |
1_011.txt | AC | 2 ms | 4352 KB |
1_012.txt | AC | 2 ms | 4352 KB |
1_013.txt | AC | 2 ms | 4352 KB |
1_014.txt | RE | 99 ms | 2432 KB |
1_015.txt | AC | 139 ms | 26880 KB |
1_016.txt | RE | 99 ms | 2432 KB |
1_017.txt | AC | 307 ms | 33920 KB |
1_018.txt | AC | 5 ms | 8960 KB |
1_019.txt | AC | 94 ms | 22784 KB |
1_020.txt | RE | 99 ms | 2432 KB |
1_021.txt | RE | 419 ms | 34176 KB |
1_022.txt | AC | 169 ms | 26880 KB |
1_023.txt | RE | 98 ms | 384 KB |
1_024.txt | RE | 99 ms | 2432 KB |
1_025.txt | RE | 99 ms | 2432 KB |
1_026.txt | RE | 99 ms | 384 KB |
1_027.txt | RE | 101 ms | 2432 KB |
1_028.txt | RE | 580 ms | 47360 KB |
1_029.txt | RE | 101 ms | 2432 KB |
1_030.txt | RE | 581 ms | 47360 KB |
1_031.txt | RE | 99 ms | 2432 KB |
1_032.txt | RE | 558 ms | 47360 KB |
1_033.txt | RE | 99 ms | 2432 KB |
1_034.txt | RE | 100 ms | 384 KB |
1_035.txt | RE | 99 ms | 2432 KB |