12/19 牛客练习赛 B solution

16 阅读1分钟

题目

B-小月的排序_牛客练习赛147

image.png

AC code

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve() {
    int n;
    cin>>n;
    vector<int>a(n),t(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        t[i]=a[i];
    }
    sort(t.begin(),t.end());
    for(int i=0;i<n;i++){
        int tt=sqrt(a[i]*t[i]);
        if(tt*tt!=a[i]*t[i]){
            cout<<"NO";
            return ;
        }
    }
    cout<<"YES";
}
signed main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}