| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 889706 | vjudge1 | Chorus (JOI23_chorus) | C++17 | 7027 ms | 456 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, k; cin >> n >> k;
string s; cin >> s;
int m = s.size();
auto get = [&](auto &u){ return u == 'A' ? -1 : 1; };
auto ok = [&](auto &s){
queue <int> q;
vector <int> nxt(m, m + 1);
for ( int i = m - 1; i >= 0; i-- ){
if ( s[i] == 'B' ) q.push(i);
else{
if ( q.empty() ){
return false;
}
nxt[i] = q.front();
q.pop();
}
}
int cnt = 1, lst = -1;
vector <int> c(m);
for ( int i = m - 1; i >= 0; i-- ){
if ( s[i] != 'B' ) continue;
if ( lst == -1 ){
lst = i;
c[lst] = i;
} else{
int mn = m + 1;
for ( int k = lst - 1; k > i; k-- ){
chmin(mn, nxt[k]);
}
if ( mn <= c[lst] ){
c[i] = i;
++cnt;
} else c[i] = c[lst];
lst = i;
}
}
return cnt <= k;
};
vector <int> a;
for ( int i = 0; i < m; i++ ){
if ( s[i] == 'B' ) a.pb(i);
}
auto t = s;
sort(all(t));
int mn = n * n + 1;
do{
if ( !ok(t) ) continue;
vector <int> b;
for ( int i = 0; i < m; i++ ){
if ( t[i] == 'B' ) b.pb(i);
}
int ans = 0;
for ( int i = 0; i < n; i++ ){
ans += abs(a[i] - b[i]);
}
auto flag = chmin(mn, ans);
} while ( next_permutation(all(t)) );
cout << mn;
cout << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
