結果

問題 No.1742 Binary Indexed Train
ユーザー Shirotsume
提出日時 2021-10-16 18:37:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 700 bytes
コンパイル時間 2,121 ms
コンパイル使用メモリ 194,016 KB
最終ジャッジ日時 2025-01-25 01:37:50
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 WA * 2 TLE * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define EPS (1e-8)


int solve(long s, long t, long bin[]){
    int maxi = 32;
    int cnt = 0;
    while (s < t){
        for (int i = 32; i >= 0; i--){
            if ((s % bin[i] == 0) && (s + bin[i] <= t)){
                s += bin[i];
                cnt += 1;
                break;
            }
        }
    }
    return cnt;
}

int main(void){
    int n, q;
    cin >> n >> q;
    long bin[100];
    bin[0] = 1;
    for(int i = 1; i < 33; i++){
        bin[i] = bin[i - 1] * 2;
    }
    long maxi = pow(2, n);
    long s, t;
    for(int i = 0; i < q; i++){
        cin >> s >> t;
        cout << solve(s, t, bin) << endl;
    }
    return 0;
}
0