結果

問題 No.220 世界のなんとか2
ユーザー LuzhiledLuzhiled
提出日時 2016-10-21 14:22:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 674 bytes
コンパイル時間 2,390 ms
コンパイル使用メモリ 145,028 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-15 10:24:54
合計ジャッジ時間 3,482 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

string N;
int p;

long long dp[21][2][2][4][2];

long long dfs(long long i=0, bool tight=true ,bool lz=true, long long sum=0, bool th=false)
{
  long long &ret = dp[i][tight][lz][sum][th];

  if (ret != -1) return ret;
  if (i == N.size()){
    if (lz) return 0;
    return (sum == 0 | th);
  }

  int x = N[i] - '0';
  int r = (tight ? x : 9);
  ret = 0;
  for (int j = 0; j <= r; ++j){
    ret += dfs(i + 1, tight && j == x, lz && j == 0, (sum + j) % 3, th || j == 3);
  }

  return ret;
}
int main()
{
  memset(dp, -1, sizeof(dp));

  cin >> p;
  N = "1";
  for (int i = 0; i < p; i++) N += '0';

  cout << dfs() << endl;
}
0