Submission #2501768
Source Code Expand
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<int> a(2 * n), b(n), w(n); vector<char> c(2 * n); for (int i = 0; i < 2 * n; i++) { cin >> c[i] >> a[i]; a[i]--; if (c[i] == 'B') b[a[i]] = i; else w[a[i]] = i; } ll ans = 0; for (int i = 0, j = 0, k = 0; k < 2 * n; k++) { int tar = -1; if (i == n) { tar = w[j]; j++; } else if (j == n) { tar = b[i]; i++; } else { if (abs(b[i] - k) < abs(w[j] - k)) { tar = b[i]; i++; } else { tar = w[j]; j++; } } for (int x = tar; x > k; x--) { if (c[x - 1] == 'B') b[a[x - 1]] = x; else w[a[x - 1]] = x; if (c[x] == 'B') b[a[x]] = x - 1; else w[a[x]] = x - 1; swap(c[x - 1], c[x]); swap(a[x - 1], a[x]); ans++; } } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Sorted and Sorted |
User | fine |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1215 Byte |
Status | WA |
Exec Time | 20 ms |
Memory | 384 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 | 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 | WA | 1 ms | 256 KB |
1_006.txt | WA | 1 ms | 256 KB |
1_007.txt | AC | 1 ms | 256 KB |
1_008.txt | WA | 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 | WA | 15 ms | 256 KB |
1_015.txt | WA | 3 ms | 256 KB |
1_016.txt | WA | 12 ms | 256 KB |
1_017.txt | WA | 5 ms | 256 KB |
1_018.txt | WA | 1 ms | 256 KB |
1_019.txt | WA | 3 ms | 256 KB |
1_020.txt | WA | 14 ms | 384 KB |
1_021.txt | AC | 2 ms | 256 KB |
1_022.txt | AC | 3 ms | 256 KB |
1_023.txt | AC | 2 ms | 256 KB |
1_024.txt | AC | 18 ms | 256 KB |
1_025.txt | WA | 20 ms | 256 KB |
1_026.txt | WA | 17 ms | 256 KB |
1_027.txt | WA | 18 ms | 256 KB |
1_028.txt | WA | 18 ms | 256 KB |
1_029.txt | WA | 19 ms | 256 KB |
1_030.txt | WA | 18 ms | 256 KB |
1_031.txt | WA | 19 ms | 256 KB |
1_032.txt | AC | 2 ms | 256 KB |
1_033.txt | AC | 13 ms | 256 KB |
1_034.txt | AC | 2 ms | 256 KB |
1_035.txt | AC | 19 ms | 256 KB |