Submission #1037798

# Submission time Handle Problem Language Result Execution time Memory
1037798 2024-07-29T08:32:08 Z 변재우(#10984) Chorus (JOI23_chorus) C++17
16 / 100
12 ms 456 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int Nmax=20;
int N, K, ans=INT_MAX, A[Nmax];
string s;

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>N>>K>>s;
    for(int i=0; i<2*N; i++) A[i]=(s[i]=='B');
    for(int i=0; i<(1<<(2*N)); i++) if(__builtin_popcount(i)==N) {
        bool flag=true, chk[Nmax]={0};
        int cnt=0, tot=0;
        for(int j=0; j<2*N; j++) {
            int t=((i>>j)&1);
            if(t) {
                if(chk[j]) continue;
                if(!cnt) {
                    flag=false; break;
                }
                for(int k=j; k<2*N && cnt; k++) if(i&(1<<k)) chk[k]=true, cnt--;
                tot++;
            }
            else cnt++;
        }
        if(tot>K || !flag) continue;
        vector<int> X, Y;
        for(int j=0; j<2*N; j++) {
            if(i&(1<<j)) X.push_back(j);
            else Y.push_back(j);
        }
        int tmp=0;
        for(int j=0, p=0, q=0; j<2*N; j++) {
            if(A[j]) tmp+=abs(j-X[p++]);
            else tmp+=abs(j-Y[q++]);
        }
        ans=min(ans, tmp/2);
    }
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 6 ms 348 KB Output is correct
8 Correct 5 ms 348 KB Output is correct
9 Correct 5 ms 448 KB Output is correct
10 Correct 5 ms 448 KB Output is correct
11 Correct 9 ms 348 KB Output is correct
12 Correct 9 ms 348 KB Output is correct
13 Correct 9 ms 348 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 11 ms 456 KB Output is correct
16 Correct 12 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 6 ms 348 KB Output is correct
8 Correct 5 ms 348 KB Output is correct
9 Correct 5 ms 448 KB Output is correct
10 Correct 5 ms 448 KB Output is correct
11 Correct 9 ms 348 KB Output is correct
12 Correct 9 ms 348 KB Output is correct
13 Correct 9 ms 348 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 11 ms 456 KB Output is correct
16 Correct 12 ms 344 KB Output is correct
17 Runtime error 1 ms 348 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 6 ms 348 KB Output is correct
8 Correct 5 ms 348 KB Output is correct
9 Correct 5 ms 448 KB Output is correct
10 Correct 5 ms 448 KB Output is correct
11 Correct 9 ms 348 KB Output is correct
12 Correct 9 ms 348 KB Output is correct
13 Correct 9 ms 348 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 11 ms 456 KB Output is correct
16 Correct 12 ms 344 KB Output is correct
17 Runtime error 1 ms 348 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 6 ms 348 KB Output is correct
8 Correct 5 ms 348 KB Output is correct
9 Correct 5 ms 448 KB Output is correct
10 Correct 5 ms 448 KB Output is correct
11 Correct 9 ms 348 KB Output is correct
12 Correct 9 ms 348 KB Output is correct
13 Correct 9 ms 348 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 11 ms 456 KB Output is correct
16 Correct 12 ms 344 KB Output is correct
17 Runtime error 1 ms 348 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 6 ms 348 KB Output is correct
8 Correct 5 ms 348 KB Output is correct
9 Correct 5 ms 448 KB Output is correct
10 Correct 5 ms 448 KB Output is correct
11 Correct 9 ms 348 KB Output is correct
12 Correct 9 ms 348 KB Output is correct
13 Correct 9 ms 348 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 11 ms 456 KB Output is correct
16 Correct 12 ms 344 KB Output is correct
17 Runtime error 1 ms 348 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -