結果

問題 No.1742 Binary Indexed Train
ユーザー 沙耶花沙耶花
提出日時 2021-11-12 21:51:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 406 ms / 3,000 ms
コード長 570 bytes
コンパイル時間 4,625 ms
コンパイル使用メモリ 259,612 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-17 01:03:01
合計ジャッジ時間 13,613 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 400 ms
4,380 KB
testcase_04 AC 397 ms
4,384 KB
testcase_05 AC 401 ms
4,384 KB
testcase_06 AC 169 ms
4,380 KB
testcase_07 AC 165 ms
4,384 KB
testcase_08 AC 359 ms
4,384 KB
testcase_09 AC 361 ms
4,380 KB
testcase_10 AC 360 ms
4,380 KB
testcase_11 AC 364 ms
4,380 KB
testcase_12 AC 365 ms
4,384 KB
testcase_13 AC 397 ms
4,380 KB
testcase_14 AC 406 ms
4,380 KB
testcase_15 AC 68 ms
4,380 KB
testcase_16 AC 55 ms
4,384 KB
testcase_17 AC 202 ms
4,380 KB
testcase_18 AC 200 ms
4,380 KB
testcase_19 AC 106 ms
4,384 KB
testcase_20 AC 10 ms
4,384 KB
testcase_21 AC 77 ms
4,380 KB
testcase_22 AC 220 ms
4,380 KB
testcase_23 AC 17 ms
4,384 KB
testcase_24 AC 8 ms
4,380 KB
testcase_25 AC 187 ms
4,380 KB
testcase_26 AC 117 ms
4,384 KB
testcase_27 AC 162 ms
4,380 KB
testcase_28 AC 20 ms
4,380 KB
testcase_29 AC 210 ms
4,384 KB
testcase_30 AC 131 ms
4,380 KB
testcase_31 AC 367 ms
4,380 KB
testcase_32 AC 127 ms
4,380 KB
testcase_33 AC 46 ms
4,380 KB
testcase_34 AC 237 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001


int main(){
	
	int n,q;
	cin>>n>>q;
	
	rep(_,q){
		long long s,t;
		cin>>s>>t;
		int ans = 0;
		while(s!=t){
			int ind = -1;
			rep(i,n){
				if((s>>i)&1){
					ind = i;
					break;
				}
			}
			if(ind==-1 || (s+(1LL<<ind))>t){
				ans += __builtin_popcountll(s^t);
				break;
			}
			ans++;
			s += 1LL<<ind;
		}
		cout<<ans<<endl;
		
	}
	
	return 0;
}
0