제출 #501974

#제출 시각아이디문제언어결과실행 시간메모리
501974amunduzbaevMonochrome Points (JOI20_monochrome)C++14
0 / 100
1 ms316 KiB
#include "bits/stdc++.h" using namespace std; #define ar array #define int long long signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin>>n; string s; cin>>s; vector<ar<int, 2>> a(n); for(int l = 0, r = n - 1, i=0;i<2*n;i++){ if(s[i] == 'B') a[l][0] = i, l++; else a[r][1] = i, r--; } auto check = [&](ar<int, 2> a, ar<int, 2> b){ if(a[0] > a[1]) swap(a[0], a[1]); if(b[0] > b[1]) swap(b[0], b[1]); if(a[0] <= b[0] && b[1] <= a[1]) return false; if(b[0] <= a[0] && a[1] <= b[1]) return false; return (max(a[0], b[0]) <= min(a[1], b[1])); }; for(int i=0;i<n;i++){ bool ok = (a[i][0] <= a[i][1]); for(int j=i+1;j<n;j++){ if(ok && a[j][0] <= a[j][1] && a[j][1] <= a[i][1]){ swap(a[j][1], a[i][1]); } if(!ok && a[j][0] >= a[j][1] && a[i][1] >= a[j][1]){ swap(a[j][1], a[i][1]); } } } int res = 0; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ res += check(a[i], a[j]); } } cout<<res<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...