QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#189656#5474. Incredibly Cute Penguin ChicksGenshinImpactsFault#RE 1ms7840kbC++172.8kb2023-09-27 19:10:262023-09-27 19:10:27

Judging History

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

  • [2023-09-27 19:10:27]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:7840kb
  • [2023-09-27 19:10:26]
  • 提交

answer

#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-6
#define FOR(i, a, b) for(int i = a; i <= b; i ++)
#define REP(i, a, b) for(int i = a; i >= b; i --)
#define pb push_back
#define fr first
#define sd second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch = getchar();
	ll s = 0, w = 1;
	while(ch < '0' || ch > '9'){if(ch == '-')w = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){s = s * 10 + ch - '0'; ch = getchar();}
	return s * w;
}
#define N 100010
#define mid ((l + r) >> 1)
const int mod = 998244353;
int rt[3][N << 1];
int s[3][N];
char a[N];
int sum[N * 80], ls[N * 80], rs[N * 80];
int n, dp[N];
int M, cnt;
void add(int &x, int l, int r, int pos, int w)
{
	if(!x)x = ++ cnt; sum[x] = (sum[x] + w) % mod;
	if(l == r)return ;
	if(pos <= mid)add(ls[x], l, mid, pos, w);
	else add(rs[x], mid + 1, r, pos, w);
}
int qry(int x, int l, int r, int ql, int qr)
{
	if(ql > qr)return 0;
	if(!x)return 0;
	if(l == ql && r == qr)return sum[x];
	if(qr <= mid)return qry(ls[x], l, mid, ql, qr);
	else if(ql > mid)return qry(rs[x], mid + 1, r, ql, qr);
	else return (qry(ls[x], l, mid, ql, mid) + qry(rs[x], mid + 1, r, mid + 1, qr)) % mod;
}
void add(int i)
{
//	cout << "EE:" << i << ' ' << dp[i] << " " << 3 * s[0][i] - i << ' ' << 3 * s[1][i] - i << ' ' << 3 * s[2][i] - i << endl;
//	cout << "ADD:" << s[0][i] - s[1][i] << ' ' << s[0][i] - s[2][i] << ' ' << s[1][i] - s[2][i] << endl;
	add(rt[0][s[0][i] - s[1][i] + n], -M, M, 3 * s[0][i] - i, dp[i]);
	add(rt[1][s[0][i] - s[2][i] + n], -M, M, 3 * s[2][i] - i, dp[i]);
	add(rt[2][s[1][i] - s[2][i] + n], -M, M, 3 * s[1][i] - i, dp[i]);
}
int qry(int i)
{
	int S = 0;
//	cout << "GG:" << i << endl;
//	cout << "EMM:" << i << ' ' << 3 * s[0][i] - i << ' ' << 3 * s[1][i] - i << ' ' << 3 * s[2][i] - i << endl;
//	cout << "QRY:" << s[0][i] - s[1][i] << ' ' << s[0][i] - s[2][i] << ' ' << s[1][i] - s[2][i] << endl;
//	cout << qry(rt[0][s[0][i] - s[1][i] + n], -M, M, 3 * s[0][i] - i + 1, M) << ' ' << qry(rt[1][s[0][i] - s[2][i] + n], -M, M, 3 * s[2][i] - i + 1, M) << ' ' << qry(rt[2][s[1][i] - s[2][i] + n], -M, M, 3 * s[1][i] - i + 1, M) << endl; 
	S = (S + qry(rt[0][s[0][i] - s[1][i] + n], -M, M, 3 * s[0][i] - i + 1, M)) % mod;
	S = (S + qry(rt[1][s[0][i] - s[2][i] + n], -M, M, 3 * s[2][i] - i + 1, M)) % mod;
	S = (S + qry(rt[2][s[1][i] - s[2][i] + n], -M, M, 3 * s[1][i] - i + 1, M)) % mod;
	return S;
}
int main()
{
	
	scanf("%s", a + 1); n = strlen(a + 1);
	M = 3 * n;
	FOR(i, 1, n)
	{
		FOR(j, 0, 2)s[j][i] = s[j][i - 1];
		if(a[i] == 'I')s[0][i] ++;
		if(a[i] == 'C')s[1][i] ++;
		if(a[i] == 'P')s[2][i] ++;
	}
	dp[0] = 1;add(0);
	FOR(i, 1, n)
	{
		dp[i] = qry(i);
		add(i);
	}
//	FOR(i, 1, n)cout << dp[i] << ' '; cout << endl;
	cout << dp[n] << '\n';
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5564kb

input:

ICPC

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 1ms
memory: 7840kb

input:

CCCIIIPPP

output:

69

result:

ok single line: '69'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5624kb

input:

PICCICCIPPI

output:

24

result:

ok single line: '24'

Test #4:

score: -100
Runtime Error

input:

PCPPCCICPICPCPCPCCPPIPPPIICCCICPICCPPPIPCCCCICCIICPCCICCCPCICIPPIPIPIPPCCPCIPPCCPPCCIPPPIPPCIICIIIPPCIPPICPPICCPIICCCCCCCICPCCPPIPIPICPCIICPCCIPICCCPPCPIIICPCPPPIIIIICCCPCICCPPCPPCICIIIPIPICPCPPPPICPCPIPIIICCICPCIPPICCICPIIPPCCCIICPCPCCICCPICPPPPPPICCCIPCCICICIPICIIICCICPCIPIICPIPIIICCPCCIIPCCCCPIPI...

output:


result: