QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#183088#6540. Beautiful SequencehiderrWA 1ms3620kbC++141001b2023-09-18 22:40:382023-09-18 22:40:39

Judging History

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

  • [2023-09-18 22:40:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3620kb
  • [2023-09-18 22:40:38]
  • 提交

answer

#include <bits/stdc++.h>
#include <queue>
using namespace std;

#define loop(i, a, b) for(int i = a; i <= b; i++)
#define loop_rev(i, a, b) for(int i = a; i >= b; i--)
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
using ui = uint32_t;
using ll = int64_t;

void solve() {
	int n; cin >> n;
	vector<int> a(n);
	loop(i, 0, n-1) cin >> a[i];
	a.push_back(0);
	sort(all(a));
	priority_queue<int> pq;
	int hole_cnt = -1, group_size = 1;
	int prev = -1, res = 1;
	loop_rev(i, n, 0) {
		if(a[i] != prev) {
			prev = a[i];
			if(group_size <= hole_cnt - 1) {
				hole_cnt -= group_size + 1;
				pq.push(group_size);
			}
			else if(!pq.empty() && group_size < pq.top()) {
				pq.pop();
				pq.push(group_size);
			}
			res += group_size - 1;
			group_size = 1;
			hole_cnt++;
		}
		else {
			group_size++;
		}
	}
	cout << (res + pq.size()) << '\n';
}

int main() {

	cin.tie(0)->sync_with_stdio(false);
	int t; cin >> t;

	while(t--) solve();

}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3500kb

input:

2
6
1 1 2 3 3 4
5
1 2 2 3 3

output:

4
4

result:

ok 2 number(s): "4 4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

2
5
1 2 2 3 3
20
1 1 1 1 1 1 4 5 8 8 8 8 9 9 9 9 10 10 10 10

output:

4
17

result:

ok 2 number(s): "4 17"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3620kb

input:

300
14
1 1 1 2 2 2 3 3 3 4 5 5 6 6
14
1 1 1 2 2 3 3 4 4 5 5 6 7 7
14
1 1 2 2 3 4 4 4 5 5 5 6 6 6
14
1 1 2 2 3 3 3 4 5 5 5 6 6 6
14
1 1 1 1 1 1 2 2 2 2 2 3 3 3
14
1 1 1 1 1 1 1 1 1 1 1 1 1 1
14
1 2 2 3 4 5 5 6 6 6 7 8 8 8
14
1 2 2 2 2 2 3 4 5 6 7 8 9 10
14
1 2 2 3 4 4 4 5 6 6 6 6 6 7
14
1 1 2 2 2 3 3...

output:

10
9
11
11
12
14
10
9
11
11
9
10
10
9
11
11
11
9
9
12
10
9
10
10
11
10
11
11
11
11
10
8
9
9
10
10
11
13
10
12
11
11
8
10
9
11
10
10
10
8
11
10
11
9
10
10
10
10
11
11
12
9
10
10
9
10
9
10
11
11
10
10
10
10
11
10
10
10
9
9
8
10
8
11
9
11
9
11
11
12
9
8
10
8
12
11
9
11
10
10
11
10
10
9
10
9
10
10
10
11...

result:

wrong answer 33rd numbers differ - expected: '10', found: '9'