# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
949994 |
2024-03-20T02:44:53 Z |
Abito |
Chorus (JOI23_chorus) |
C++17 |
|
19 ms |
16476 KB |
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
typedef unsigned long long ull;
using namespace std;
const int N=21,M=1e6+5;
int dis[M],n,k;
char a[N];
void bfs(int s){
dis[s]=0;
queue<int> q;q.push(s);
while (!q.empty()){
int x=q.front();q.pop();
for (int i=0;i<2*n-1;i++){
if ((x&(1<<i)) && (x&(1<<(i+1)))) continue;
if (!(x&(1<<i)) && !(x&(1<<(i+1)))) continue;
int y=x;
y^=(1<<i);
y^=(1<<(i+1));
if (dis[y]==-1) dis[y]=dis[x]+1,q.push(y);
}
}return;
}
bool check(int s){
int x=0,y=0;
bool vis[20]={0};
for (int i=2*n-1;i>=0;i--){
if (s&(1<<i)){
x++;
continue;
}
if (vis[i]) continue;
y++;
for (int j=i;j>=0 && x;j--){
if (s&(1<<j)) continue;
if (vis[j]) continue;
vis[j]=1;x--;
}
}
return y<=k && !x;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
memset(dis,-1,sizeof(dis));
cin>>n>>k;int mask=0;
for (int i=0;i<2*n;i++){
cin>>a[i];
if (a[i]=='B') mask|=(1<<i);
}
bfs(mask);
int ans=INT_MAX;
for (int i=0;i<M;i++){
if (dis[i]==-1) continue;
if (check(i)) ans=min(ans,dis[i]);
}cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8024 KB |
Output is correct |
2 |
Correct |
4 ms |
8284 KB |
Output is correct |
3 |
Correct |
3 ms |
8284 KB |
Output is correct |
4 |
Runtime error |
19 ms |
16476 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8024 KB |
Output is correct |
2 |
Correct |
4 ms |
8284 KB |
Output is correct |
3 |
Correct |
3 ms |
8284 KB |
Output is correct |
4 |
Runtime error |
19 ms |
16476 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8024 KB |
Output is correct |
2 |
Correct |
4 ms |
8284 KB |
Output is correct |
3 |
Correct |
3 ms |
8284 KB |
Output is correct |
4 |
Runtime error |
19 ms |
16476 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8024 KB |
Output is correct |
2 |
Correct |
4 ms |
8284 KB |
Output is correct |
3 |
Correct |
3 ms |
8284 KB |
Output is correct |
4 |
Runtime error |
19 ms |
16476 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8024 KB |
Output is correct |
2 |
Correct |
4 ms |
8284 KB |
Output is correct |
3 |
Correct |
3 ms |
8284 KB |
Output is correct |
4 |
Runtime error |
19 ms |
16476 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |