結果

問題 No.1185 完全な3の倍数
ユーザー betrue12
提出日時 2020-09-01 03:28:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 630 bytes
コンパイル時間 2,243 ms
コンパイル使用メモリ 194,712 KB
最終ジャッジ日時 2025-01-14 02:49:16
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    int N;
    cin >> N;
    int N2 = N;
    vector<int> D(11);
    for(int i=0; i<11; i++){
        D[i] = N2 % 10;
        N2 /= 10;
    }
    static int dp[11][2];
    dp[10][0] = 1;
    for(int i=9; i>=0; i--) for(int l=0; l<2; l++) for(int d : {0, 3, 6, 9}){
        if(l==0 && d > D[i]) continue;
        dp[i][l|(d<D[i])] += dp[i+1][l];
    }

    int ans = dp[0][0] + dp[0][1];
    for(int d : {0, 3, 6, 9}) if(d <= N) ans--;
    for(int i=0; i<10; i++) for(int j=0; j<10; j++) if(i%3 && (i+j)%3==0 && 10*i+j <= N) ans++;
    cout << ans << endl;
    return 0;
}
0