結果

問題 No.220 世界のなんとか2
ユーザー risujirohrisujiroh
提出日時 2018-09-08 15:52:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,146 bytes
コンパイル時間 1,814 ms
コンパイル使用メモリ 177,780 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-22 11:11:13
合計ジャッジ時間 2,859 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int p; cin >> p;
  string x(p + 1, '0');
  x[0] = '1';
  int n = x.size();
  VV<VV<lint>> dp; assign(dp, n + 1, 2, 3, 2);
  dp[0][1][0][0] = 1;
  for (int i = 0; i < n; i++) for (int r = 0; r < 3; r++) for (int d = 0; d < 10; d++) {
    dp[i + 1][0][(r + d) % 3][d == 3] += dp[i][0][r][0];
    dp[i + 1][0][(r + d) % 3][1] += dp[i][0][r][1];
    if (d > x[i] - '0') continue;
    dp[i + 1][d == x[i] - '0'][(r + d) % 3][d == 3] += dp[i][1][r][0];
    dp[i + 1][d == x[i] - '0'][(r + d) % 3][1] += dp[i][1][r][1];
  }
  lint res = 0;
  for (int f = 0; f < 2; f++) for (int r = 0; r < 3; r++) for (int g = 0; g < 2; g++) if (!r or g) res += dp[n][f][r][g];
  cout << res - 1 << '\n';
}
0