Submission #426144

#TimeUsernameProblemLanguageResultExecution timeMemory
426144dualityThe short shank; Redemption (BOI21_prison)C++11
100 / 100
671 ms223492 KiB
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long int LLI;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

int t[2000000];
vpii in;
vpii S;
vi adjList[2000000];
vi S2;
int height[2000000];
vi vv;
int doDFS(int u) {
    int i;
    for (i = 0; i < adjList[u].size(); i++) {
        int v = adjList[u][i];
        doDFS(v),height[u] = max(height[u],height[v]+1);
    }
    return 0;
}
int doDFS2(int u,int l) {
    int i,f = 0;
    for (i = 0; i < adjList[u].size(); i++) {
        int v = adjList[u][i];
        if (!f && (height[u] == height[v]+1)) doDFS2(v,l+1),f = 1;
        else doDFS2(v,1);
    }
    if (!f) vv.pb(l);
    return 0;
}
int main() {
    int i;
    int N,D,T;
    scanf("%d %d %d",&N,&D,&T);
    for (i = 0; i < N; i++) scanf("%d",&t[i]),t[i] -= i;

    int ans = 0;
    for (i = 0; i < N; i++) {
        if (t[i] <= T-i) ans++;
        else {
            int p = upper_bound(S.begin(),S.end(),mp(T-i,(int) 1e9))-S.begin()-1;
            if (p >= 0) in.pb(mp(S[p].second,i-1)),ans++;
        }
        while (!S.empty() && (S.back().first >= t[i])) S.pop_back();
        S.pb(mp(t[i],i));
    }
    for (i = 0; i < in.size(); i++) {
        while (!S2.empty() && (in[S2.back()].first >= in[i].first)) {
            adjList[i].pb(S2.back());
            S2.pop_back();
        }
        S2.pb(i);
    }
    for (i = 0; i < S2.size(); i++) {
        doDFS(S2[i]);
        doDFS2(S2[i],1);
    }
    sort(vv.begin(),vv.end(),greater<int>());
    for (i = 0; i < min(D,(int) vv.size()); i++) ans -= vv[i];
    printf("%d\n",ans);

    return 0;
}

Compilation message (stderr)

prison.cpp: In function 'int doDFS(int)':
prison.cpp:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (i = 0; i < adjList[u].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~~~~~
prison.cpp: In function 'int doDFS2(int, int)':
prison.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (i = 0; i < adjList[u].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~~~~~
prison.cpp: In function 'int main()':
prison.cpp:51: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]
   51 |     for (i = 0; i < in.size(); i++) {
      |                 ~~^~~~~~~~~~~
prison.cpp:58:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for (i = 0; i < S2.size(); i++) {
      |                 ~~^~~~~~~~~~~
prison.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%d %d %d",&N,&D,&T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
prison.cpp:39:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     for (i = 0; i < N; i++) scanf("%d",&t[i]),t[i] -= 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...