結果
問題 |
No.3242 Count 8 Included Numbers (Hard)
|
ユーザー |
![]() |
提出日時 | 2025-08-25 11:34:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,974 bytes |
コンパイル時間 | 519 ms |
コンパイル使用メモリ | 43,964 KB |
実行使用メモリ | 7,720 KB |
最終ジャッジ日時 | 2025-08-25 11:34:51 |
合計ジャッジ時間 | 2,300 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 11 WA * 9 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:67:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 67 | scanf("%s", s); | ~~~~~^~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 3242.cc: No.3242 Count 8 Included Numbers (Hard) - yukicoder */ #include<cstdio> #include<cstring> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 888888; 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 { return MI(MOD - 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 % MOD MI 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 */ char s[MAX_N + 4]; mi es[MAX_N + 1]; /* subroutines */ /* main */ int main() { scanf("%s", s); int n = strlen(s); es[0] = 1; for (int i = 0; i < n; i++) es[i + 1] = es[i] * 9; mi s0 = 0; for (int i = 0; i < n; i++) s0 = s0 * 10 + (s[i] - '0'); s0 += 1; mi s1 = 0; bool f = false; for (int i = n - 1; ! f && i >= 0; i--) { int di = s[n - 1 - i] - '0'; int maxj = max(8, di); s1 += es[i] * di; if (di == 8) f = true; } if (! f) s1 += 1; //printf(" s0=%d, s1=%d\n", (int)s0, (int)s1); printf("%d\n", (int)(s0 - s1)); return 0; }