QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#63736 | #4800. Oscar's Round Must Have a Constructive Problem | neko_nyaa | WA | 75ms | 3372kb | C++23 | 781b | 2022-11-23 11:40:40 | 2022-11-23 11:41:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n; cin >> n;
vector<int> p(n); map<int, int> cnt;
for (int i = 0; i < n; i++) {
cin >> p[i]; cnt[p[i]]++;
if (cnt[p[i]] == n) {
cout << "NO\n";
return;
}
}
set<int> st; vector<int> a;
for (int i = 0; i < n; i++) {
st.insert(i);
a.push_back(i+1);
}
sort(a.begin(), a.end(), [&](int x, int y){
return cnt[x] > cnt[y];
});
vector<int> ans(n);
for (int i: a) {
for (int j: st) {
if (p[j] == i) continue;
ans[j] = i; st.erase(j); break;
}
}
cout << "YES\n";
for (int i: ans) cout << i << ' ';
cout << '\n';
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int t; cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3364kb
input:
3 3 3 3 3 3 3 2 1 6 1 1 4 5 1 4
output:
NO YES 1 3 2 YES 4 5 1 2 3 6
result:
ok ok
Test #2:
score: -100
Wrong Answer
time: 75ms
memory: 3372kb
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 2 1 YES 1 2 NO NO YES 2 3 1 YES 3 2 1 YES 2 1 3 YES 2 1 3 YES 2 1 0 YES 3 1 2 YES 2 1 3 YES 3 1 2 YES 1 2 3 YES 1 2 3 YES 1 2 0 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 1 2 3 YES 1 3 2 YES 1 3 2 YES 2 3 1 YES 2 3 1 YES 1 2 3 YES 2 1 3 NO ...
result:
wrong answer Integer 0 violates the range [1, 3]