Submission #1076668

# Submission time Handle Problem Language Result Execution time Memory
1076668 2024-08-26T15:25:50 Z allin27x Radio Towers (IOI22_towers) C++17
0 / 100
10 ms 2260 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

vector<int> h;
vector<int> lc,rc,a;

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

int dfs(int i, int d){
	if (i==-1) return 0;
	if (lc[i]==-1 && rc[i]==-1) return -a[i];
	int lans = dfs(lc[i],d);
	int rans = dfs(rc[i],d);
	if (lans < 0 && a[i] - d >= a[lc[i]]) lans = 1;
	if (rans < 0 && a[i] - d >= a[rc[i]]) rans = 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 max_towers(signed l, signed r, signed d){
	int sz = r-l+1;
	a.assign(sz,0); for (int i=l; i<=r; i++) a[i-l] = h[i];

	a.push_back(2e9);
	stack<int> st; st.push(sz);
	lc.assign(sz+1,-1); rc.assign(sz+1,-1);

	for (int i=0; i<sz; i++){
		int last = -1;
		while (a[i] > a[st.top()]) {
			last=st.top();
			st.pop();
		}
		lc[i] = last;
		rc[st.top()]=i;
		st.push(i);
	}
	for (int i=0; i<=sz; i++) cout<<i<<' '<<lc[i]<<' '<<rc[i]<<'\n'; cout<<'\n';
	return dfs(sz,d);
}

Compilation message

towers.cpp: In function 'long long int dfs(long long int, long long int)':
towers.cpp:19:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   19 |  if (!lans) return rans; if (!rans) return lans;
      |  ^~
towers.cpp:19:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   19 |  if (!lans) return rans; if (!rans) return lans;
      |                          ^~
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:44:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   44 |  for (int i=0; i<=sz; i++) cout<<i<<' '<<lc[i]<<' '<<rc[i]<<'\n'; cout<<'\n';
      |  ^~~
towers.cpp:44:67: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   44 |  for (int i=0; i<=sz; i++) cout<<i<<' '<<lc[i]<<' '<<rc[i]<<'\n'; cout<<'\n';
      |                                                                   ^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1644 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 2260 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1180 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1644 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -