結果

問題 No.2356 Back Door Tour in Four Seasons
ユーザー Heart_BlueHeart_Blue
提出日時 2023-06-17 00:00:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 1,655 bytes
コンパイル時間 1,463 ms
コンパイル使用メモリ 131,316 KB
実行使用メモリ 5,132 KB
最終ジャッジ日時 2023-09-06 23:05:36
合計ジャッジ時間 5,967 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 103 ms
4,620 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 118 ms
4,380 KB
testcase_09 AC 132 ms
4,896 KB
testcase_10 AC 132 ms
4,384 KB
testcase_11 AC 131 ms
4,604 KB
testcase_12 AC 132 ms
4,384 KB
testcase_13 AC 132 ms
4,384 KB
testcase_14 AC 133 ms
4,600 KB
testcase_15 AC 66 ms
4,380 KB
testcase_16 AC 122 ms
4,452 KB
testcase_17 AC 125 ms
4,484 KB
testcase_18 AC 120 ms
4,616 KB
testcase_19 AC 68 ms
4,380 KB
testcase_20 AC 118 ms
4,728 KB
testcase_21 AC 96 ms
4,388 KB
testcase_22 AC 66 ms
4,380 KB
testcase_23 AC 48 ms
4,380 KB
testcase_24 AC 125 ms
4,496 KB
testcase_25 AC 4 ms
4,384 KB
testcase_26 AC 95 ms
4,380 KB
testcase_27 AC 124 ms
4,480 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 48 ms
5,132 KB
testcase_31 AC 48 ms
5,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e3 + 10;
const LL mod = 998244353;
LL powmod(LL a, LL b)
{
	a %= mod;
	LL ret = 1;
	while (b)
	{
		if (b & 1)
			ret = ret * a % mod;
		b >>= 1;
		a = a * a % mod;
	}
	return ret;
}
vector<int> v[4];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	LL cnt[4] = { 0,0,0,0 };
	LL tot[4] = { 0,0,0,0 };
	map<char, int> mc;
	mc['U'] = 0;
	mc['F'] = 1;
	mc['W'] = 2;
	mc['P'] = 3;
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		char c;
		int d;
		scanf(" %c%d", &c, &d);
		cnt[mc[c]]++;
		tot[mc[c]] += d;
		v[mc[c]].push_back(d);
	}
	if (tot[0] == 0 || tot[1] == 0 || tot[2] == 0)
	{
		puts("0");
		return 0;
	}
	// (x^ a - (x - 1) ^ a) + (n - 1) ^ rest
	LL ans = 1;
	for (int i = 0; i < 3; i++)
	{
		LL sum = 0;
		for (auto& d : v[i])
		{
			sum += (powmod(n - 1, d) - powmod(n - 2, d)) % mod * powmod(n - 1, tot[i] - d) % mod;
		}
		sum %= mod;
		ans = ans * sum % mod;
	}
	ans = ans * powmod(n - 1, tot[3]) % mod;
	if (ans < 0) ans += mod;
	ans = ans * cnt[3] % mod;
	printf("%lld\n", ans);
	return 0;
}
0