結果

問題 No.3 ビットすごろく
ユーザー mnmmnm
提出日時 2022-06-17 01:46:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,477 bytes
コンパイル時間 897 ms
コンパイル使用メモリ 79,964 KB
実行使用メモリ 4,512 KB
最終ジャッジ日時 2023-07-29 08:52:01
合計ジャッジ時間 1,922 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
4,380 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <bitset>

#define rep(i,n) for(i=0; i<n; ++i)
#define in(a) cin >> a
#define out(a,b) cout << a << b
#define print_vec(v) for(auto it=v.begin();it!=v.end();++it)cout<<*it <<" ";cout<<endl
#define print_vec2d(v) for(int i=0;i<v.size();++i){for(int j=0;j<v[i].size();++j)cout<<v[i][j]<<" ";cout<<endl;}cout<<endl
using namespace std;
using lint = long long;

string base_conv(lint n, lint r){
    string str = "";
    if(n<0||r<2);   // なにもしない
    else{
        char pop; int num;
        while(n){
            num = n%r;
    
            if(num>9)  pop = 'A'+num-10;
            else    pop = '0'+num;
    
            str = pop + str;
            n/=r;
        }
    }
    return str;
}

int count_string(string str, char c){
    int cnt=0, i;
    rep(i,str.size()){
        cnt+=str[i]==c;
    }
    return cnt;
}

void write_vec(int indx, vector<lint> &x){
    string bin_s=base_conv(indx+1, 2);
    int cnt=count_string(bin_s, '1');
    if(indx-cnt>0&&x[indx-cnt]<0){
        x[indx-cnt]=x[indx]+1;
        write_vec(indx-cnt, x);
    }
    if(indx+cnt<x.size()&&x[indx+cnt]<0){
        x[indx+cnt]=x[indx]+1;
        write_vec(indx+cnt, x);
    }
    return;
}

int main(void){
    lint i, j, k;
    lint p, n, m;
    in(n);
    vector<lint> count(n, -1);
    count[0]=1;
    write_vec(0, count);

    out(count[n-1],endl);

    return 0;
}
0