結果

問題 No.1185 完全な3の倍数
ユーザー Falcon_
提出日時 2020-08-22 17:36:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 838 bytes
コンパイル時間 1,568 ms
コンパイル使用メモリ 168,084 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-24 09:33:28
合計ジャッジ時間 2,762 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int p(std::string, int, int)':
main.cpp:12:1: warning: control reaches end of non-void function [-Wreturn-type]
   12 | }
      | ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int p(string S,int i,int count){
    if(S.size()==i)return 1;
    if(S.at(i)=='0'){count/=4;return p(S,i+1,count);}
    if(S.at(i)=='3'){count/=(i==0? 3:4);return p(S,i+1,count)+(i==0? 0:count);}
    if(S.at(i)=='6'){count/=(i==0? 3:4);return p(S,i+1,count)+count*(i==0? 1:2);}
    if(S.at(i)=='9'){count/=(i==0? 3:4);return p(S,i+1,count)+count*(i==0? 2:3);}
    if(S.at(i)<'3')return (i==0? 0:count/4);
    if(S.at(i)<'6')return count/(i==0? 3:4)*(i==0? 1:2);
    if(S.at(i)<'9')return count/(i==0? 3:4)*(i==0? 2:3);
}
int main(){
    int N;cin>>N;
    if(N<100){
        cout<<(N-9)/3<<endl;
        return 0;
    }
    int ans=30;
    string S=to_string(N);
    int count=48;
    for(int i=3;i<S.size();i++){
        ans+=count;
        count*=4;
    }
    cout<<p(S,0,count)+ans<<endl;
}
0