Submission #78972


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<bits/stdc++.h>
using namespace std;
main(){
int n;
scanf("%d",&n);
int a[n+1];
a[0]=0;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
int q;
scanf("%d",&q);
for(int i=0;i<q;i++){
int b;
scanf("%d",&b);
int l=0,r=n+1;
while(r-l>1){
int mid=(l+r)/2;
if(a[mid]>b){
r=mid;
}else{
l=mid;
}
}
printf("%d\n",l);
}
}

ステータス

項目 データ
問題 0738 - プログラミング入門:二分探索
ユーザー名 ei2326
投稿日時 2024-05-23 16:15:06
言語 C++17
状態 Accepted
得点 10
ソースコード長 516 Byte
最大実行時間 154 ms
最大メモリ使用量 47840 KB

セット

セット 得点 Cases
1 Linear Search 2 / 2 Input0[1-5]
2 Binary Search 8 / 8 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
Input01 AC 33 ms 476 KB
1
2
Input02 AC 30 ms 576 KB
1
2
Input03 AC 27 ms 424 KB
1
2
Input04 AC 26 ms 524 KB
1
2
Input05 AC 21 ms 620 KB
1
2
Input06 AC 154 ms 14540 KB
2
Input07 AC 139 ms 24560 KB
2
Input08 AC 139 ms 32408 KB
2
Input09 AC 145 ms 40640 KB
2
Input10 AC 113 ms 47840 KB
2