Submission #8400522
Source Code Expand
#include<bits/stdc++.h> using namespace std; #define taskname "A" #define pb push_back #define mp make_pair #ifndef LOCAL #define cerr if(0)cout #endif typedef long double ld; typedef long long ll; typedef pair<int,int> ii; const int maxn = 2005; const int maxm = 1e4 + 5; int n; ii a[maxn * 2]; int cost[maxn][2][maxn][2]; int dp[maxn][maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(taskname".INP","r")){ freopen(taskname".INP", "r",stdin); freopen(taskname".OUT", "w",stdout); } cin >> n; for(int i = 1 ; i <= n * 2 ; ++i){ char x;cin >> x >> a[i].second; if(x == 'W')a[i].first = 0; else a[i].first = 1; } for(int i = 1 ; i <= n * 2 ; ++i){ for(int j = n * 2 ; j > i ; --j){ cost[a[i].second][a[i].first][a[j].second][a[j].first]++; } for(int j = 1 ; j <= n ; ++j){ for(int k = 0 ; k < 2 ; ++k){ cost[a[i].second][a[i].first][j][k] += cost[a[i].second][a[i].first][j - 1][k]; } } } fill_n(&dp[0][0],maxn*maxn,1e9); dp[0][0] = 0; for(int i = 0 ; i <= n ; ++i){ for(int j = 0 ; j <= n ; ++j){ if(i == 0 && j == 0)continue; if(i > 0)dp[i][j] = min(dp[i][j] , dp[i - 1][j] + cost[i][0][i - 1][0] + cost[i][0][j][1]); if(j > 0)dp[i][j] = min(dp[i][j] , dp[i][j - 1] + cost[j][1][i][0] + cost[j][1][j - 1][1]); } } cout << dp[n][n]; }
Submission Info
Submission Time | |
---|---|
Task | E - Sorted and Sorted |
User | thanhqt2002 |
Language | C++14 (GCC 5.4.1) |
Score | 600 |
Code Size | 1550 Byte |
Status | AC |
Exec Time | 99 ms |
Memory | 78720 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:27:43: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result] freopen(taskname".INP", "r",stdin); ^ ./Main.cpp:28:44: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result] freopen(taskname".OUT", "w",stdout); ^
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 | 16640 KB |
0_001.txt | AC | 6 ms | 16640 KB |
0_002.txt | AC | 6 ms | 16640 KB |
1_003.txt | AC | 6 ms | 16768 KB |
1_004.txt | AC | 6 ms | 16640 KB |
1_005.txt | AC | 6 ms | 16640 KB |
1_006.txt | AC | 6 ms | 16640 KB |
1_007.txt | AC | 6 ms | 16640 KB |
1_008.txt | AC | 6 ms | 16640 KB |
1_009.txt | AC | 6 ms | 16640 KB |
1_010.txt | AC | 6 ms | 16640 KB |
1_011.txt | AC | 6 ms | 16640 KB |
1_012.txt | AC | 6 ms | 16640 KB |
1_013.txt | AC | 6 ms | 16640 KB |
1_014.txt | AC | 79 ms | 71936 KB |
1_015.txt | AC | 18 ms | 39168 KB |
1_016.txt | AC | 61 ms | 63744 KB |
1_017.txt | AC | 30 ms | 47360 KB |
1_018.txt | AC | 7 ms | 20736 KB |
1_019.txt | AC | 14 ms | 35072 KB |
1_020.txt | AC | 70 ms | 67840 KB |
1_021.txt | AC | 30 ms | 49408 KB |
1_022.txt | AC | 20 ms | 41216 KB |
1_023.txt | AC | 56 ms | 65792 KB |
1_024.txt | AC | 85 ms | 78080 KB |
1_025.txt | AC | 98 ms | 78720 KB |
1_026.txt | AC | 99 ms | 78720 KB |
1_027.txt | AC | 98 ms | 78720 KB |
1_028.txt | AC | 98 ms | 78720 KB |
1_029.txt | AC | 98 ms | 78720 KB |
1_030.txt | AC | 98 ms | 78720 KB |
1_031.txt | AC | 98 ms | 78720 KB |
1_032.txt | AC | 89 ms | 78720 KB |
1_033.txt | AC | 89 ms | 78720 KB |
1_034.txt | AC | 89 ms | 78720 KB |
1_035.txt | AC | 88 ms | 78720 KB |