結果

問題 No.220 世界のなんとか2
ユーザー HankHank
提出日時 2017-08-29 21:43:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,006 bytes
コンパイル時間 870 ms
コンパイル使用メモリ 94,268 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 02:59:34
合計ジャッジ時間 1,300 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
 
#define MOD 1000000007
#define ll long long 
#define ld long double
#define rep(i,n) for(ll i =0;i<n;i++)
using namespace std;

ll withModDP(string s, ll _witha, ll _moda){
  ll n = s.size();
  ll dp[n+1][2][2][_moda]; // keta,less,forbid, mod  _moda, mod _modb
  rep(i,n+1)rep(j,2)rep(k,2)rep(l,_moda) dp[i][j][k][l] = 0;
  
  dp[0][0][0][0] = 1;
  rep(keta,n)rep(less,2)rep(ng,2)rep(l,_moda){
    int lim = less? 9 : s[keta]-'0';
    rep(d,lim+1)
      dp[keta+1][less||d<lim][ng||d==_witha][(l+d)%_moda] += dp[keta][less][ng][l];      
  }

  ll result = 0;
  rep(less,2)rep(ng,2)rep(l,_moda){   
    if( (ng || l==0))result += dp[n][less][ng][l];
  }
  return result;
  
}

int main(){ 
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll a;
  cin >> a;
  string s = "1";
  for(ll i =0;i<a;i++){
    s += "0";
  }
  cout <<  withModDP(s,3,3)-1 << endl;
}
0