提出 #67142951


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
#define int long long
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

/*
*/

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }
        auto b = a;
        sort(b.begin(), b.end());
        int k = -1;
        for(int i = 0; i < n; i++) {
            if(b[i] == a[0]) {
                k = i;
                break;
            }
        }
        if(a[n - 1] <= 2 * a[0] && n != 1) {
            cout << 2 << '\n';
            continue;
        }
        int ans = 1;
        bool bad = false;
        while(k < n) {
            int j = upper_bound(b.begin(), b.end(), 2 * b[k]) - b.begin();
            j--;
            if(j == k) {
                bad = true;
                break;
            }
            if(b[j] > 2 * b[k]) {
                bad = true;
                break;
            }
            k = j;
            ans++;
            if(b[k] >= a[n - 1]) break;
        }
        cout << (bad ? -1 : ans) << '\n';
    }
}

提出情報

提出日時
問題 C - Giant Domino
ユーザ Wasif_Shahzad
言語 C++ 20 (gcc 12.2)
得点 300
コード長 1263 Byte
結果 AC
実行時間 24 ms
メモリ 6308 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 1
AC × 32
セット名 テストケース
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 01_small_08.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 03_corner_00.txt, 03_corner_01.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3316 KiB
01_small_00.txt AC 11 ms 3480 KiB
01_small_01.txt AC 12 ms 3420 KiB
01_small_02.txt AC 8 ms 3408 KiB
01_small_03.txt AC 23 ms 3476 KiB
01_small_04.txt AC 19 ms 3416 KiB
01_small_05.txt AC 18 ms 3420 KiB
01_small_06.txt AC 18 ms 3476 KiB
01_small_07.txt AC 16 ms 3480 KiB
01_small_08.txt AC 16 ms 3608 KiB
02_random_00.txt AC 12 ms 4572 KiB
02_random_01.txt AC 24 ms 6224 KiB
02_random_02.txt AC 24 ms 6076 KiB
02_random_03.txt AC 17 ms 5140 KiB
02_random_04.txt AC 24 ms 6308 KiB
02_random_05.txt AC 22 ms 6144 KiB
02_random_06.txt AC 23 ms 6252 KiB
02_random_07.txt AC 23 ms 6248 KiB
02_random_08.txt AC 20 ms 5712 KiB
02_random_09.txt AC 23 ms 6156 KiB
02_random_10.txt AC 23 ms 6216 KiB
02_random_11.txt AC 18 ms 5356 KiB
02_random_12.txt AC 23 ms 6200 KiB
02_random_13.txt AC 23 ms 6240 KiB
02_random_14.txt AC 20 ms 5688 KiB
02_random_15.txt AC 23 ms 6168 KiB
02_random_16.txt AC 22 ms 6220 KiB
02_random_17.txt AC 20 ms 5908 KiB
02_random_18.txt AC 23 ms 6216 KiB
02_random_19.txt AC 23 ms 6144 KiB
03_corner_00.txt AC 1 ms 3468 KiB
03_corner_01.txt AC 1 ms 3536 KiB