QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#226297#5474. Incredibly Cute Penguin ChicksOAleksaTL 0ms3824kbC++14923b2023-10-25 19:43:562023-10-25 19:43:57

Judging History

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

  • [2023-10-25 19:43:57]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3824kb
  • [2023-10-25 19:43:56]
  • 提交

answer

#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
#define int long long
signed main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int tt = 1;
   //cin >> tt;
   while(tt--) {
		string s;
		cin >> s;
		int n = s.size();
		s = "#" + s;
		const int mod = 998244353;
		auto add = [&](int x, int y) {
			x += y;
			if (x >= mod)
				x -= mod;
			return x;
		};
		vector<int> dp(n + 1);
		dp[0] = 1;
		for (int i = 1;i <= n;i++) {
			int x = 0, y = 0, z = 0;
			for (int j = i;j >= 1;j--) {
				x += (s[j] == 'I');
				y += (s[j] == 'C');
				z += (s[j] == 'P');
				if (x > y && x > z && y == z)
					dp[i] = add(dp[i], dp[j - 1]);
				else if (y > x && y > z && x == z)
					dp[i] = add(dp[i], dp[j - 1]);
				else if (z > x && z > y && y == x)
					dp[i] = add(dp[i], dp[j - 1]);
			}
		}
		cout << dp[n];
   }
   return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

input:

ICPC

output:

2

result:

ok single line: '2'

Test #2:

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

input:

CCCIIIPPP

output:

69

result:

ok single line: '69'

Test #3:

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

input:

PICCICCIPPI

output:

24

result:

ok single line: '24'

Test #4:

score: -100
Time Limit Exceeded

input:

PCPPCCICPICPCPCPCCPPIPPPIICCCICPICCPPPIPCCCCICCIICPCCICCCPCICIPPIPIPIPPCCPCIPPCCPPCCIPPPIPPCIICIIIPPCIPPICPPICCPIICCCCCCCICPCCPPIPIPICPCIICPCCIPICCCPPCPIIICPCPPPIIIIICCCPCICCPPCPPCICIIIPIPICPCPPPPICPCPIPIIICCICPCIPPICCICPIIPPCCCIICPCPCCICCPICPPPPPPICCCIPCCICICIPICIIICCICPCIPIICPIPIIICCPCCIIPCCCCPIPI...

output:


result: