답안 #1069923

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1069923 2024-08-22T10:04:59 Z Arapak 송신탑 (IOI22_towers) C++17
0 / 100
4000 ms 5964 KB
#include "towers.h"
#include "bits/stdc++.h"
using namespace std;

#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

#ifdef DEBUG
auto& operator<<(auto &os, const pair<auto,auto> &p) {
	return os<<"("<<p.first<<", "<<p.second<<")";
}
auto& operator<<(auto &os, const auto &v) {
	os<<"{";
	for(auto it=begin(v);it!=end(v);++it) {
		if(it != begin(v)) os<<", ";
		os<<(*it);
	}
	return os<<"}";
}

void dbg_out(auto... x) {
	((cerr<<' '<<x), ...) << endl;
}
#define dbg(x...) cerr<<"("<<#x<<"):", dbg_out(x);
#else
#define dbg(...)
#endif

const int inf = 1e9 + 7;

int n, root;
vi h;
vi L, R, siz;

int get_max(int l, int r) {
	int maxi = l;
	rep(i,l+1,r)
		if(h[i] > h[maxi])
			maxi = i;
	return maxi;
}

int build_tree(int l, int r) {
	if(l == r) return -1;
	if(l+1 == r) {
		siz[l] = 1;
		return l;
	}
	int index = get_max(l, r);
	L[index] = build_tree(l, index);
	R[index] = build_tree(index+1, r);
	siz[index] = (L[index] == -1 ? 0 : siz[L[index]]) 
				+(R[index] == -1 ? 0 : siz[R[index]]);
	return index;
}

void init(int N, vi H) {
	n = N;
	h = H;
	L.resize(n);
	R.resize(n);
	siz.assign(n, 0);
	root = build_tree(0, n);
	dbg(root);
	dbg(L);
	dbg(R);
}

int solve(int v, int l, int r, int a, int b, int d, int maxi) {
	if(l == r || r <= a || b <= l) return 0;
	dbg(v, l, r, a, b, d, maxi);
	if(l+1 == r) return h[v] <= maxi;
	int res = 0;
	if(L[v] == -1 || v < a)
		res += solve(R[v], v+1, r, a, b, d, maxi);
	else if(R[v] == -1 || v >= b)
		res += solve(L[v], l, v, a, b, d, maxi);
	else {
		res += solve(L[v], l  , v, a, b, d, min(maxi, h[v] - d));
		res += solve(R[v], v+1, r, a, b, d, min(maxi, h[v] - d));
	}
	if(res == 0 && (a <= v && v < b && h[v] <= maxi))
		return 1;
	return res;
}

int max_towers(int L, int R, int D) {
	int res = solve(root, 0, n, L, R+1, D, inf);
	return res == 0 ? 1 : res;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4002 ms 5964 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '292', found: '289'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '292', found: '289'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4061 ms 2648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4069 ms 856 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '292', found: '289'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4002 ms 5964 KB Time limit exceeded
2 Halted 0 ms 0 KB -