QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#380475#8515. KMOPcorneasTL 1ms3804kbC++14809b2024-04-07 04:34:042024-04-07 04:34:05

Judging History

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

  • [2024-04-07 04:34:05]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3804kb
  • [2024-04-07 04:34:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int n;
string s, ans = "";
vector<string> v;

bool isVowel(char c){
    return (c=='U'||c=='A'||c=='O'||c=='I'||c=='E'|| c=='Y');
}

void bt(string ss, int level, int freq){
    if(level == n){
        if(ans == "")ans = ss;
        else if(ans.size() > ss.size())ans = ss;
        return;
    }
    for(int i = 0; i < v[level].size(); ++i){
        ss += v[level][i];
        if(isVowel(v[level][i]))freq = 0;
        else ++freq;
        if(freq < 3)bt(ss, level + 1, freq);
        else return;
    }
}

int main(){
    cin>>n;
    for(int i = 0; i < n; ++i){
        cin>>s;
        v.push_back(s.substr(0,3));
    }
    bt("", 0, 0);
    if(ans == "")cout<<'*';
    else cout<<ans.size();
    cout<<'\n';
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3804kb

input:

3
KNUTH
MORRIS
PRATT

output:

4

result:

ok "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

3
KNUTH
M
PRATT

output:

5

result:

ok "5"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3484kb

input:

3
K
M
P

output:

*

result:

ok "*"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3612kb

input:

2
K
M

output:

2

result:

ok "2"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

4
YOU
SHOULD
BE
DANCING

output:

5

result:

ok "5"

Test #6:

score: -100
Time Limit Exceeded

input:

1000000
Y
E
U
O
I
E
I
E
E
Y
I
I
E
Y
E
U
U
O
A
I
U
O
Y
I
Y
Y
U
A
O
E
U
I
A
U
U
I
A
I
U
A
Y
I
E
U
I
O
Y
U
Y
Y
I
E
O
Y
E
A
U
O
O
I
A
E
I
I
Y
U
A
E
Y
Y
A
O
O
Y
A
U
E
A
O
I
O
Y
A
E
I
U
I
E
Y
O
U
O
I
I
Y
E
I
A
Y
U
I
I
Y
E
E
U
O
O
U
A
I
Y
A
I
I
E
O
O
A
A
I
U
I
U
O
E
U
I
E
A
O
E
A
I
O
O
Y
I
U
U
A
I
A
Y
O
A
...

output:


result: