Submission #3726967
Source Code Expand
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i)) using namespace std; template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); } template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); } int solve(int n, vector<char> const & c, vector<int> const & a) { auto dp = vectors(n + 1, n + 1, INT_MAX); dp[0][0] = 0; REP (w, n + 1) { REP (b, n + 1) { if (w - 1 >= 0) { int delta = 0; REP (i, 2 * n) { if (c[i] == 'W' and a[i] == w - 1) break; delta += a[i] >= (c[i] == 'B' ? b : w - 1); } chmin(dp[w][b], dp[w - 1][b] + delta); } if (b - 1 >= 0) { int delta = 0; REP (i, 2 * n) { if (c[i] == 'B' and a[i] == b - 1) break; delta += a[i] >= (c[i] == 'B' ? b - 1 : w); } chmin(dp[w][b], dp[w][b - 1] + delta); } } } return dp[n][n]; } int main() { int n; cin >> n; vector<char> c(2 * n); vector<int> a(2 * n); REP (i, 2 * n) { cin >> c[i] >> a[i]; -- a[i]; } cout << solve(n, c, a) << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Sorted and Sorted |
User | kimiyuki |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1498 Byte |
Status | TLE |
Exec Time | 2105 ms |
Memory | 18048 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 | 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 | TLE | 2104 ms | 12544 KB |
1_015.txt | AC | 1392 ms | 2048 KB |
1_016.txt | TLE | 2104 ms | 9344 KB |
1_017.txt | TLE | 2104 ms | 3968 KB |
1_018.txt | AC | 4 ms | 256 KB |
1_019.txt | AC | 737 ms | 1536 KB |
1_020.txt | TLE | 2104 ms | 10880 KB |
1_021.txt | TLE | 2103 ms | 4480 KB |
1_022.txt | AC | 978 ms | 2432 KB |
1_023.txt | TLE | 2104 ms | 9472 KB |
1_024.txt | TLE | 2104 ms | 15360 KB |
1_025.txt | TLE | 2104 ms | 16000 KB |
1_026.txt | TLE | 2103 ms | 18048 KB |
1_027.txt | TLE | 2105 ms | 16000 KB |
1_028.txt | TLE | 2104 ms | 16000 KB |
1_029.txt | TLE | 2104 ms | 16000 KB |
1_030.txt | TLE | 2104 ms | 16000 KB |
1_031.txt | TLE | 2104 ms | 16000 KB |
1_032.txt | TLE | 2104 ms | 16000 KB |
1_033.txt | TLE | 2104 ms | 16000 KB |
1_034.txt | TLE | 2104 ms | 16000 KB |
1_035.txt | TLE | 2103 ms | 18048 KB |