結果

問題 No.220 世界のなんとか2
ユーザー tossytossy
提出日時 2017-01-01 17:42:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 984 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 89,256 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-22 09:13:32
合計ジャッジ時間 1,744 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define long long long

long dp[21][2][3];
// [上から何桁][3を使った][mod3]

int main(){
  int p;
  cin>>p;

  fill(dp[0][0], dp[20][0], 0);
  dp[0][0][0]=1;

  rep(i,p) rep(j,2) rep(k,3){
    rep(l,10) dp[i+1][j | (l==3)][(k*10+l)%3] += dp[i][j][k];
  }

  long ans=0;
  rep(i,3) ans += dp[p][1][i];
  ans += dp[p][0][0];

  cout << ans-1 << endl; // このままだと0を含む

  return 0;
}
0