QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#408244 | #8515. KMOP | ucup-team191# | WA | 0ms | 15480kb | C++23 | 1.9kb | 2024-05-09 21:42:03 | 2024-05-09 21:42:05 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 1e6 + 500;
const int INF = 0x3f3f3f3f;
int n;
bool vowel(char c) {
return (c == 'A') || (c == 'E') || (c == 'O') || (c == 'I') || (c == 'U') || (c == 'Y');
}
int dp[N][3];
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
memset(dp, -1, sizeof(dp));
dp[0][0] = 0; dp[0][1] = -1; dp[0][2] = -1;
for(int i = 1;i <= n;i++) {
string s; cin >> s;
int x = 0;
while(x < (int)s.size() && !vowel(s[x])) x++;
if(x >= 3) {
continue;
}
if(x == (int)s.size()) {
if(dp[i - 1][0] != -1) dp[i][1] = dp[i - 1][0] + 1;
if(dp[i - 1][1] != -1) dp[i][2] = dp[i - 1][1] + 1;
} else if(x == 0) {
dp[i][0] = INF;
if(dp[i - 1][0] != -1) dp[i][0] = min(dp[i][0], dp[i - 1][0] + 1 + x);
if(dp[i - 1][1] != -1) dp[i][0] = min(dp[i][0], dp[i - 1][1] + 1 + x);
if(dp[i - 1][2] != -1) dp[i][0] = min(dp[i][0], dp[i - 1][2] + 1 + x);
if(dp[i][0] == INF) dp[i][0] = -1;
} else if(x == 1) {
if(dp[i - 1][0] != -1) dp[i][1] = dp[i - 1][0] + 1;
if(dp[i - 1][1] != -1) dp[i][2] = dp[i - 1][1] + 1;
dp[i][0] = INF;
if(dp[i - 1][0] != -1) dp[i][0] = min(dp[i][0], dp[i - 1][0] + 1 + x);
if(dp[i - 1][1] != -1) dp[i][0] = min(dp[i][0], dp[i - 1][1] + 1 + x);
if(dp[i][0] == INF) dp[i][0] = -1;
} else if(x == 2) {
if(dp[i - 1][0] != -1) dp[i][1] = dp[i - 1][0] + 1;
if(dp[i - 1][1] != -1) dp[i][2] = dp[i - 1][1] + 1;
dp[i][0] = INF;
if(dp[i - 1][0] != -1) dp[i][0] = min(dp[i][0], dp[i - 1][0] + 1 + x);
if(dp[i][0] == INF) dp[i][0] = -1;
}
// cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl;
}
int ans = INF;
if(dp[n][0] != -1) ans = min(ans, dp[n][0]);
if(dp[n][1] != -1) ans = min(ans, dp[n][1]);
if(dp[n][2] != -1) ans = min(ans, dp[n][2]);
cout << (ans < INF ? ans : -1) << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 15480kb
input:
3 KNUTH MORRIS PRATT
output:
4
result:
ok "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 15304kb
input:
3 KNUTH M PRATT
output:
5
result:
ok "5"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 15312kb
input:
3 K M P
output:
-1
result:
wrong answer 1st words differ - expected: '*', found: '-1'