結果

問題 No.220 世界のなんとか2
ユーザー noynotenoynote
提出日時 2017-08-28 16:42:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 842 bytes
コンパイル時間 2,111 ms
コンパイル使用メモリ 196,932 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 01:50:37
合計ジャッジ時間 2,869 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 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 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 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 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
const long long M = 1000000007;
using namespace std;

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

    string s = "1";
    rep(i,n) s+='0';

    long long dp[30][2][2][3] = {0}; //i文字まで見た、sより小さい、3が含まれる、mod 3
    dp[0][0][0][0] = 1;

    rep(i,s.size()) rep(j,2) rep(k,2) rep(l,3) {
        int lim = j ? 9 : s[i] - '0';
        rep(d,lim + 1){
            dp[i + 1][j || d < lim][k || (d == 3)][(l + d) % 3] += dp[i][j][k][l];
        }
    }

    long long ans = 0;
    rep(i,2) rep(j,2) rep(k,3) if(j || k == 0) ans += dp[s.size()][i][j][k];
    cout << ans - 1 << endl;
}
0