結果

問題 No.1542 ぽんぽんぽん ぽんぽんぽんぽん ぽんぽんぽん
ユーザー 👑 ygussanyygussany
提出日時 2021-06-06 19:21:32
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 2,604 bytes
コンパイル時間 1,193 ms
コンパイル使用メモリ 31,820 KB
実行使用メモリ 7,628 KB
最終ジャッジ日時 2023-08-15 02:34:46
合計ジャッジ時間 13,999 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,032 KB
testcase_01 AC 1 ms
5,936 KB
testcase_02 AC 1 ms
6,020 KB
testcase_03 AC 1 ms
6,040 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
6,000 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
4,384 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

void chmax(int* a, int b)
{
	if (*a < b) *a = b;
}

int count(char S[])
{
	int i, j, k, l, dp[2][501][501], q[2][250001][2], head, tail, cur, prev, tmp;
	for (l = 0; S[l] != 0; l++);
	for (i = 0; i <= l; i++) {
		for (j = 0; j <= l; j++) {
			dp[0][i][j] = -1;
			dp[1][i][j] = -1;
		}
	}
	dp[1][0][0] = 0;
	q[1][0][0] = 0;
	q[1][0][1] = 0;
	tail = 1;
	for (k = 0, cur = 0, prev = 1; k < l; k++, cur ^= 1, prev ^= 1) {
		for (head = tail - 1, tail = 0; head >= 0; head--) {
			i = q[prev][head][0];
			j = q[prev][head][1];
			tmp = dp[prev][i][j];
			dp[prev][i][j] = -1;
			
			if (S[k] == 'p') {
				if (j == 0) {
					if (dp[cur][i+1][j] == -1) {
						q[cur][tail][0] = i + 1;
						q[cur][tail++][1] = j;
					}
					chmax(&(dp[cur][i+1][j]), tmp);
				} else {
					if (j % 2 == 0) {
						if (dp[cur][i][j+1] == -1) {
							q[cur][tail][0] = i;
							q[cur][tail++][1] = j + 1;
						}
						chmax(&(dp[cur][i][j+1]), tmp);
					}
					if (dp[cur][i][j] == -1) {
						q[cur][tail][0] = i;
						q[cur][tail++][1] = j;
					}
					chmax(&(dp[cur][i][j]), tmp);
				}
			} else if (S[k] == 'o') {
				if (j % 2 != 0) {
					if (dp[cur][i][j+1] == -1) {
						q[cur][tail][0] = i;
						q[cur][tail++][1] = j + 1;
					}
					chmax(&(dp[cur][i][j+1]), tmp);
				} else {
					if (i > 0 && j == 0) {
						if (dp[cur][i-1][j+2] == -1) {
							q[cur][tail][0] = i - 1;
							q[cur][tail++][1] = j + 2;
						}
						chmax(&(dp[cur][i-1][j+2]), tmp);
					}
					if (dp[cur][i][j] == -1) {
						q[cur][tail][0] = i;
						q[cur][tail++][1] = j;
					}
					chmax(&(dp[cur][i][j]), tmp);
				}
			} else {
				if (j > 0 && j % 2 == 0) {
					if (dp[cur][i][j-2] == -1) {
						q[cur][tail][0] = i;
						q[cur][tail++][1] = j - 2;
					}
					chmax(&(dp[cur][i][j-2]), tmp + 1);
				} else {
					if (j > 0) {
						if (dp[cur][i][j-3] == -1) {
							q[cur][tail][0] = i;
							q[cur][tail++][1] = j - 3;
						}
						chmax(&(dp[cur][i][j-3]), tmp + 1);
					}
					if (dp[cur][i][j] == -1) {
						q[cur][tail][0] = i;
						q[cur][tail++][1] = j;
					}
					chmax(&(dp[cur][i][j]), tmp);
				}
			}
		}
	}
	
	int ans = 0;
	for (head = 0; head < tail; head++) {
		i = q[prev][head][0];
		j = q[prev][head][1];
		chmax(&ans, dp[prev][i][j]);
	}
	return ans;
}

int main()
{
	int N;
	char S[501];
	scanf("%d", &N);
	scanf("%s", S);
	
	int i, j, k, ans = -1;
	char c;
	for (i = 3; i < N - 2; i++) {
		c = S[i];
		S[i] = 0;
		j = count(S);
		S[i] = c;
		k = count(&(S[i]));
		if (j >= 1 && k >= 1) chmax(&ans, j + k - 2);
	}
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}
0