Submission #2501806
Source Code Expand
#include<iostream> #include<iomanip> #include<math.h> #include<vector> #include<algorithm> #include<set> #include<map> #include<unordered_map> #include<queue> #include<stack> #include<string> #include<bitset> #include<random> #include<time.h> #define MOD 1000000007ll #define INF 1000000000ll #define EPS 1e-10 #define REP(i,m) for(long long i=0; i<(ll)m; i++) #define FOR(i,n,m) for(long long i=n; i<(ll)m; i++) #define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; } #define ALL(v) v.begin(),v.end() #define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); #define pb push_back using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef long double ld; ll N = 2020; ll bit[2020]; void add(ll a, ll w) { a++; for (ll x = a; x <= N; x += x & -x) bit[x] += w; } ll sum(ll a) { a++; ll ret = 0; for (ll x = a; x > 0; x -= x & -x) ret += bit[x]; return ret; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin>>n; vector<ll> a(2*n); vector<char> c(2*n); REP(i,2*n) cin>>c[i]>>a[i]; REP(i,2*n) a[i]--; ll ans=0; vector<bool> aprd_w(n,false); vector<bool> aprd_b(n,false); for(ll i=2*n-1; i>=0; i--) { if(c[i]=='W') { aprd_w[a[i]]=true; REP(j,a[i]) if(aprd_w[j])ans++; } else { aprd_b[a[i]]=true; REP(j,a[i]) if(aprd_b[j])ans++; } } vector<vector<ll>> cnt(n,vector<ll>(n+1,0)); for(ll i=2*n-1; i>=0; i--) { if(c[i]=='W') { add(a[i],1); } else { REP(j,n+1) { if(j>0) cnt[a[i]][j]+=sum(j-1); if(j<n) cnt[a[i]][j]+=(n-j)-(sum(2019)-cnt[a[i]][j]); } } } vector<vector<ll>> dp(n,vector<ll>(n+1,INF)); REP(i,n) { // 黒 i の球までを REP(j,n+1) { // 白 j より左にいれる if(j>0) dp[i][j]=dp[i][j-1]; if(i>0) dp[i][j]=min(dp[i][j],dp[i-1][j]+cnt[i][j]); else dp[i][j]=min(dp[i][j],cnt[i][j]); } } ll tmp=INF*INF; REP(i,n+1) tmp=min(tmp,dp[n-1][i]); cout<<ans+tmp<<endl; }
Submission Info
Submission Time | |
---|---|
Task | E - Sorted and Sorted |
User | gazelle |
Language | C++14 (GCC 5.4.1) |
Score | 600 |
Code Size | 2081 Byte |
Status | AC |
Exec Time | 88 ms |
Memory | 62976 KB |
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 | 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 | 69 ms | 49280 KB |
1_015.txt | AC | 11 ms | 7552 KB |
1_016.txt | AC | 51 ms | 36736 KB |
1_017.txt | AC | 22 ms | 15232 KB |
1_018.txt | AC | 1 ms | 384 KB |
1_019.txt | AC | 8 ms | 5248 KB |
1_020.txt | AC | 60 ms | 42880 KB |
1_021.txt | AC | 24 ms | 17024 KB |
1_022.txt | AC | 13 ms | 8960 KB |
1_023.txt | AC | 52 ms | 37120 KB |
1_024.txt | AC | 84 ms | 60672 KB |
1_025.txt | AC | 88 ms | 62976 KB |
1_026.txt | AC | 88 ms | 62976 KB |
1_027.txt | AC | 88 ms | 62976 KB |
1_028.txt | AC | 88 ms | 62976 KB |
1_029.txt | AC | 88 ms | 62976 KB |
1_030.txt | AC | 88 ms | 62976 KB |
1_031.txt | AC | 88 ms | 62976 KB |
1_032.txt | AC | 88 ms | 62976 KB |
1_033.txt | AC | 88 ms | 62976 KB |
1_034.txt | AC | 88 ms | 62976 KB |
1_035.txt | AC | 88 ms | 62976 KB |