이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
#define int long long
using namespace std;
struct no{
vector<int> ch;
int dep=-1;
};
vector<no> g;
int d;
void dfs(int r,int f){
g[r].dep=g[f].dep+1;
for(auto h:g[r].ch){
if(h!=f){
dfs(h,r);
}
}
}
vector<int> z;
void dfs2(int r,int f,int y){
pair<int,int> mx(-1,-1);
for(auto h:g[r].ch){
if(h!=f){
mx=max(mx,{g[h].dep,h});
}
}
for(auto h:g[r].ch){
if(h!=f){
if(mx.sc==h){
dfs2(h,r,y+1);
}
else{
dfs2(h,r,1);
}
}
}
if(mx.sc==-1){
z.push_back(y);
}
}
signed main(){
AquA;
int n,t;
cin >> n >> d >> t;
g.resize(n);
vector<int> v(n);
for(int i=0;i<n;i++){
cin >> v[i];
}
int rt=-1;
int rn=2e9;
vector<int> s;
int ans=0;
for(int i=n-1;i>=0;i--){
if(v[i]<=t){
rn=min(rn,v[i]-i);
ans++;
}
else{
rt=max(rt,i);
while(s.size() && t-s.back()>=rn){
s.pop_back();
}
if(s.empty()){
s.push_back(i);
rn=2e9;
continue;
}
g[s.back()].ch.push_back(i);
s.push_back(i);
rn=2e9;
}
}
if(rt==-1){
cout << n << "\n";
return 0;
}
dfs(rt,rt);
dfs2(rt,rt,1);
sort(z.begin(),z.end(),greater<int>());
d=min(d,(int)z.size());
for(int i=d;i<z.size();i++){
ans+=z[i];
}
cout << ans << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
prison.cpp: In function 'int main()':
prison.cpp:87:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for(int i=d;i<z.size();i++){
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |