Task: | Sorting |
Sender: | lolok123 |
Submission time: | 2021-02-02 12:58:42 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 36 |
#2 | ACCEPTED | 64 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.09 s | 1, 2 | details |
#2 | ACCEPTED | 0.10 s | 2 | details |
#3 | ACCEPTED | 0.09 s | 1, 2 | details |
#4 | ACCEPTED | 0.09 s | 1, 2 | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:39:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int l=0; l<v.size(); ++l){ ~^~~~~~~~~
Code
#define MOD 1000000007 #include <bits/stdc++.h> #include <numeric> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); array<set<vector<int>>,8> arr; queue<int> q; set<int> vis; for(int i=1; i<=8; ++i){ int n=0; for(int j=1; j<=i; ++j){ n*=10; n+=j; } q.push(n); vis.insert(n); while(!q.empty()){ n=q.front(); q.pop(); vector<int> v; while(n){ v.push_back(n%10); n/=10; } reverse(v.begin(),v.end()); arr[i-1].insert(v); for(int j=0; j<i-3; ++j){ for(int k=j+2; k<i-1; ++k){ swap(v[j],v[k]); swap(v[j+1],v[k+1]); n=0; for(int l=0; l<v.size(); ++l){ n*=10; n+=v[l]; } if(vis.find(n)==vis.end()){ vis.insert(n); q.push(n); } swap(v[j],v[k]); swap(v[j+1],v[k+1]); } } } } int T; cin>>T; for(int T_Case=1;T_Case<=T;++T_Case){ int n,c{0}; cin>>n; vector<int> a(n); for(int i=0; i<n; ++i){ cin>>a[i]; for(int j=0; j<i; ++j){ c+=a[j]>a[i]; } } if(n<=8){ if(arr[n-1].find(a)!=arr[n-1].end()){ cout<<"YES"<<'\n'; } else{ cout<<"NO"<<'\n'; } } else{ if(c%2==0){ cout<<"YES"<<'\n'; } else{ cout<<"NO"<<'\n'; } } } }
Test details
Test 1
Group: 1, 2
Verdict: ACCEPTED
input |
---|
153 1 1 2 1 2 ... |
correct output |
---|
YES YES NO NO NO ... |
user output |
---|
YES YES NO NO NO ... Truncated |
Test 2
Group: 2
Verdict: ACCEPTED
input |
---|
1000 59 35 29 32 50 11 15 9 21 19 45 2... |
correct output |
---|
YES NO YES NO YES ... |
user output |
---|
YES NO YES NO YES ... Truncated |
Test 3
Group: 1, 2
Verdict: ACCEPTED
input |
---|
720 6 1 6 4 5 2 3 6 6 3 2 1 5 4 ... |
correct output |
---|
YES NO NO NO YES ... |
user output |
---|
YES NO NO NO YES ... Truncated |
Test 4
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1000 8 7 4 2 8 6 3 5 1 8 3 8 2 7 5 4 6 1 ... |
correct output |
---|
NO NO YES NO YES ... |
user output |
---|
NO NO YES NO YES ... Truncated |