Submission #3730252
Source Code Expand
#include<bits/stdc++.h> #define fi first #define se second #define LL long long using namespace std; const int maxn = 2e3 + 5; typedef pair<int, int> P; int dp[maxn][maxn]; int pre[maxn << 1][maxn][2]; int a[maxn], b[maxn]; int n; char s[maxn]; int main() { #ifdef TT freopen("xxx.in", "r", stdin); #endif // TT scanf("%d", &n); for(int i = 1, u; i <= n + n; ++i) { scanf("%s%d", s, &u); if(s[0] == 'W') { a[u] = i; pre[i][u][0] ++; } else { b[u] = i; pre[i][u][1] ++; } } for(int T = 0; T < 2; ++T) { for(int i = 1; i <= n + n; ++i) { for(int j = 1; j <= n; ++j) { pre[i][j][T] += pre[i - 1][j][T]; } } for(int i = 1; i <= n + n; ++i) { for(int j = n; j; --j) { pre[i][j][T] += pre[i][j + 1][T]; } } } memset(dp, 0x3f, sizeof(dp)); dp[0][0] = 0; for(int i = 0; i <= n; ++i) { for(int j = 0; j <= n; ++j) { if(i < n) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + pre[a[i + 1]][i + 2][0] + pre[a[i + 1]][j + 1][1]); } if(j < n) { dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + pre[b[j + 1]][j + 2][1] + pre[b[j + 1]][i + 1][0]); } } } cout <<dp[n][n] <<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Sorted and Sorted |
User | vjudge3 |
Language | C++14 (GCC 5.4.1) |
Score | 600 |
Code Size | 1404 Byte |
Status | AC |
Exec Time | 161 ms |
Memory | 78720 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:18: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, &u); ^
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 | 6 ms | 17408 KB |
0_001.txt | AC | 6 ms | 17408 KB |
0_002.txt | AC | 6 ms | 17408 KB |
1_003.txt | AC | 6 ms | 17408 KB |
1_004.txt | AC | 6 ms | 17408 KB |
1_005.txt | AC | 6 ms | 17408 KB |
1_006.txt | AC | 6 ms | 17408 KB |
1_007.txt | AC | 6 ms | 17408 KB |
1_008.txt | AC | 6 ms | 17408 KB |
1_009.txt | AC | 6 ms | 17408 KB |
1_010.txt | AC | 6 ms | 17408 KB |
1_011.txt | AC | 6 ms | 17408 KB |
1_012.txt | AC | 6 ms | 17408 KB |
1_013.txt | AC | 6 ms | 17408 KB |
1_014.txt | AC | 121 ms | 74624 KB |
1_015.txt | AC | 24 ms | 39040 KB |
1_016.txt | AC | 91 ms | 66432 KB |
1_017.txt | AC | 40 ms | 47488 KB |
1_018.txt | AC | 7 ms | 19968 KB |
1_019.txt | AC | 18 ms | 34816 KB |
1_020.txt | AC | 106 ms | 70528 KB |
1_021.txt | AC | 46 ms | 49664 KB |
1_022.txt | AC | 27 ms | 41088 KB |
1_023.txt | AC | 100 ms | 66432 KB |
1_024.txt | AC | 132 ms | 78720 KB |
1_025.txt | AC | 148 ms | 78720 KB |
1_026.txt | AC | 148 ms | 78720 KB |
1_027.txt | AC | 148 ms | 78720 KB |
1_028.txt | AC | 149 ms | 78720 KB |
1_029.txt | AC | 149 ms | 78720 KB |
1_030.txt | AC | 153 ms | 78720 KB |
1_031.txt | AC | 150 ms | 78720 KB |
1_032.txt | AC | 151 ms | 78720 KB |
1_033.txt | AC | 156 ms | 78720 KB |
1_034.txt | AC | 161 ms | 78720 KB |
1_035.txt | AC | 134 ms | 78720 KB |