結果
| 問題 |
No.1677 mæx
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-01-04 01:03:54 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 89 ms / 2,000 ms |
| コード長 | 1,659 bytes |
| コンパイル時間 | 8,786 ms |
| コンパイル使用メモリ | 168,884 KB |
| 実行使用メモリ | 196,908 KB |
| 最終ジャッジ日時 | 2024-09-27 18:34:26 |
| 合計ジャッジ時間 | 11,501 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (84 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
static int NN => int.Parse(ReadLine());
static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
public static void Main()
{
Solve();
}
static void Solve()
{
var s = ReadLine();
var k = NN;
var pos = 0;
WriteLine(DFS(s, ref pos)[k]);
}
static int mod = 998_244_353;
static int[][] mex = new int[][] {
new int[] { 1, 2, 1 },
new int[] { 2, 0, 0 },
new int[] { 1, 0, 0 },
};
static int[][] max = new int[][] {
new int[] { 0, 1, 2 },
new int[] { 1, 1, 2 },
new int[] { 2, 2, 2 },
};
static long[] DFS(string s, ref int pos)
{
var ans = new long[3];
if (s[pos] != 'm')
{
if (s[pos] == '?') ans = new long[] { 1, 1, 1 };
else ans[s[pos] - '0'] = 1;
pos += 2;
return ans;
}
var domex = s[pos + 1] != 'a';
var domax = s[pos + 1] != 'e';
long[] a;
long[] b;
pos += 4;
a = DFS(s, ref pos);
b = DFS(s, ref pos);
++pos;
for (var i = 0; i < 3; ++i) for (var j = 0; j < 3; ++j)
{
if (domex) ans[mex[i][j]] = (ans[mex[i][j]] + a[i] * b[j] % mod) % mod;
if (domax) ans[max[i][j]] = (ans[max[i][j]] + a[i] * b[j] % mod) % mod;
}
return ans;
}
}