QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#63736#4800. Oscar's Round Must Have a Constructive Problemneko_nyaaWA 75ms3372kbC++23781b2022-11-23 11:40:402022-11-23 11:41:22

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-23 11:41:22]
  • 评测
  • 测评结果:WA
  • 用时:75ms
  • 内存:3372kb
  • [2022-11-23 11:40:40]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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]