Submission #251521

# Submission time Handle Problem Language Result Execution time Memory
251521 2020-07-21T16:46:45 Z kostia244 Jousting tournament (IOI12_tournament) C++17
0 / 100
1000 ms 7680 KB
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
struct range {
	int i, l, r;
	bool operator<(const range &rhs) const {
		return l < rhs.l;
	}
};
using oset = tree<range, null_type, less<range>, rb_tree_tag, tree_order_statistics_node_update>;
const int maxn = 1<<18;
int n, c, x, l[maxn], r[maxn];
vector<int> g[maxn];

int tr[maxn];
int qry(int l, int r) {
	int ans = 0;
	for(l += n, r += n; l < r; l>>=1, r>>=1) {
		if(l&1) ans = max(ans, tr[l++]);
		if(r&1) ans = max(ans, tr[--r]);
	}
	return ans;
}

int dp[maxn];
int dfs(int v) {
	if(v < n) return 0;
	if(dp[v] >= 0) return dp[v];
	int good = qry(l[v], r[v]) < x;
	dp[v] = good;
	for(auto &i : g[v]) dp[v] = max(dp[v], good+dfs(i));
	return dp[v];
}
int GetBestPosition(int N, int C, int X, int *a, int *s, int *e) {
	n = N, c = C, x = X;
	for(int i = 0; i < n-1; i++) {
		int j = n+i;
		for(;j;j>>=1) tr[j] = max(tr[j], a[i]);
	}
	for(int i = 0; i < n-1; i++) {
		int mx = 0;
		for(int j = i; j < n-1; j++) {
			mx = max(mx, a[j]);
			assert(mx == qry(i, j+1));
		}
	}
	oset b;
	for(int i = 0; i < n; i++) l[i] = r[i] = i, b.insert(range{i, l[i], r[i]});
	for(int i = 0; i < c; i++) {
		int len = e[i] - s[i] + 1;
		int nl, nr;
		for(int j = 1; j <= len; j++) {
			auto t = *b.find_by_order(s[i]);
			if(j == 1) nl = t.l;
			if(j == len) nr = t.r;
			g[n+i].push_back(t.i);
			b.erase(t);
		}
		l[n+i] = nl;
		r[n+i] = nr;
		b.insert(range{n+i, nl, nr});
		//for(auto i : b) cout << i.l << " " << i.r << " | "; cout << '\n';
	}
	memset(dp, -1, sizeof dp);
	int ans = 0;
	for(int i = 0; i < n+c; i++) ans = max(ans, dfs(i));
	return ans;
}

Compilation message

tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:51:11: warning: 'nr' may be used uninitialized in this function [-Wmaybe-uninitialized]
   int nl, nr;
           ^~
tournament.cpp:51:7: warning: 'nl' may be used uninitialized in this function [-Wmaybe-uninitialized]
   int nl, nr;
       ^~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7552 KB Output is correct
2 Incorrect 5 ms 7552 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 7680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 7296 KB Time limit exceeded
2 Halted 0 ms 0 KB -