Submission #734676

#TimeUsernameProblemLanguageResultExecution timeMemory
734676lovrotThe short shank; Redemption (BOI21_prison)C++17
15 / 100
2066 ms133900 KiB
#include <cstdio> #include <algorithm> #include <cstring> #define X first #define Y second #define pb push_back using namespace std; typedef long long ll; typedef pair<int, int> pii; const int LOG = 12; const int OFF = 1 << LOG; const int INF = 2e9; const int N = 4010; int n, d, t, C[OFF], E[OFF]; int T[2 * OFF], P[2 * OFF]; void add(int x, int val) { T[x] += val; P[x] += val; } void propagate(int x) { if(x >= OFF) return; add(2 * x, P[x]); add(2 * x + 1, P[x]); P[x] = 0; } int desc(int ind, int val, int x = 1, int lo = 0, int hi = OFF) { if(ind + 1 <= lo || hi <= ind) return T[x]; if(lo + 1 == hi) { T[x] = val; P[x] = 0; return T[x]; } propagate(x); int mi = (lo + hi) / 2; T[x] = min(desc(ind, val, 2 * x, lo, mi), desc(ind, val, 2 * x + 1, mi, hi)); return T[x]; } int update(int l, int r, int val, int x = 1, int lo = 0, int hi = OFF) { if(r <= lo || hi <= l) return T[x]; if(l <= lo && hi <= r) { add(x, val); return T[x]; } propagate(x); int mi = (lo + hi) / 2; T[x] = min(update(l, r, val, 2 * x, lo, mi), update(l, r, val, 2 * x + 1, mi, hi)); return T[x]; } int query(int val, int x = 1, int lo = 0, int hi = OFF) { if(lo + 1 == hi) return lo; if(T[x] > val) return -1; propagate(x); int mi = (lo + hi) / 2; if(T[2 * x + 1] <= val) return query(val, 2 * x + 1, mi, hi); return query(val, 2 * x, lo, mi); } int DP[OFF][OFF]; int dyn(int i, int w) { if(i >= n) return 0; if(DP[i][w] != -1) return DP[i][w]; DP[i][w] = 0; for(int j = i; j < n; j++) DP[i][w] += E[j] >= i; if(w) { int cnt = 0; for(int j = i; j < n; j++) { cnt += E[j] >= i; DP[i][w] = min(DP[i][w], cnt + dyn(j + 1, w - 1)); } } return DP[i][w]; } int main() { for(int i = 0; i < 2 * OFF; i++) T[i] = INF; memset(DP, -1, sizeof(DP)); scanf("%d%d%d", &n, &d, &t); d = min(d, n); for(int i = 0; i < n; i++) { scanf("%d", C + i); desc(i, C[i]), update(0, i, 1); E[i] = query(t); } printf("%d\n", dyn(0, d)); return 0; }

Compilation message (stderr)

prison.cpp: In function 'int main()':
prison.cpp:89:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |  scanf("%d%d%d", &n, &d, &t);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
prison.cpp:92:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |   scanf("%d", C + 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...