제출 #444333

#제출 시각아이디문제언어결과실행 시간메모리
444333parsabahramiThe short shank; Redemption (BOI21_prison)C++17
55 / 100
2089 ms204160 KiB
/* I do it for the glory */ #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<double, int> pii; #define SZ(x) (int) x.size() #define F first #define S second #define lc id << 1 #define rc lc | 1 const int N = 1e6 + 10, MOD = 1e9 + 7; const double eps = 1e-14; int R[N], t[N], n, T, D; int seg[N << 2], dp[N][100]; void bld(int x, int id = 1, int l = 1, int r = n + 1) { if (r - l < 2) { seg[id] = dp[l][x] + l; return; } int md = (l + r) >> 1; bld(x, lc, l, md), bld(x, rc, md, r); seg[id] = min(seg[lc], seg[rc]); } int get(int ql, int qr, int id = 1, int l = 1, int r = n + 1) { if (qr <= l || r <= ql) return MOD; if (ql <= l && r <= qr) { return seg[id]; } int md = (l + r) >> 1; return min(get(ql, qr, lc, l, md), get(ql, qr, rc, md, r)); } int main() { scanf("%d%d%d", &n, &D, &T); //assert(n <= N); for (int i = 1; i <= n; i++) scanf("%d", &t[i]); for (int i = n; i; i--) { for (R[i] = i + 1; R[i] <= n && t[R[i]] - R[i] > t[i] - i; R[i] = R[R[i]]); } for (int i = n; i; i--) { if (R[i] <= min(n, i + T - t[i])) R[i] = R[R[i]]; else R[i] = min(n, i + T - t[i]); if (R[i] < i) R[i] = -1; } for (int i = n; i; i--) { if (R[i] < i) dp[i][0] = dp[i + 1][0]; else dp[i][0] = (R[i] - i + 1) + dp[R[i] + 1][0]; } for (int j = 1; j <= D; j++) { bld(j - 1); for (int i = n; i; i--) { if (R[i] < i) dp[i][j] = min(dp[i + 1][j - 1], dp[i + 1][j]); else { int x = get(i + 1, R[i] + 2); dp[i][j] = min(x - i, dp[R[i] + 1][j] + R[i] - i + 1); } } } printf("%d\n", dp[1][D]); return 0; }

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

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