Submission #774679

# Submission time Handle Problem Language Result Execution time Memory
774679 2023-07-06T01:42:13 Z NK_ Sailing Race (CEOI12_race) C++17
40 / 100
128 ms 14160 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define pb push_back
#define f first
#define s second
#define mp make_pair

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

const int INF = 1e9 + 10;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, K; cin >> N >> K;
	assert(K == 0);

	V<V<int>> adj(N);
	for(int i = 0; i < N; i++) {
		int x = -1;
		while(1) {
			cin >> x; --x;
			if (x == -1) break;
			adj[i].pb(x);
		}
	}

	V<V<V<int>>> dp(N, V<V<int>>(N, V<int>(2, -1)));

	auto between = [&](int L, int M, int R) {
		if (L > R) R += N;
		if (L > M) M += N;
		return L < M && M < R;
	};

	function<int(int, int, int)> DP = [&](int l, int r, int d) {
		int x = !d ? l : r;

		if (dp[l][r][d]!= -1) {
			// cout << l << ", " << r << ", " << x << " => " << dp[l][r][d] << endl;
			return dp[l][r][d];
		}

		// cout << l << ", " << r << ", " << x << ", " << d << endl;

		int best = 0;
		for(auto y : adj[x]) {
			// cout << y << " -> " << between(l, y, r) << endl;
			if (between(l, y, r)) {
				// cout << "IN: " << y << endl;
				best = max(best, DP(l, y, 1) + 1); // CUT INTO [L, y]
				best = max(best, DP(y, r, 0) + 1); // CUT INTO [y, R]
			}
		}

		// cout << l << ", " << r << ", " << x << " => " << best << endl;
		return dp[l][r][d] = best;
	};

	// HANDLE K = 1
	// FIX LINE THAT CROSSES THE FIRST LINE

	// OBS: FOR A LINE TO ONLY CROSS THE FIRST LINE
	// THE RANGE SHOULD MOVE ONLY TOWARDS THE FIRST HARBORS

	// ITERATE OVER SECOND HARBOR (RIGHT POINT OF FIRST LINE)
	// FIND LONGEST PATH FROM START OF FIXED EDGE TO THE SECOND HARBOR (THAT WAS CHOSEN)
	// FIND FIRST HARBOR THAT MAXIMIZES SIZE OF RANGE THAT THE END OF THE FIXED EDGE HAS

	int ans = -1, best = -1;
	for(int l = 0; l < N; l++) for(auto r : adj[l]) {
		int res1 = DP(l, r, 1);
		if (ans < res1) ans = res1, best = l + 1;

		int res2 = DP(r, l, 0);
		if (ans < res2) ans = res2, best = l + 1;
	}

	cout << ans + 1 << nl << best << nl;
		

    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Runtime error 1 ms 468 KB Execution killed with signal 6
4 Runtime error 1 ms 468 KB Execution killed with signal 6
5 Correct 1 ms 468 KB Output is correct
6 Runtime error 1 ms 468 KB Execution killed with signal 6
7 Correct 4 ms 588 KB Output is correct
8 Runtime error 1 ms 468 KB Execution killed with signal 6
9 Correct 6 ms 724 KB Output is correct
10 Correct 16 ms 972 KB Output is correct
11 Correct 8 ms 852 KB Output is correct
12 Runtime error 1 ms 468 KB Execution killed with signal 6
13 Runtime error 1 ms 452 KB Execution killed with signal 6
14 Correct 106 ms 9212 KB Output is correct
15 Runtime error 1 ms 468 KB Execution killed with signal 6
16 Runtime error 1 ms 468 KB Execution killed with signal 6
17 Runtime error 1 ms 468 KB Execution killed with signal 6
18 Correct 128 ms 14160 KB Output is correct
19 Runtime error 1 ms 468 KB Execution killed with signal 6
20 Runtime error 1 ms 468 KB Execution killed with signal 6