Submission #67337743


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(s,e) for(long long i=s; i<e; i++)
#define rf(e,s) for(long long i=e; i>=s; i--)
#define pb push_back
#define MOD 1000000007
#define um unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define si set<int>
#define all(a) (a).begin(),(a).end()
#define fora(a) for(auto &u:a)
/*********************************************/
void yes(){cout<<"Yes"<<endl;}
void no(){cout<<"No"<<endl;}
ll add(ll x, ll y){return ((x + y) % MOD + MOD) % MOD;}
ll mul(ll x, ll y){return x * 1ll * y % MOD;}
ll binpow(ll x, ll y){
    ll z = 1;
    while(y){
        if(y % 2 == 1) z = mul(z, x);
        x = mul(x, x);
        y /= 2;
    }
    return z;
}
ll inv(ll x){return binpow(x, MOD - 2);}
ll divide(ll x, ll y){return mul(x, inv(y));}
/***************************************/
static bool comp(ll &a, ll &b){
    return abs(a) < abs(b);
}
bool check(vector<ll> &a){
    unordered_set<ll> st;
    int pos = 0, neg = 0;
    fora(a){
        st.insert(abs(u));
        if(u < 0){
            neg++;
        }
        else{
            pos++;
        }
    }
    // cout << pos << " " << neg << endl;
    if(st.size() == 1 && abs(pos-neg) <= 1){
        return true;
    }
    else{
        return false;
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin >> n;
        vector<ll> a(n);
        f(0, n){
            cin >> a[i];
        }
        if(check(a)){
            yes();
            continue;
        }
        sort(all(a),comp);
        bool flag = true;
        for(int i = 1; i < n-1; i++){
            ll sqr = a[i]*a[i];
            ll othr = a[i-1]*a[i+1];
            if(sqr != othr){
                flag = false;
                break;
            }
        }
        if(flag){
            yes();
        }
        else{
            no();
        }
    }
}

Submission Info

Submission Time
Task D - Make Geometric Sequence
User itsganesh
Language C++ 17 (gcc 12.2)
Score 425
Code Size 2033 Byte
Status AC
Exec Time 59 ms
Memory 13828 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 1
AC × 32
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 3472 KiB
01_random_01.txt AC 25 ms 3436 KiB
01_random_02.txt AC 53 ms 9264 KiB
01_random_03.txt AC 54 ms 10956 KiB
01_random_04.txt AC 52 ms 3336 KiB
01_random_05.txt AC 51 ms 6008 KiB
01_random_06.txt AC 14 ms 3400 KiB
01_random_07.txt AC 20 ms 4564 KiB
01_random_08.txt AC 52 ms 3428 KiB
01_random_09.txt AC 52 ms 3488 KiB
01_random_10.txt AC 29 ms 3420 KiB
01_random_11.txt AC 52 ms 8624 KiB
01_random_12.txt AC 52 ms 3468 KiB
01_random_13.txt AC 52 ms 3528 KiB
01_random_14.txt AC 52 ms 3532 KiB
01_random_15.txt AC 51 ms 4376 KiB
01_random_16.txt AC 52 ms 3532 KiB
01_random_17.txt AC 52 ms 3532 KiB
01_random_18.txt AC 38 ms 3448 KiB
01_random_19.txt AC 21 ms 4660 KiB
01_random_20.txt AC 24 ms 3428 KiB
01_random_21.txt AC 53 ms 9140 KiB
01_random_22.txt AC 52 ms 3484 KiB
01_random_23.txt AC 32 ms 3532 KiB
01_random_24.txt AC 59 ms 13828 KiB
01_random_25.txt AC 52 ms 3432 KiB
01_random_26.txt AC 52 ms 3436 KiB
01_random_27.txt AC 42 ms 4464 KiB
01_random_28.txt AC 53 ms 9216 KiB
01_random_29.txt AC 52 ms 3424 KiB
01_random_30.txt AC 26 ms 4328 KiB
02_handmade_31.txt AC 1 ms 3448 KiB