結果
問題 | No.2807 Have Another Go (Easy) |
ユーザー |
![]() |
提出日時 | 2024-07-15 17:34:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 3,000 ms |
コード長 | 2,200 bytes |
コンパイル時間 | 414 ms |
コンパイル使用メモリ | 42,240 KB |
最終ジャッジ日時 | 2025-02-23 15:47:13 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 46 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:83:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 83 | scanf("%d%d%d", &n, &m, &k); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:84:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 84 | for (int i = 0; i < k; i++) scanf("%d", cs + i); | ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-** 2807.cc: No.2807 Have Another Go (Easy) - yukicoder*/#include<cstdio>#include<algorithm>using namespace std;/* constant */const int MAX_N = 500000;const int MAX_M = 2;const int MAX_NM = MAX_N * MAX_M;const int MAX_K = 5000;const int MOD = 998244353;/* typedef */template<const int MOD>struct MI {int v;MI(): v() {}MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; }MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; }explicit operator int() const { return v; }MI operator+(const MI m) const { return MI(v + m.v); }MI operator-(const MI m) const { return MI(v + MOD - m.v); }MI operator*(const MI m) const { return MI((long long)v * m.v); }MI &operator+=(const MI m) { return (*this = *this + m); }MI &operator-=(const MI m) { return (*this = *this - m); }MI &operator*=(const MI m) { return (*this = *this * m); }bool operator==(const MI m) const { return v == m.v; }bool operator!=(const MI m) const { return v != m.v; }MI pow(int n) const { // a^n % MODMI pm = 1, a = *this;while (n > 0) {if (n & 1) pm *= a;a *= a;n >>= 1;}return pm;}MI inv() const { return pow(MOD - 2); }MI operator/(const MI m) const { return *this * m.inv(); }MI &operator/=(const MI m) { return (*this = *this / m); }};using mi = MI<MOD>;/* global variables */int cs[MAX_K];mi dp[MAX_NM + 6];/* subroutines */mi calc1(int nm, int i) {mi sum = 0;for (int j = 1; j <= 6 && nm - i - j >= 0; j++)sum += dp[nm - i - j] * (7 - j);return dp[i] * sum;}mi calc2(int nm, int i0, int i1) {mi sum = 0;for (int j = 1; j <= 6 && nm - i1 - j >= 0; j++)sum += dp[nm - i1 - j] * (7 - j);return dp[i0] * dp[i1 - i0] * sum;}/* main */int main() {int n, m, k;scanf("%d%d%d", &n, &m, &k);for (int i = 0; i < k; i++) scanf("%d", cs + i);int nm = n * m;dp[0] = 1;for (int i = 0; i < nm; i++)for (int j = 1; j <= 6; j++)dp[i + j] += dp[i];for (int i = 0; i < k; i++) {int j0 = cs[i], j1 = j0 + n;mi d = calc1(nm, j0) + calc1(nm, j1) - calc2(nm, j0, j1);printf("%d\n", (int)d);}return 0;}