Submission #659381

#TimeUsernameProblemLanguageResultExecution timeMemory
659381600MihneaThe short shank; Redemption (BOI21_prison)C++17
15 / 100
2086 ms2608 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2000000 + 7; const int INF = (int) 1e9 + 7; int n; int d; int t; int trebel[N]; bool block[N]; int gain[N]; int ant[N]; bool valid[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen ("input.txt", "r", stdin); cin >> n >> d >> t; for (int i = 1; i <= n; i++) { cin >> trebel[i]; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { if (trebel[j] + i - j <= t) { ant[i] = j; } } } for (int iqd = 1; iqd <= d; iqd++) { for (int i = 1; i <= n; i++) { valid[i] = 0; if (ant[i]) { valid[i] = 1; for (int j = ant[i]; j < i; j++) { valid[i] &= (block[j] == 0); } } } for (int i = 1; i < n; i++) { if (!block[i]) { gain[i] = 0; for (int j = 1; j <= n; j++) { if (valid[j] && ant[j] <= i && i < j) { gain[i]++; } } } } int mx = -1, jj = -1; for (int i = 1; i < n; i++) { if (!block[i]) { if (gain[i] >= mx) { mx = gain[i]; jj = i; } } } assert(1 <= jj && jj < n); block[jj] = 1; } for (int i = 1; i <= n; i++) { valid[i] = 0; if (ant[i]) { valid[i] = 1; for (int j = ant[i]; j < i; j++) { valid[i] &= (block[j] == 0); } } } int sol = 0; for (int i = 1; i <= n; i++) { sol += valid[i]; } cout << sol << "\n"; return 0; }
#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...