QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#50649 | #4800. Oscar's Round Must Have a Constructive Problem | alittlestory# | WA | 57ms | 3660kb | C++ | 2.5kb | 2022-09-28 13:35:49 | 2022-09-28 13:35:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long long ll;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1e9+7;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a, ll b, ll mod) {ll res=1;a%=mod;
assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;
a=a*a%mod;};return res;}
ll gcd(ll a, ll b) {return b?gcd(b, a%b):a;}
template<class T>
void chkmin(T&x,T y){x=min(x,y);}
template<class T>
void chkmax(T&x,T y){x=max(x,y);}
template<class T>
void add(T&x,T y){x+=y;if(x>=mod)x-=mod;}
template<class T>
void sub(T&x,T y){x-=y;if(x<0)x+=mod;}
// head
bool cmp(pair<VI,int>& a, pair<VI,int>& b) {
return a.fi.size() < b.fi.size();
}
bool is_per(VI& a) {
int n = SZ(a);
VI cnt(n, 0);
for (int i : a)
++cnt[i];
for (int i : cnt)
if (i != 1) return false;
return true;
}
void solve() {
// to solve a single test case
int n, cnt = 0;
cin >> n;
VI a(n), ans(n);
vector<pair<VI, int>> pos(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
--a[i];
if (i) cnt += a[i] == a[i - 1];
pos[a[i]].fi.pb(i);
pos[i].se = i;
}
sort(all(pos), cmp);
reverse(all(pos));
if (cnt == n - 1) {
cout << "NO\n";
return;
}
cout << "YES\n";
if (is_per(a)) {
for (int i : a)
cout << (i + 2) % n + 1 << ' ';
cout << '\n';
} else {
queue<int> res;
int cur;
for (int i = 0; i < n; i++)
if (a[i] != pos[0].se) {
res.push(i);
cur = i;
break;
}
for (auto [p, x] : pos) {
//cout << x << ' ' << res.front() << '\n';
ans[res.front()] = x; res.pop();
for (int i : p)
if (i != cur) res.push(i);
}
for (int i : ans) cout << i + 1 << ' ';
cout << '\n';
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int tt;
cin >> tt;
//tt = 1;
while (tt--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3644kb
input:
3 3 3 3 3 3 3 2 1 6 1 1 4 5 1 4
output:
NO YES 2 1 3 YES 4 5 1 2 6 3
result:
ok ok
Test #2:
score: -100
Wrong Answer
time: 57ms
memory: 3660kb
input:
50069 1 1 2 1 1 2 1 2 2 2 1 2 2 2 3 1 1 1 3 1 1 2 3 1 1 3 3 1 2 1 3 1 2 2 3 1 2 3 3 1 3 1 3 1 3 2 3 1 3 3 3 2 1 1 3 2 1 2 3 2 1 3 3 2 2 1 3 2 2 2 3 2 2 3 3 2 3 1 3 2 3 2 3 2 3 3 3 3 1 1 3 3 1 2 3 3 1 3 3 3 2 1 3 3 2 2 3 3 2 3 3 3 3 1 3 3 3 2 3 3 3 3 4 1 1 1 1 4 1 1 1 2 4 1 1 1 3 4 1 1 1 4 4 1 1 2 1 ...
output:
NO NO YES 1 2 YES 2 1 NO NO YES 2 3 1 YES 3 2 1 YES 2 1 3 YES 2 1 3 YES 3 1 2 YES 3 1 2 YES 3 2 1 YES 3 1 2 YES 1 2 3 YES 1 2 3 YES 1 3 2 YES 1 3 2 NO YES 3 1 2 YES 1 2 3 YES 3 2 1 YES 3 2 1 YES 1 3 2 YES 2 3 1 YES 1 3 2 YES 2 1 3 YES 2 3 1 YES 2 3 1 YES 1 2 3 YES 2 1 3 NO ...
result:
wrong answer P_1 == A_1.