Submission #1079710

# Submission time Handle Problem Language Result Execution time Memory
1079710 2024-08-28T22:34:00 Z allin27x Radio Towers (IOI22_towers) C++17
0 / 100
482 ms 7532 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int MAXN = 1e5+4;

int n;
int h[MAXN];
int olc[MAXN], orc[MAXN];
int lc[MAXN],rc[MAXN];
int pr[MAXN];
int inited = 0;
int fl[MAXN];
int fr[MAXN];

int sum (int l, int r) {
	if (l > r) return 0;
	if (l==0) return pr[r];
	return pr[r] - pr[l-1];
}

int dfs(int i, int d){
	if (i==-1) return 0;
	if (lc[i]==-1 && rc[i]==-1) return -h[i];
	int lans = dfs(lc[i],d);
	int rans = dfs(rc[i],d);
	if (lans < 0 && h[i] - d >= -lans) lans = 1;
	if (rans < 0 && h[i] - d >= -rans) rans = 1;
	if (lans < 0) {
		lc[lc[i]] = -2; rc[lc[i]] = -2;
		lc[i] = -1;
	}
	if (rans < 0) {
		lc[rc[i]] = -2; rc[rc[i]] = -2;
		rc[i] = -1;
	}
	if (!lans) return rans; if (!rans) return lans;
	if (lans < 0 && rans < 0) return max(lans,rans);
	if (lans < 0) return rans;
	if (rans < 0) return lans;
	return lans + rans;
}

signed helper(int d){

	h[n] = 3e9;
	stack<int> st; st.push(n);
	for (int i=0; i<=n; i++) lc[i] = rc[i] = -1;

	for (int i=0; i<n; i++){
		int last = -1;
		while (h[i] > h[st.top()]) {
			last=st.top();
			st.pop();
		}
		lc[i] = last;
		rc[st.top()]=i;
		st.push(i);
	}
	for (int i=0; i<=n; i++) orc[i] =rc[i], olc[i] = lc[i];
	return dfs(n,d);
}


void init(signed N, std::vector<signed> H){
	n= N; for (int i = 0; i < N; i++) h[i] = H[i];
}

void init0(int d) {
	helper(d);
	pr[0] = (lc[0]==-1 && rc[0]==-1);
	for (int i=1; i<n; i++) pr[i] = pr[i-1] + (lc[i]==-1 && rc[i]==-1);
	int rs = 1e9;
	for (int i=n-1; i>=0; i--) {
		if (lc[i]!=-2) rs = i;
		fl[i] = rs;
	}
	rs = -1;
	for (int i=0; i<n; i++) {
		if (lc[i]!=-2) rs = i;
		fr[i] = rs;
	}
}


signed max_towers(signed l, signed r, signed d) {
	if (!inited) init0(d), inited = 1;
	int l1= l, r1=r;
	l = fl[l]; r = fr[r];
	if (r-l <= 1) return 1;
	int s = sum(l+1,r-1);
	s += rc[l] == -1 && (olc[l] == -1 || (olc[l]!=-1 && lc[l] >= l1));
	s += lc[r] == -1 && (orc[r] == -1 || (orc[r]!=-1 && rc[r] <= r1));
	return s;
}

Compilation message

towers.cpp: In function 'long long int dfs(long long int, long long int)':
towers.cpp:37:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   37 |  if (!lans) return rans; if (!rans) return lans;
      |  ^~
towers.cpp:37:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   37 |  if (!lans) return rans; if (!rans) return lans;
      |                          ^~
# Verdict Execution time Memory Grader output
1 Incorrect 301 ms 7532 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Incorrect 1 ms 2392 KB 1st lines differ - on the 1st token, expected: '176', found: '175'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Incorrect 1 ms 2392 KB 1st lines differ - on the 1st token, expected: '176', found: '175'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 482 ms 6868 KB 1st lines differ - on the 1st token, expected: '11903', found: '11902'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 214 ms 3416 KB 2nd lines differ - on the 1st token, expected: '7063', found: '7197'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Incorrect 1 ms 2392 KB 1st lines differ - on the 1st token, expected: '176', found: '175'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 301 ms 7532 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -