跳到正文

个人记录

P4447求调!!!

#SUSPENDED#约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年7月17日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <climits>
#define ll long long
using namespace std;

struct G {
	ll l;
	ll len;
	bool operator>(const G& o) const {
		return len > o.len;
	}
};

int main(void) {
	cin.sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	priority_queue<G, vector<G>, greater<G>> gs;
	for (ll x : a) {
		vector<G> temp;
		while (!gs.empty() && gs.top().l != x - 1) {
			temp.push_back(gs.top());
			gs.pop();
		}
		if (gs.empty()) {
			gs.push({x, 1});
		} else {
			G g = gs.top();
			gs.pop();
			g.l = x;
			g.len++;
			gs.push(g);
		}
		for (auto& g : temp) {
			gs.push(g);
		}
	}
	ll ans = INT_MAX;
	while (!gs.empty()) {
		ans = min(ans, gs.top().len);
		gs.pop();
	}
	cout << ans << endl;

	return 0;
}

一个点TLE,用很多方法去调没用THT。。。

原文