Submission #67329127


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tt = 1;
    cin >> tt;
    while (tt--)
    {
        int n;
        cin >> n;
        int a[n];
        bool pos = false, neg = false, f = true;
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            pos |= (a[i] > 0);
            neg |= (a[i] < 0);
        }
        sort(a, a + n);
        if (!pos || !neg)
        {
            for (int i = 1; i < n - 1; i++)
            {
                if ((a[i] * a[i]) != (a[i - 1] * a[i + 1]))
                {
                    f = false;
                    break;
                }
            }
            cout << (f ? "Yes\n" : "No\n");
        }
        else
        {
            int ind = lower_bound(a, a + n, 0LL) - a;
            int l = ind - 1, r = ind;
            bool c = true;
            int pos_ele = a[r], neg_ele = a[l];
            if (abs(neg_ele) > pos_ele)
            {
                c = false;
            }
            while (l >= 0 && r < n)
            {
                if (!c)
                {
                    if (r < n - 1)
                    {
                        if ((a[l] * a[l]) != (a[r] * a[r + 1]))
                        {
                            f = false;
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                    c = !c;
                    ++r;
                }
                else
                {
                    if (l > 0)
                    {
                        if ((a[l] * a[l - 1]) != (a[r] * a[r]))
                        {
                            f = false;
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                    --l;
                    c = !c;
                }
            }
            f &= ((r == n - 1) && (l == 0));
            cout << (f ? "Yes\n" : "No\n");
        }
    }
    return 0;
}

Submission Info

Submission Time
Task D - Make Geometric Sequence
User Piyush8595
Language C++ 20 (gcc 12.2)
Score 0
Code Size 2312 Byte
Status WA
Exec Time 24 ms
Memory 5032 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 425
Status
AC × 1
AC × 3
WA × 29
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 02_handmade_31.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3480 KiB
01_random_01.txt WA 9 ms 3476 KiB
01_random_02.txt WA 22 ms 4472 KiB
01_random_03.txt WA 24 ms 4704 KiB
01_random_04.txt WA 17 ms 3560 KiB
01_random_05.txt WA 19 ms 3924 KiB
01_random_06.txt WA 5 ms 3308 KiB
01_random_07.txt AC 15 ms 5032 KiB
01_random_08.txt WA 17 ms 3352 KiB
01_random_09.txt WA 17 ms 3420 KiB
01_random_10.txt WA 10 ms 3472 KiB
01_random_11.txt WA 21 ms 4216 KiB
01_random_12.txt WA 17 ms 3404 KiB
01_random_13.txt WA 17 ms 3348 KiB
01_random_14.txt WA 17 ms 3428 KiB
01_random_15.txt WA 18 ms 3656 KiB
01_random_16.txt WA 17 ms 3408 KiB
01_random_17.txt WA 18 ms 3564 KiB
01_random_18.txt WA 13 ms 3476 KiB
01_random_19.txt AC 16 ms 4968 KiB
01_random_20.txt WA 8 ms 3476 KiB
01_random_21.txt WA 22 ms 4408 KiB
01_random_22.txt WA 17 ms 3412 KiB
01_random_23.txt WA 11 ms 3476 KiB
01_random_24.txt WA 24 ms 5000 KiB
01_random_25.txt WA 17 ms 3540 KiB
01_random_26.txt WA 17 ms 3436 KiB
01_random_27.txt WA 15 ms 3640 KiB
01_random_28.txt WA 22 ms 4412 KiB
01_random_29.txt WA 17 ms 3424 KiB
01_random_30.txt WA 10 ms 3640 KiB
02_handmade_31.txt WA 1 ms 3428 KiB