結果
問題 | No.2356 Back Door Tour in Four Seasons |
ユーザー |
|
提出日時 | 2023-06-17 00:00:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 142 ms / 2,000 ms |
コード長 | 1,655 bytes |
コンパイル時間 | 1,400 ms |
コンパイル使用メモリ | 128,176 KB |
最終ジャッジ日時 | 2025-02-14 21:42:01 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:58:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 58 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:63:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 63 | scanf(" %c%d", &c, &d); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#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) ^ restLL 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;}