Submission #61094
ソースコード
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include<iostream> #include<algorithm> #include<vector> #include<string> #include<cmath> #include<queue> #include<stack> #include<map> #include<numeric> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) template < typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true ); } template < typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true ); } int main () { cin.tie(0); ios::sync_with_stdio( false ); int n,m; cin >> n; vector< int > d(n); for ( int i = 0; i < n; i++){ cin >> d[i]; } cin >> m; vector< int > t(m); for ( int i = 0; i < m; i++){ cin >> t[i]; int l = -1,r = n; while (r - l > 1){ int mid = (l + r) / 2; if (d[mid] <= t[i]){ l = mid; } else { r = mid; } } cout << r << '\n' ; } return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0738 - プログラミング入門:二分探索 |
ユーザー名 | kumakuma |
投稿日時 | 2020-07-18 20:30:36 |
言語 | C++14 |
状態 | Accepted |
得点 | 10 |
ソースコード長 | 903 Byte |
最大実行時間 | 209 ms |
最大メモリ使用量 | 48104 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | Linear Search | 2 / 2 | Input0[1-5] |
2 | Binary Search | 8 / 8 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # | |
---|---|---|---|---|---|
Input01 | AC | 52 ms | 604 KB |
1
|
2
|
Input02 | AC | 21 ms | 564 KB |
1
|
2
|
Input03 | AC | 30 ms | 648 KB |
1
|
2
|
Input04 | AC | 23 ms | 476 KB |
1
|
2
|
Input05 | AC | 16 ms | 548 KB |
1
|
2
|
Input06 | AC | 209 ms | 14824 KB |
2
|
|
Input07 | AC | 169 ms | 24936 KB |
2
|
|
Input08 | AC | 137 ms | 32748 KB |
2
|
|
Input09 | AC | 143 ms | 40940 KB |
2
|
|
Input10 | AC | 115 ms | 48104 KB |
2
|