Submission #444011

#TimeUsernameProblemLanguageResultExecution timeMemory
444011yungyaoThe short shank; Redemption (BOI21_prison)C++17
100 / 100
1375 ms277788 KiB
using namespace std; #include <iostream> #include <algorithm> #include <queue> #include <stack> #include <map> #include <set> #include <utility> #include <vector> #include <memory.h> #include <deque> typedef long long LL; typedef pair<int,int> pii; #define l first #define r second #define mkp make_pair #define iter(x) x.begin(),x.end() #define MEM(s,e) memset(s,e,sizeof(s)) const int maxn = 2e6+200; int s[maxn]; vector <int> tree[maxn]; struct node{ pii iv; int idx; node (pii iv,int i): iv(iv), idx(i) {} }; vector <int> val; int dfs(int x){ vector <int> ret; for (auto i:tree[x]){ ret.push_back(dfs(i)); } sort(iter(ret),[](int a,int b){return a > b;}); for (int i=1;i<ret.size();++i) val.push_back(ret[i]); return 1 + (ret.empty() ? 0 : ret[0]); } int main(){ int n,d,t; stack <pii> sk; vector <pii> iv; cin >> n >> d >> t; int ans = n; for (int i=1;i<=n;++i){ if (sk.size() and sk.top().r < i) sk.pop(); cin >> s[i]; if (s[i] > t){ if (sk.empty()) --ans; else iv.push_back(mkp(sk.top().l,i)); } if (s[i] < t){ pii x = mkp(i,i + t - s[i]); while (sk.size() and x.r >= sk.top().r) sk.pop(); sk.push(x); } } sort (iter(iv),[](pii a,pii b){return a.l != b.l ? a.l < b.l : a.r > b.r;}); stack <node> dfss; vector <int> roots; for (int i=0;i<iv.size();++i){ while (dfss.size() and iv[i].l > dfss.top().iv.r) dfss.pop(); if (dfss.empty()) roots.push_back(i); else tree[dfss.top().idx].push_back(i); dfss.push(node(iv[i],i)); } for (auto i:roots){ val.push_back(dfs(i)); } sort (iter(val),[](int a,int b){return a > b;}); for (int i=0;i<min(d,int(val.size()));++i) ans -= val[i]; cout << ans; return 0; }

Compilation message (stderr)

prison.cpp: In function 'int dfs(int)':
prison.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (int i=1;i<ret.size();++i) val.push_back(ret[i]);
      |                  ~^~~~~~~~~~~
prison.cpp: In function 'int main()':
prison.cpp:71:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for (int i=0;i<iv.size();++i){
      |                  ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...