-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path431-perfecto.cpp
More file actions
61 lines (57 loc) · 1.48 KB
/
Copy path431-perfecto.cpp
File metadata and controls
61 lines (57 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Perfecto [2071B]
* Problem: https://codeforces.com/problemset/problem/2071/B
* Verdict: ACCEPTED Solved: 2025-02-28
* Language: C++17 (GCC 7-32)
* Runtime: 343 ms Memory: 12900 KB
* Tags: brute force, constructive algorithms, greedy, math
* Author: BidoTeima
* Source: https://codeforces.com/contest/2071/submission/308327564
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool perfectSquare(ll x){
ll sq = sqrt(x);
return sq*sq == x;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
/*for(int j = 1; j <= 1000; j++){
assert(perfectSquare(j*j));
}*/
int t;
cin>>t;
while(t--){
int n;
cin>>n;
set<int>st;
for(int i = 1; i <= n; i++)st.insert(-i);
vector<int>ans;
ll cur = 0;
while((int)ans.size() < n){
bool found=0;
for(auto it = st.begin(); it != st.end(); ++it){
if(!perfectSquare(cur - (*it))){
found=1;
ans.push_back(-(*it));
cur -= (*it);
st.erase(it);
break;
}
}
if(!found){
//cout<<"brah\n";
ans.clear();
ans.push_back(-1);
break;
}
}
if(!perfectSquare(cur))for(int i : ans)cout<<i<<' ';
else cout<<-1;
cout<<'\n';
}
return 0;
}