답안 #773352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773352 2023-07-05T00:44:56 Z NK_ Teams (CEOI11_tea) C++17
40 / 100
459 ms 84672 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 = 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;
	auto check = [&](int W) {
		deque<pi> q; 
		dp = V<int>(N+1, -INF), par = V<int>(N+1, -INF);
		dp[0] = 0, par[0] = -1;

		int l = 0, r = 0;
		for(int i = 1; i <= N; i++) {
			int L = max(0, i - W) - 1, R = max(-1, i - B[i-1].first);
			// cout << l << " " << r << endl;
			// cout << i << " -> " << L << " " << R << endl;

			while(r <= R) {
				while(sz(q) && q.back().first < dp[r]) q.pop_back();
				q.push_back(mp(dp[r], r)); ++r;
			}

			while(l <= L) {
				if (sz(q) && q.front().second == l) q.pop_front();
				++l;
			}

			if (sz(q)) {
				// cout << l << " " << r << endl;
				// cout << i << " -> " << B[i-1].first << " " << sz(q) << " " << q.front().second << endl;
				// cout << dp[best] + 1 << endl;
				tie(dp[i], par[i]) = q.front();	dp[i]++;
			}
			// cout << endl;
		}

		// for(int i = 0; i <= N; i++) cout << dp[i] << " " << par[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 << " ";
		cout << nl;
	}

    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 320 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 488 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 3272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 3808 KB Output is correct
2 Correct 28 ms 2984 KB Output is correct
3 Correct 34 ms 3256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 313 ms 25312 KB Output is correct
2 Correct 324 ms 25492 KB Output is correct
3 Correct 327 ms 24764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 411 ms 34924 KB Output is correct
2 Correct 459 ms 84672 KB Output is correct
3 Correct 424 ms 33716 KB Output is correct
4 Incorrect 405 ms 28376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 386 ms 35384 KB Output is correct
2 Correct 183 ms 36940 KB Output is correct
3 Correct 449 ms 31796 KB Output is correct
4 Incorrect 456 ms 32108 KB Output isn't correct
5 Halted 0 ms 0 KB -