結果

問題 No.1542 ぽんぽんぽん ぽんぽんぽんぽん ぽんぽんぽん
ユーザー 👑 ygussanyygussany
提出日時 2021-06-06 19:08:52
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 2,281 bytes
コンパイル時間 1,554 ms
コンパイル使用メモリ 32,512 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-05-02 14:38:42
合計ジャッジ時間 5,539 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 (dp[cur][i][j] == -1) {
				q[cur][tail][0] = i;
				q[cur][tail++][1] = j;
			}
			chmax(&(dp[cur][i][j]), tmp);
			
			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);
				}
			} 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);
				}
			} 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);
				}
			}
		}
	}
	
	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