QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#597858#6338. ChorusDimash#16 562ms23948kbC++171.5kb2024-09-28 19:10:412024-09-28 19:10:45

Judging History

你现在查看的是最新测评结果

  • [2024-09-28 19:10:45]
  • 评测
  • 测评结果:16
  • 用时:562ms
  • 内存:23948kb
  • [2024-09-28 19:10:41]
  • 提交

answer

#include <bits/stdc++.h>
    
using namespace std;
    
typedef long long ll;
const int  N = 2e5 + 12, MOD = (int)1e9 + 7;

const int inf = (int)1e9;
int n, k, res = inf;
string s;
map<string, bool> vis;

bool good(string s) {
    set<int> a;
    for(int i = 0; i < n + n; i++) {
        a.insert(i);
    }
    int f = 0;
    while(!a.empty()) {
        int col = 0;
        vector<int> del;
        for(int j:a) {
            if(s[j] == 'A') {
                del.push_back(j);
                col++;
            } else {
                break;
            }
        }
        if(!col) {
            return false;
        }
        f++;
        for(int j:a) {
            if(s[j] == 'B') {
                col--;
                del.push_back(j);
                if(!col) break;
            }
        }
        for(int t:del) {
            a.erase(t);
        }
    }
    return (f <= k);
}
void go(string s, int dep =0 ) {
    if(vis.count(s)) return;
    if(good(s)) {
        res = min(res, dep);
        return;
    }
    vis[s] = 1;
    for(int i = 0; i < n + n - 1; i++) {
        if(s[i] == 'A' && s[i + 1] == 'B') continue;;
        swap(s[i], s[i + 1]);
        go(s, dep + 1);
        swap(s[i], s[i + 1]);
    }
}
void test() {
    cin >> n >> k >> s;
    go(s);
    cout << res << '\n';
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); 
    
    int t = 1; 
    // cin >> t;
    
    while(t--) 
        test();
    return 0;
}

详细

Subtask #1:

score: 16
Accepted

Test #1:

score: 16
Accepted
time: 0ms
memory: 3564kb

input:

1 1
BA

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 16
Accepted
time: 1ms
memory: 3608kb

input:

7 5
ABBAAABBABABBA

output:

3

result:

ok 1 number(s): "3"

Test #3:

score: 16
Accepted
time: 196ms
memory: 10544kb

input:

10 3
BABBABAABAABBABBBAAA

output:

26

result:

ok 1 number(s): "26"

Test #4:

score: 16
Accepted
time: 6ms
memory: 3960kb

input:

10 2
AAABBABABBAAABBBAABB

output:

11

result:

ok 1 number(s): "11"

Test #5:

score: 16
Accepted
time: 552ms
memory: 23852kb

input:

10 1
BBBBBBBBBBAAAAAAAAAA

output:

100

result:

ok 1 number(s): "100"

Test #6:

score: 16
Accepted
time: 562ms
memory: 23948kb

input:

10 2
BBBBBBBBBBAAAAAAAAAA

output:

75

result:

ok 1 number(s): "75"

Test #7:

score: 16
Accepted
time: 526ms
memory: 22040kb

input:

10 9
BBBBBBBBBBAAAAAAAAAA

output:

56

result:

ok 1 number(s): "56"

Test #8:

score: 16
Accepted
time: 533ms
memory: 21892kb

input:

10 10
BBBBBBBBBBAAAAAAAAAA

output:

55

result:

ok 1 number(s): "55"

Test #9:

score: 16
Accepted
time: 0ms
memory: 3560kb

input:

10 10
ABABABABABABABABABAB

output:

0

result:

ok 1 number(s): "0"

Test #10:

score: 16
Accepted
time: 20ms
memory: 4248kb

input:

10 2
ABAAABABABBBABABABAB

output:

14

result:

ok 1 number(s): "14"

Test #11:

score: 16
Accepted
time: 3ms
memory: 3672kb

input:

10 4
ABAABBAAABBBAAABBBAB

output:

2

result:

ok 1 number(s): "2"

Test #12:

score: 16
Accepted
time: 3ms
memory: 3672kb

input:

10 4
ABAAABBBAAABBBAABBAB

output:

2

result:

ok 1 number(s): "2"

Subtask #2:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Test #13:

score: 0
Time Limit Exceeded

input:

179 54
AAABABABABBAAABBABBABBABBBAAABAAAAABBBABAAAAABABBBAABBBABABBAABABAABABBBBABAABAABABABBBABBAABABBAABBAABABBAAABAAAAAAAABBAAAAABAAABBBBBBBABBAABBBABABAABBAABBABABABBABAAABABAAABABABBAABABAAABBABABABABABBAAABABBBBBBBAABBBAABABBBBABAABBAAAABAABBABABAABAAABABAAAABBBAABAAABBABABBBABAAABAABBBABBBBBA...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%