結果

問題 No.220 世界のなんとか2
ユーザー sashimingsashiming
提出日時 2019-08-27 02:12:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,419 bytes
コンパイル時間 1,481 ms
コンパイル使用メモリ 166,888 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-08 23:26:32
合計ジャッジ時間 2,821 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define prique priority_queue
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int int_fast64_t

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

int dp[24][2][3][2]; // pos, smllr, mod3, exist3

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

  int P; cin >> P;
  string S = "1";
  REP(i, P) S += "0";
  dp[0][0][0][0] = 1;
  REP(i, S.size()){
    int D = S[i]-'0';
    REP(j, 2) REP(k, 3) REP(l, 2){
      for(int d = 0; d <= (j ? 9 : D); d++){
        dp[i+1][j or (d<D)][(k+d)%3][l or d==3] += dp[i][j][k][l];
      }
    }
  }
  int ans = 0;
  REP(i, 2) REP(j, 3) REP(k, 2){
    if(j!=0 and k!=1) continue;
    ans += dp[S.size()][i][j][k];
  }
  cout << ans << endl;
}
0