| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 889809 | vjudge1 | Chorus (JOI23_chorus) | C++17 | 44 ms | 2132 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rnd(l, r) uniform_int_distribution<int>(l, r)(rng)
using namespace std;
void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
int pow(int a,int b,int m){int ans=1;while(b){if(b&1){ans=(ans*a)%m;}b>>=1;a=(a*a)%m;}return ans;}
int binpow(int a,int b){int ans=1;while(b){if(b&1){ans=(ans*a);}b>>=1;a=(a*a);}return ans;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 3e5 + 5, inf = 1e9, M = 3e4;
int calc(string a, string b){
int res = 0;
vector <int> pos;
for(int i = 0; i < (int)a.size(); i++){
if(a[i] == 'A'){
pos.pb(i);
}
}
for(int i = (int)b.size() - 1; i >= 0; i--){
if(b[i] == 'A'){
res += abs(pos.back() - i);
pos.pop_back();
}
}
return res;
}
main(){
iostream::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, k;
cin >> n >> k;
n *= 2;
string s;
cin >> s;
set<string> st;
int ans = inf;
for(int i = 0; i < ( 1 << n); i++){
if(__builtin_popcount(i) != n / 2)continue;
string t = "";
for(int j = 0; j < n; j++){
if(i & (1 << j))
t.pb('B');
else
t.pb('A');
}
string prev = t;
int r = n - 1, l = n - 1;
int cnt = 0;
for(int de = 0; de < k; de++){
while(r >= 0 && t[r] != 'A'){
if(t[r] == 'B')
cnt++;
r--;
}
l = r;
while(cnt && l >= 0){
if(t[l] == 'A'){
cnt--;
t[l] = '.';
}
l--;
}
}
if(l < 0 && cnt == 0){
st.insert(prev);
ans = min(ans, calc(s, prev));
//cout << i << endl;
}
}
cout << ans << endl;
}
/*
* Before implementing the problem:
Do I understand the problem correctly?
Which places are tricky? What do I need to remember to implement them correctly?
Which place is the heaviest by implementation? Can I do it simpler?
Which place is the slowest? Where do I need to be careful about constant factors and where I can choose slower but simpler implementation?
----------------------------------
If not AC:
Did you remember to do everything to handle the tricky places you thought about before?
Is the solution correct?
Do I understand the problem correctly?
----------------------------------
If you have a test on which the solution gives wrong answer:
Is the solution doing what it was supposed to do?
Is the problem in the code or in the idea?
*/
컴파일 시 표준 에러 (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... | ||||
