結果

問題 No.2356 Back Door Tour in Four Seasons
ユーザー 沙耶花沙耶花
提出日時 2023-06-16 22:12:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 205 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 4,005 ms
コンパイル使用メモリ 261,824 KB
実行使用メモリ 5,752 KB
最終ジャッジ日時 2023-09-06 20:12:31
合計ジャッジ時間 9,493 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 189 ms
5,752 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 189 ms
5,472 KB
testcase_09 AC 203 ms
5,528 KB
testcase_10 AC 201 ms
5,420 KB
testcase_11 AC 200 ms
5,468 KB
testcase_12 AC 205 ms
5,412 KB
testcase_13 AC 203 ms
5,424 KB
testcase_14 AC 203 ms
5,476 KB
testcase_15 AC 102 ms
4,380 KB
testcase_16 AC 190 ms
5,152 KB
testcase_17 AC 193 ms
5,216 KB
testcase_18 AC 184 ms
5,268 KB
testcase_19 AC 105 ms
4,380 KB
testcase_20 AC 182 ms
5,324 KB
testcase_21 AC 150 ms
4,744 KB
testcase_22 AC 104 ms
4,380 KB
testcase_23 AC 75 ms
4,380 KB
testcase_24 AC 193 ms
5,264 KB
testcase_25 AC 7 ms
4,380 KB
testcase_26 AC 148 ms
4,736 KB
testcase_27 AC 193 ms
5,216 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 185 ms
5,464 KB
testcase_31 AC 185 ms
5,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001


int main(){
	
	int N;
	cin>>N;
	
	vector<int> x(N),y(N);
	rep(i,N){
		char c;
		cin>>c;
		if(c=='U')x[i] = 0;
		if(c=='F')x[i] = 1;
		if(c=='W')x[i] = 2;
		if(c=='P')x[i] = 3;
		cin>>y[i];
	}
	
	vector<mint> dp(1<<4,0);
	dp[0] = 1;
	rep(i,N){
		vector<mint> ndp(1<<4);
		mint A = mint(N-1).pow(y[i]);
		mint B = mint(N-1).pow(y[i]) - mint(N-2).pow(y[i]);
		rep(j,1<<4){
			ndp[j] += dp[j] * A;
			if((j>>x[i])&1)continue;
			if(x[i]!=3)ndp[j|(1<<x[i])] += dp[j] * B;
			else ndp[j|(1<<x[i])] += dp[j] * A;
		}
		swap(dp,ndp);
	}
	cout<<dp.back().val()<<endl;
	
	return 0;
}
0