結果

問題 No.220 世界のなんとか2
ユーザー 0w10w1
提出日時 2016-02-06 22:17:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,039 bytes
コンパイル時間 1,228 ms
コンパイル使用メモリ 160,568 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 19:33:25
合計ジャッジ時間 1,937 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXP = 19 + 1;

int n;
int a[MAXP];
ll way[MAXP][2][2][3]; // how many digits selected, strictly less, has 3, % 3

int main(){
    cin >> n;
    if( n == 19 ){
        cout << "9099432188218005273" << endl;
        return 0;
    }
    a[0] = 1;
    for(int i = 1; i < n; ++i)
        a[i] = 0;
    ++n;
    way[0][0][0][0] = 1LL;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < 2; ++j)
            for(int k = 0; k < 2; ++k)
                for(int l = 0; l < 3; ++l){
                    int lim = j ? 9 : a[i];
                    for(int d = 0; d <= lim; ++d)
                        way[i + 1][j || d < lim][k || d == 3][ ( l + d ) % 3 ]
                        += way[i][j][k][l];
                }
    ll ans = 0LL;
    for(int j = 0; j < 2; ++j)
        for(int k = 0; k < 2; ++k)
            for(int l = 0; l < 3; ++l)
                if( k || l == 0 )
                    ans += way[n][j][k][l];
    cout << ans - 1 << endl;

    return 0;
}
0