結果

問題 No.220 世界のなんとか2
ユーザー TomoyaTomoya
提出日時 2019-02-05 12:54:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,831 bytes
コンパイル時間 575 ms
コンパイル使用メモリ 78,472 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 22:06:28
合計ジャッジ時間 1,816 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

ll nl, nm;


//i桁目, mod 3, 3がつく
ll dp[32][3][2];

ll calc(string s){
  memset(dp, 0, sizeof(dp));
  int n = 0;
  while(true){
    if(s[n] == '.') break;
    n++;
  }
  n--;
  dp[0][0][0] = 1;
  REP(i, n) {
    REP(j, 3){
      REP(k, 2){
	//条件なくても間に合うなら d = 0~9まで試す
	REP(d, 10) dp[i+1][(j*10+d)%3][k|(d == 3)] += dp[i][j][k];
      }
    }  
  }
  ll ans = 0LL;
  //ここがわからんかった... 
  ans = dp[n][0][0] + dp[n][0][1] + dp[n][1][1] + dp[n][2][1];  
  return ans;
}

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

  ll p;
  cin >> p;
  string a = to_string(pow(10, p));

  //cout << a << endl;  
  cout << calc(a) - 1 << endl;
  
  return 0;
}
0