結果
| 問題 |
No.3040 Aoiスコア
|
| コンテスト | |
| ユーザー |
pengin_2000
|
| 提出日時 | 2025-02-28 22:22:41 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 1,000 ms |
| コード長 | 1,652 bytes |
| コンパイル時間 | 633 ms |
| コンパイル使用メモリ | 28,752 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 20:58:54 |
| 合計ジャッジ時間 | 1,218 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:18:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
18 | scanf("%lld %lld", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:19:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
19 | scanf("%s", s);
| ^~~~~~~~~~~~~~
main.c:23:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | scanf("%lld %lld", &u[i], &v[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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;
}
pengin_2000