제출 #407213

#제출 시각아이디문제언어결과실행 시간메모리
407213mat_vThe short shank; Redemption (BOI21_prison)C++14
35 / 100
2095 ms117516 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


int n,d,t;
int niz[100005];

int dp[4005][4005];
int ans[4005][4005];
int nxt[4005];
int seg[4 * 4005][4005];


int kveri(int node, int l, int r, int levo, int desno, int idx){
    if(l > r || levo > desno)return 1e9;
    if(r < levo || desno < l)return 1e9;
    if(l >= levo && r <= desno)return seg[node][idx];
    int mid = (l + r) / 2;
    return min(kveri(node * 2, l, mid, levo, desno, idx), kveri(node * 2 + 1, mid + 1, r, levo, desno, idx));
}
void init(int node, int l, int r, int idx){
    if(l == r){
        seg[node][idx] = 1e9;
        return;
    }
    int mid = (l + r) / 2;
    init(node * 2, l, mid, idx);
    init(node * 2 + 1, mid + 1, r, idx);
    seg[node][idx] = 1e9;
}
void update(int node, int l, int r, int poz, int val, int idx){
    if(l == r){
        seg[node][idx] = val;
        return;
    }
    int mid = (l + r) / 2;
    if(poz <= mid)update(node * 2, l, mid, poz, val, idx);
    else update(node * 2 + 1, mid + 1, r, poz, val, idx);
    seg[node][idx] = min(seg[node * 2][idx], seg[node * 2 + 1][idx]);
}

int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> n >> d >> t;
    ff(i,1,n){
        cin >> niz[i];
        niz[i] -= i;
    }
    d = min(n,d);
    ff(i,1,n){
        int mn = niz[i];
        ff(j,i,n){
            if(j > i)ans[i][j] += ans[i][j - 1];
            mn = min(mn, niz[j]);
            if(mn <= t-j)ans[i][j]++;
        }
    }
    ff(i,1,n){
        ff(j,i+1,n){
            if(niz[j] <= niz[i]){
                nxt[i] = j;
                break;
            }
        }
        if(nxt[i] == 0)nxt[i] = n+1;
    }


    ff(j,0,d){
        if(j == 0){
            fb(i,n,1){
                dp[i][j] = ans[i][n];
                update(1,1,n,i,i+dp[i][0],0);
            }
            continue;
        }
        fb(i,n,1){
            dp[i][j] = dp[nxt[i]][j] + ans[i][nxt[i] - 1];
            int r = nxt[i] - 1;
            int reach = t - (i + niz[i]);
            if(reach < 0){
                dp[i][j] = dp[i + 1][j];
                continue;
            }
            r = min(r, i + reach);
            dp[i][j] = min(dp[i][j], kveri(1,1,n,i,r,j-1)-i);
        }
        ff(i,1,n)update(1,1,n,i,i+dp[i][j],j);
    }
    cout << dp[1][d] << "\n";
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

prison.cpp: In function 'int main()':
prison.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
prison.cpp:65:5: note: in expansion of macro 'ff'
   65 |     ff(i,1,n){
      |     ^~
prison.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
prison.cpp:70:5: note: in expansion of macro 'ff'
   70 |     ff(i,1,n){
      |     ^~
prison.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
prison.cpp:72:9: note: in expansion of macro 'ff'
   72 |         ff(j,i,n){
      |         ^~
prison.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
prison.cpp:78:5: note: in expansion of macro 'ff'
   78 |     ff(i,1,n){
      |     ^~
prison.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
prison.cpp:79:9: note: in expansion of macro 'ff'
   79 |         ff(j,i+1,n){
      |         ^~
prison.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
prison.cpp:89:5: note: in expansion of macro 'ff'
   89 |     ff(j,0,d){
      |     ^~
prison.cpp:7:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
      |                           ^
prison.cpp:91:13: note: in expansion of macro 'fb'
   91 |             fb(i,n,1){
      |             ^~
prison.cpp:7:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
      |                           ^
prison.cpp:97:9: note: in expansion of macro 'fb'
   97 |         fb(i,n,1){
      |         ^~
prison.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
prison.cpp:108:9: note: in expansion of macro 'ff'
  108 |         ff(i,1,n)update(1,1,n,i,i+dp[i][j],j);
      |         ^~
#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...