QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#408244#8515. KMOPucup-team191#WA 0ms15480kbC++231.9kb2024-05-09 21:42:032024-05-09 21:42:05

Judging History

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

  • [2024-05-09 21:42:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:15480kb
  • [2024-05-09 21:42:03]
  • 提交

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;
}

詳細信息

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'