結果

問題 No.2356 Back Door Tour in Four Seasons
ユーザー Heart_BlueHeart_Blue
提出日時 2023-06-16 23:50:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,655 bytes
コンパイル時間 1,648 ms
コンパイル使用メモリ 132,452 KB
実行使用メモリ 5,192 KB
最終ジャッジ日時 2023-09-06 22:53:41
合計ジャッジ時間 7,679 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 119 ms
4,488 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 48 ms
5,192 KB
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

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[0] % mod;
	printf("%lld\n", ans);
	return 0;
}
0