이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define sz(v) ((int)v.size())
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define sz(v) ((int)v.size())
#define all(v) begin(v),end(v)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
void dbg_out() { cerr << endl ;}
template<typename Head, typename... Tail> void dbg_out(Head H,Tail... T){
cerr<<' '<<H ;
dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr<<"("<< #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__), cerr << endl;
#else
#define dbg(...) 42
#endif
const int N = 2e6 + 10;
int t[N];
int nxt[N];
int H[N];
int id[N];
int vis[N];
vi g[N];
void dfs(int v,int p=-1){
if(p==-1)H[v] = 0;
vis[v] = 1;
for(auto to : g[v])if(to!=p){
H[to] = H[v] + 1;
dfs(to,v);
}
}
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,d,T;
cin >> n >> d >> T;
rep(i,1,n+1)cin >> t[i];
int ans = n;
int Mx=0;
stack<pii> S;
int curId=0;
for(int i=1;i<=n;i++){
int cur = i + T - t[i];
Mx = max(Mx,cur);
if(!S.empty())S.top().ss = max(S.top().ss, cur);
if(t[i] > T){
if(Mx < i){
ans--;
continue;
}
int last = -1;
while(!S.empty()){
int cur = S.top().ff;
last = max(last, cur);
if(last >= i)break;
nxt[id[cur]] = curId;
S.pop();
}
S.push({i, -1});
id[i] = curId++;
nxt[id[i]] = -1;
dbg(i,id[i]);
}
}
for(int i=0;i<curId;i++){
dbg(i,nxt[i]);
if(nxt[i]!=-1){
g[nxt[i]].pb(i);
}
}
rep(i,0,curId)if(!vis[i]){
dfs(i);
}
vi ids;
rep(i,0,curId)ids.pb(i);
sort(all(ids),[&](int a,int b){
return H[a] > H[b];
});
memset(vis,0,sizeof(vis));
priority_queue<int> pq;
for(auto i : ids){
int val = 0;
while(i!=-1 && !vis[i]){
vis[i] = 1,val++;
i = nxt[i];
}
pq.push(val);
}
while(d-- && sz(pq))ans -= pq.top(),pq.pop();
cout << ans << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
prison.cpp: In function 'int32_t main()':
prison.cpp:25:18: warning: statement has no effect [-Wunused-value]
25 | #define dbg(...) 42
| ^~
prison.cpp:76:4: note: in expansion of macro 'dbg'
76 | dbg(i,id[i]);
| ^~~
prison.cpp:25:18: warning: statement has no effect [-Wunused-value]
25 | #define dbg(...) 42
| ^~
prison.cpp:80:3: note: in expansion of macro 'dbg'
80 | dbg(i,nxt[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... |