답안 #774222

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
774222 2023-07-05T13:11:41 Z NK_ Teams (CEOI11_tea) C++17
100 / 100
328 ms 90464 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define f first
#define s second
#define mp make_pair
#define sz(x) int(x.size())

using pi = pair<int, int>;
template<class T> using V = vector<T>;
using vi = V<int>;

const int INF = int(1e9) + 10;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N; cin >> N;
	V<int> A(N); for(auto& x : A) cin >> x;

	V<pi> B(N); for(int i = 0; i < N; i++) B[i] = mp(A[i], i);

	sort(begin(B), end(B));

	V<int> dp, par, lst;
	auto check = [&](int W) {
		dp = V<int>(N+1, -INF), par = V<int>(N+1, -INF), lst = V<int>(N+1, -1);
		dp[0] = 0, par[0] = -1, lst[0] = 0;

		for(int i = 1; i <= N; i++) {
			int R = max(-1, i - B[i-1].first);

			if (R < 0) dp[i] = -INF;
			else {
				int prv = lst[R];
				if ((i - prv) > W) dp[i] = -INF;
				else dp[i] = dp[prv] + 1, par[i] = prv;
			}
			
			if (dp[i] == -INF || dp[i] < dp[lst[i-1]]) lst[i] = lst[i-1];
			else lst[i] = i;
			// cout << i << " " << dp[i] << endl;
		}

		return dp[N];
	};

	int most = check(N + 1); 

	int lo = *max_element(begin(A), end(A)), hi = N + 1;
	while(lo < hi) {
		int mid = (lo + hi) / 2;

		// cout << lo << " < " << mid << " < " << hi << endl;
		if (check(mid) == most) hi = mid;
		else lo = mid + 1;
		// cout << dp[N - 1] << endl;	
	}

	// cout << "ANS: " << lo << endl;
	check(lo);

	int x = N;
	V<V<int>> ans;
	while(x > 0) {
		int nxt = par[x];
		ans.push_back({});
		while(x > nxt) ans.back().push_back(B[--x].second + 1);
	}

	cout << sz(ans) << nl;
	for(auto& v : ans) {
		cout << sz(v) << " ";
		for(auto c : v) {
			cout << c << " ";
			// assert(sz(v) >= A[c - 1]);
		}
		cout << nl;
	}

    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 3676 KB Output is correct
2 Correct 19 ms 3444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 4036 KB Output is correct
2 Correct 22 ms 3332 KB Output is correct
3 Correct 23 ms 4044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 30288 KB Output is correct
2 Correct 203 ms 30440 KB Output is correct
3 Correct 210 ms 32232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 278 ms 42388 KB Output is correct
2 Correct 328 ms 90464 KB Output is correct
3 Correct 271 ms 40488 KB Output is correct
4 Correct 258 ms 36404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 293 ms 44504 KB Output is correct
2 Correct 168 ms 48308 KB Output is correct
3 Correct 279 ms 39360 KB Output is correct
4 Correct 289 ms 41756 KB Output is correct