Submission #659370

#TimeUsernameProblemLanguageResultExecution timeMemory
659370600MihneaThe short shank; Redemption (BOI21_prison)C++17
0 / 100
3 ms340 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]; int compute2() { int sol = 0, last_blocked; for (int i = 1; i <= n; i++) { if (ant[i] == 0) { continue; } /// ant[i], i sol++; for (int j = ant[i]; j < i; j++) { if (block[j]) { sol--; break; } } } return sol; } int compute() { int sl = compute2(); int last = INF, sol = 0; for (int i = 1; i <= n; i++) { if (block[i - 1]) { last = trebel[i]; } else { last = min(last + 1, trebel[i]); } sol += (last <= t); } assert(sol == sl); return sol; } 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++) { int init = compute(); int mx = -1, jj = -1; for (int i = 1; i < n; i++) { if (!block[i]) { block[i] = 1; gain[i] = init - compute(); assert(gain[i] >= 0); if (gain[i] >= mx) { mx = gain[i]; jj = i; } block[i] = 0; } } assert(1 <= jj && jj < n); block[jj] = 1; } cout << compute() << "\n"; return 0; }

Compilation message (stderr)

prison.cpp: In function 'int compute2()':
prison.cpp:16:16: warning: unused variable 'last_blocked' [-Wunused-variable]
   16 |   int sol = 0, last_blocked;
      |                ^~~~~~~~~~~~
prison.cpp: In function 'int main()':
prison.cpp:51:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |   freopen ("input.txt", "r", stdin);
      |   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...