이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int INF=INT_MAX/2;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
int n,d,t;
cin >> n >> d >> t;
vector<int> a(n);
for(auto &x:a)cin >> x;
vector<int> pre(n,-1);
stack<pair<int,int>> s;
s.emplace(-INF,-1);
for(int i=0;i<n;i++){
int x=min(a[i],t)-i;
while(s.top().first>x)s.pop();
pre[i]=a[i]>t?s.top().second:-1;
s.emplace(a[i]-i,i);
}
vector<pair<int,int>> range;
for(int i=0;i<n;i++)if(pre[i]!=-1){
range.emplace_back(pre[i],i-1);
assert(range.empty()||range.back().first>=pre[i]);
}
int m=range.size();
vector<vector<int>> g(m);
vector<int> par(m,-1);
stack<pair<int,int>> st;
for(int i=0;i<m;i++){
int x=range[i].first;
while(!st.empty()&&st.top().first>=x){
int j=st.top().second;
st.pop();
g[i].emplace_back(j);
par[j]=i;
}
st.emplace(x,i);
}
vector<int> b;
function<int(int)> dfs=[&](int u){
vector<int> dep;
for(auto v:g[u])dep.emplace_back(dfs(v));
if(dep.empty())return 1;
sort(dep.begin(),dep.end());
for(int i=0;i<dep.size()-1;i++)b.emplace_back(dep[i]);
return dep.back()+1;
};
for(int i=0;i<m;i++)if(par[i]==-1)b.emplace_back(dfs(i));
sort(b.rbegin(),b.rend());
int ans=n;
for(int i=0;i<min(d,(int)b.size());i++)ans-=b[i];
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
prison.cpp: In lambda function:
prison.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i=0;i<dep.size()-1;i++)b.emplace_back(dep[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... |