結果

問題 No.1185 完全な3の倍数
ユーザー recososo
提出日時 2020-08-29 11:30:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,442 bytes
コンパイル時間 1,592 ms
コンパイル使用メモリ 171,364 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-24 09:49:58
合計ジャッジ時間 2,624 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    int t=s.size();
    vector<vector<int>> dp(t+1,vector<int>(2));
    dp[0][0]=1;
    REP(i,t){
        int p=s[i]-'0';
        REP(j,2){
            if(j){
                dp[i+1][1]+=4*dp[i][1];
            }
            else{
                if(p%3==0){
                    dp[i+1][0]+=dp[i][0];
                    dp[i+1][1]+=(p/3)*dp[i][0];
                }
                else{

                    dp[i+1][1]+=(p/3+1)*dp[i][0];
                }
            }
        }
    }
    int n=stoi(s);
    int cnt=0;
    for(int i=10;i<=min(n,99);i++){
        if(i%3==0){
            if((i/10+i%10)%3==0&&i%10%3!=0){
                cnt++;
            }
        }
    }
    cout << dp[t][0]+dp[t][1]-4+cnt << endl;
}
0