Task: | Sorting |
Sender: | endagorion |
Submission time: | 2021-01-31 08:05:30 +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.01 s | 1, 2 | details |
#2 | ACCEPTED | 0.01 s | 2 | details |
#3 | ACCEPTED | 0.01 s | 1, 2 | details |
#4 | ACCEPTED | 0.01 s | 1, 2 | details |
Code
#include <bits/stdc++.h>#define mp make_pair#define mt make_tuple#define fi first#define se second#define pb push_back#define all(x) (x).begin(), (x).end()#define rall(x) (x).rbegin(), (x).rend()#define forn(i, n) for (int i = 0; i < (int)(n); ++i)#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)using namespace std;typedef pair<int, int> pii;typedef vector<int> vi;typedef vector<pii> vpi;typedef vector<vi> vvi;typedef long long i64;typedef vector<i64> vi64;typedef vector<vi64> vvi64;typedef pair<i64, i64> pi64;typedef double ld;template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }int main() {ios::sync_with_stdio(false);cin.tie(nullptr);cout.precision(10);cout << fixed;#ifdef LOCAL_DEFINEfreopen("input.txt", "rt", stdin);#endifset<vi> bad;for1(n, 4) {vvi allp;vi perm(n);iota(all(perm), 0);do {allp.pb(perm);} while (next_permutation(all(perm)));set<vi> vis = {allp[0]};vvi q = {allp[0]};forn(cur, q.size()) {vi v = q[cur];forn(i, n - 1) forn(j, i - 1) {vi u = v;swap(u[j], u[i]);swap(u[j + 1], u[i + 1]);if (vis.count(u)) continue;vis.insert(u);q.pb(u);}}for (auto &v: allp) if (!vis.count(v)) {bad.insert(v);}}int T;cin >> T;while (T--) {int n;cin >> n;vi a(n);forn(i, n) cin >> a[i], --a[i];bool ok;if (n <= 4) ok = !bad.count(a);else {int inv = 0;forn(i, n) forn(j, i) if (a[j] > a[i]) ++inv;ok = inv % 2 == 0;}cout << (ok ? "YES" : "NO") << '\n';}#ifdef LOCAL_DEFINEcerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";#endifreturn 0;}
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 |