結果

問題 No.1185 完全な3の倍数
ユーザー Falcon_
提出日時 2020-08-22 17:23:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 720 bytes
コンパイル時間 1,708 ms
コンパイル使用メモリ 167,960 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-15 11:15:34
合計ジャッジ時間 2,937 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 33 WA * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 0;
    if(S.at(i)=='0'){count/=4;return p(S,i+1,count);}
    if(S.at(i)=='3'){count/=4;return p(S,i+1,count)+count;}
    if(S.at(i)=='6'){count/=4;return p(S,i+1,count)+count*2;}
    if(S.at(i)=='9'){count/=4;return p(S,i+1,count)+count*3;}
    if(S.at(i)<'3')return 0;
    if(S.at(i)<'6')return count/3;
    if(S.at(i)<'9')return count/3*2;
}
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