結果

問題 No.3040 Aoiスコア
コンテスト
ユーザー pengin_2000
提出日時 2025-02-28 22:22:41
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 1,652 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 345 ms
コンパイル使用メモリ 45,392 KB
最終ジャッジ日時 2026-02-22 12:43:25
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<stdio.h>
long long int modpow(long long int a, long long int n, long long int p)
{
	if (n < 0)
		return 0;
	long long int res = 1;
	for (; n > 0; n /= 2, a = a * a % p)
		if (n % 2 > 0)
			res = res * a % p;
	return res;
}
long long int u[20004], v[20004];
char s[10004];
long long int cnt[10004][3];
int main()
{
	long long int n, m;
	scanf("%lld %lld", &n, &m);
	scanf("%s", s);
	long long int i;
	for (i = 0; i < m; i++)
	{
		scanf("%lld %lld", &u[i], &v[i]);
		u[i + m] = --v[i];
		v[i + m] = --u[i];
	}
	m *= 2;
	const long long int p = 998244353;
	for (i = 0; i < n; i++)
		cnt[i][0] = cnt[i][1] = cnt[i][2] = 0;
	for (i = 0; i < m; i++)
	{
		if (s[u[i]] == 'a')
			cnt[v[i]][0]++;
		else if (s[u[i]] == 'i')
			cnt[v[i]][1]++;
		else if (s[u[i]] == '?')
			cnt[v[i]][2]++;
	}
	long long int q = 0;
	for (i = 0; i < n; i++)
		if (s[i] == '?')
			q++;
	long long int ans = 0;
	for (i = 0; i < n; i++)
	{
		if (s[i] == 'o')
		{
			ans += cnt[i][0] * cnt[i][1] % p * modpow(26, q, p) % p;
			ans %= p;
			ans += cnt[i][0] * cnt[i][2] % p * modpow(26, q - 1, p) % p;
			ans %= p;
			ans += cnt[i][2] * cnt[i][1] % p * modpow(26, q - 1, p) % p;
			ans %= p;
			ans += cnt[i][2] * (cnt[i][2] - 1) % p * modpow(26, q - 2, p) % p;
			ans %= p;
		}
		else if (s[i] == '?')
		{
			q--;
			ans += cnt[i][0] * cnt[i][1] % p * modpow(26, q, p) % p;
			ans %= p;
			ans += cnt[i][0] * cnt[i][2] % p * modpow(26, q - 1, p) % p;
			ans %= p;
			ans += cnt[i][2] * cnt[i][1] % p * modpow(26, q - 1, p) % p;
			ans %= p;
			ans += cnt[i][2] * (cnt[i][2] - 1) % p * modpow(26, q - 2, p) % p;
			ans %= p;
			q++;
		}
	}
	printf("%lld\n", ans);
	return 0;
}
0