QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#380491#8515. KMOPcorneasTL 1ms3772kbC++14830b2024-04-07 04:47:282024-04-07 04:47:28

Judging History

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

  • [2024-04-07 04:47:28]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3772kb
  • [2024-04-07 04:47:28]
  • 提交

answer

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

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, int &nn){
    if(level == nn){
        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, nn);
        else return;
    }
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
KNUTH
MORRIS
PRATT

output:

4

result:

ok "4"

Test #2:

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

input:

3
KNUTH
M
PRATT

output:

5

result:

ok "5"

Test #3:

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

input:

3
K
M
P

output:

*

result:

ok "*"

Test #4:

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

input:

2
K
M

output:

2

result:

ok "2"

Test #5:

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

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: