# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
1077288 |
2024-08-27T04:38:29 Z |
pcc |
송신탑 (IOI22_towers) |
C++17 |
|
4000 ms |
11972 KB |
#include "towers.h"
#include <vector>
#include <bits/stdc++.h>
#define pii pair<int,int>
#define fs first
#define sc second
using namespace std;
const int B = 20;
const int mxn = 1e5+10;
const int inf = 1e9;
int mx;
int N;
vector<int> H;
int par[mxn][B];
pii tree[mxn];
int arr[mxn];
int rt;
int dep[mxn];
pii big[mxn];
pii eul[mxn];
int dp[mxn];
void dfs(int now){
for(int i = 1;i<B;i++)par[now][i] = par[par[now][i-1]][i-1];
eul[now] = pii(now,now);
if(tree[now].fs){
int nxt = tree[now].fs;
dep[nxt] = dep[now]+1;
par[nxt][0] = now;
dfs(nxt);
eul[now].fs = eul[nxt].fs;
}
if(tree[now].sc){
int nxt = tree[now].sc;
dep[nxt] = dep[now]+1;
par[nxt][0] = now;
dfs(nxt);
eul[now].sc = eul[nxt].sc;
}
return;
}
void add(int now,int val,int D){
int pos = now;
int tar = arr[now]+D;
for(int i = B-1;i>=0;i--){
int p = par[now][i];
if(arr[p]<=tar)now = p;
}
if(arr[now]<tar)now = par[now][0];
if(arr[now]<tar)return;
int side = 0;
int rs = tree[now].sc;
if(rs&&eul[rs].fs<=pos&&eul[rs].sc>=pos)side = 1;
if(!side)big[now].fs = max(big[now].fs,val);
else big[now].sc = max(big[now].sc,val);
return;
}
int dfs1(int now,int D){
dp[now] = 1;
if(tree[now].fs){
dp[now] = max(dp[now],dfs1(tree[now].fs,D));
}
if(tree[now].sc){
dp[now] = max(dp[now],dfs1(tree[now].sc,D));
}
dp[now] = max(dp[now],big[now].fs+big[now].sc);
add(now,dp[now],D);
return dp[now];
}
void build(int s,int e){
for(auto &i:tree)i = pii(0,0);
vector<int> st;
for(int i = s;i<=e;i++){
while(!st.empty()&&arr[st.back()]<arr[i]){
tree[i].fs = st.back();
st.pop_back();
}
if(!st.empty())tree[st.back()].sc = i;
st.push_back(i);
}
rt = st[0];
par[rt][0] = rt;
dfs(rt);
}
void debug(int now){
if(!now)return;
cerr<<now<<":"<<eul[now].fs<<' '<<eul[now].sc<<endl;
debug(tree[now].fs);
debug(tree[now].sc);
}
void init(int NN, std::vector<int> HH) {
N = NN;
arr[0] = inf;
for(int i = 0;i<N;i++)arr[i+1] = HH[i];
}
int max_towers(int L, int R, int D) {
L++,R++;
build(L,R);
memset(dp,0,sizeof(dp));
for(auto &i:big)i = pii(0,0);
//debug(rt);
return dfs1(rt,D);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4014 ms |
11360 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
1st lines differ - on the 1st token, expected: '13', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
1st lines differ - on the 1st token, expected: '13', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4006 ms |
11972 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4086 ms |
4820 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
1st lines differ - on the 1st token, expected: '13', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4014 ms |
11360 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |