結果

問題 No.220 世界のなんとか2
ユーザー nenuonnenuon
提出日時 2017-07-22 15:05:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 882 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 92,220 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 15:48:41
合計ジャッジ時間 1,435 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 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 <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
ll dp[100][2][2][3]; // みた桁数、小さいことが確定してるか、3がつくか、3の倍数か
int main()
{
  int P;
  cin>>P;
  string s('0',P);
  s = '1' + s;
  int len = P + 1;
  
  dp[0][0][0][0] = 1;
  FOR(i,0,len) FOR(j,0,2) FOR(k,0,2) FOR(l,0,3) {
    int lim = j ? 9 : s[i] - '0';
    FOR(d,0,lim+1) {
      dp[i+1][j||d<lim][k||d==3][(l+d)%3] += dp[i][j][k][l];
    }
  }
  ll ans = 0;
  FOR(j,0,2) FOR(k,0,2) FOR(l,0,3){
    if(k || l==0)
      ans += dp[len][j][k][l];
  }
  cout << ans - 1 << endl;
  return 0;
}
0