Submission #3928637
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int N = 2005; struct BIT{ int d[2 * N]; void i(){ fill(d + 1, d + 2 * N, 0); } void u(int x){ for(; x < 2 * N; x += x & -x) d[x]++; } void r(int x){ for(; x < 2 * N; x += x & -x) d[x]--; } int g(int x){ int r = 0; for(; x; x -= x & -x) r += d[x]; return r; } } B; int n, b[N], w[N], d[N][N], r = N * N; int main(){ scanf("%d", &n); for(int i = 1; i <= 2 * n; i++){ char s[3]; int x; scanf("%s%d", s, &x); if(s[0] == 'B') b[x] = i; else w[x] = i; } for(int i = 0; i <= n; i++) fill(d[i], d[i] + n + 1, N * N); d[0][0] = 0; for(int i = 0; i <= n; i++){ B.i(); for(int k = i + 1; k <= n; k++) B.u(b[k]); for(int k = 1; k <= n; k++) B.u(w[k]); for(int j = 0; j <= n; j++){ if(i < n) d[i + 1][j] = min(d[i + 1][j], d[i][j] + B.g(b[i + 1] - 1)); if(j < n) d[i][j + 1] = min(d[i][j + 1], d[i][j] + B.g(w[j + 1] - 1)); if(j < n) B.r(w[j + 1]); } } printf("%d\n", min(d[n][n - 1], d[n - 1][n])); }
Submission Info
Submission Time | |
---|---|
Task | E - Sorted and Sorted |
User | kdh9949 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1140 Byte |
Status | WA |
Exec Time | 193 ms |
Memory | 16000 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:17:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.cpp:20:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s%d", s, &x); ^
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 | 1 ms | 256 KB |
0_001.txt | AC | 1 ms | 256 KB |
0_002.txt | AC | 1 ms | 256 KB |
1_003.txt | AC | 1 ms | 256 KB |
1_004.txt | AC | 1 ms | 256 KB |
1_005.txt | AC | 1 ms | 256 KB |
1_006.txt | AC | 1 ms | 256 KB |
1_007.txt | AC | 1 ms | 256 KB |
1_008.txt | AC | 1 ms | 256 KB |
1_009.txt | AC | 1 ms | 256 KB |
1_010.txt | AC | 1 ms | 256 KB |
1_011.txt | AC | 1 ms | 256 KB |
1_012.txt | AC | 1 ms | 256 KB |
1_013.txt | AC | 1 ms | 256 KB |
1_014.txt | AC | 151 ms | 14592 KB |
1_015.txt | AC | 23 ms | 6144 KB |
1_016.txt | AC | 113 ms | 12544 KB |
1_017.txt | AC | 47 ms | 8448 KB |
1_018.txt | AC | 2 ms | 768 KB |
1_019.txt | AC | 17 ms | 6016 KB |
1_020.txt | AC | 132 ms | 14592 KB |
1_021.txt | AC | 38 ms | 8448 KB |
1_022.txt | AC | 22 ms | 6144 KB |
1_023.txt | AC | 78 ms | 12544 KB |
1_024.txt | WA | 132 ms | 15616 KB |
1_025.txt | AC | 193 ms | 16000 KB |
1_026.txt | AC | 193 ms | 16000 KB |
1_027.txt | AC | 192 ms | 16000 KB |
1_028.txt | AC | 193 ms | 16000 KB |
1_029.txt | AC | 193 ms | 16000 KB |
1_030.txt | AC | 193 ms | 16000 KB |
1_031.txt | AC | 193 ms | 16000 KB |
1_032.txt | AC | 129 ms | 16000 KB |
1_033.txt | AC | 138 ms | 16000 KB |
1_034.txt | AC | 129 ms | 16000 KB |
1_035.txt | WA | 143 ms | 16000 KB |