Submission #67164164


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T; cin >> T;
    while(T--) {
        int n; cin >> n;
        vector<int> v(n);
        for(int i = 0; i < n; i++) cin >> v[i];

        if(n > 2) sort(v.begin() + 1, v.end() - 1);

        int start = 0, end = n - 1;
        int ans = 1;

        if(n == 2) {
            if(v[0] * 2 >= v[1]) cout << 2 << "\n";
            else cout << -1 << "\n";
            continue;
        }

        while(true) {
            if(start == n - 2) {
                if(v[start] * 2 >= v[n-1]) cout << ans + 1 << "\n";
                else cout << -1 << "\n";
                break;
            }

            if(v[start] * 2 >= v[end]) {
                cout << ans + 1 << "\n";
                break;
            }

            int willTopple = upper_bound(v.begin() + start + 1, v.end() - 1, 2 * v[start]) - v.begin() - 1;

            if(willTopple <= start) {
                cout << -1 << "\n";
                break;
            }

            if(v[start] != v[willTopple]) ans++;
            start = willTopple;
        }
    }
    return 0;
}

Submission Info

Submission Time
Task C - Giant Domino
User wanpisu
Language C++ 20 (gcc 12.2)
Score 300
Code Size 1213 Byte
Status AC
Exec Time 23 ms
Memory 3976 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 1
AC × 32
Set Name Test Cases
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
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3376 KiB
01_small_00.txt AC 11 ms 3640 KiB
01_small_01.txt AC 11 ms 3516 KiB
01_small_02.txt AC 8 ms 3520 KiB
01_small_03.txt AC 21 ms 3492 KiB
01_small_04.txt AC 18 ms 3520 KiB
01_small_05.txt AC 18 ms 3524 KiB
01_small_06.txt AC 17 ms 3488 KiB
01_small_07.txt AC 15 ms 3496 KiB
01_small_08.txt AC 15 ms 3640 KiB
02_random_00.txt AC 12 ms 3616 KiB
02_random_01.txt AC 23 ms 3808 KiB
02_random_02.txt AC 23 ms 3976 KiB
02_random_03.txt AC 16 ms 3588 KiB
02_random_04.txt AC 23 ms 3752 KiB
02_random_05.txt AC 21 ms 3788 KiB
02_random_06.txt AC 22 ms 3820 KiB
02_random_07.txt AC 22 ms 3840 KiB
02_random_08.txt AC 19 ms 3816 KiB
02_random_09.txt AC 22 ms 3880 KiB
02_random_10.txt AC 22 ms 3924 KiB
02_random_11.txt AC 17 ms 3572 KiB
02_random_12.txt AC 22 ms 3876 KiB
02_random_13.txt AC 22 ms 3840 KiB
02_random_14.txt AC 19 ms 3856 KiB
02_random_15.txt AC 22 ms 3840 KiB
02_random_16.txt AC 22 ms 3820 KiB
02_random_17.txt AC 20 ms 3832 KiB
02_random_18.txt AC 22 ms 3820 KiB
02_random_19.txt AC 22 ms 3868 KiB
03_corner_00.txt AC 1 ms 3404 KiB
03_corner_01.txt AC 1 ms 3432 KiB