제출 #406150

#제출 시각아이디문제언어결과실행 시간메모리
406150maomao90The short shank; Redemption (BOI21_prison)C++17
35 / 100
1238 ms16344 KiB
#include <bits/stdc++.h> using namespace std; #pragma(once) #define mnto(x, y) x = min(x, (__typeof__(x)) y) #define mxto(x, y) x = max(x, (__typeof__(x)) y) #define REP(i, s, e) for (int i = s; i < e; i++) #define RREP(i, s, e) for (int i = s; i >= e; i--) typedef long long ll; typedef long double ld; #define MP make_pair #define FI first #define SE second typedef pair<int, int> ii; typedef pair<ll, ll> pll; #define MT make_tuple typedef tuple<int, int, int> iii; #define ALL(_a) _a.begin(), _a.end() #define pb emplace_back typedef vector<int> vi; typedef vector<ii> vii; #define INF 1000000005 #define LINF 1000000000000000005 #define MOD 1000000007 #define MAXN 75000 #define MAXL 22 int n, d, t; int ti[MAXN]; ll dp[2][MAXN]; int lst[MAXN]; ii p[MAXL][MAXN]; int id[MAXN * 2], val[MAXN * 2]; int fw[MAXN]; inline void incre(int p, int v) { for (; p <= n; p += p & -p) mxto(fw[p], v); } inline int query(int p) { int res = 0; for (; p > 0; p -= p & -p) mxto(res, fw[p]); return res; } inline int cost(int l, int r) { int res = 0; int cur = id[l]; RREP (k, MAXL - 1, 0) { if (p[k][cur].FI != -1 && val[p[k][cur].FI] <= r) { res += p[k][cur].SE; cur = p[k][cur].FI; } } if (p[0][cur].SE > 0) { res += r - val[cur] + 1; } return res; } inline void dnc(int i, int lo, int hi, int optl, int optr) { if (lo > hi) return; int j = lo + hi >> 1; int opt = -1; dp[i & 1][j] = LINF; REP (k, max(1, optl), min(optr + 1, j)) { if (dp[i & 1][j] > dp[(i + 1) & 1][k] + cost(k + 1, j)) { dp[i & 1][j] = dp[(i + 1) & 1][k] + cost(k + 1, j); opt = k; } } dnc(i, lo, j - 1, optl, opt); dnc(i, j + 1, hi, opt, optr); } int main() { scanf("%d%d%d", &n, &d, &t); REP (i, 1, n + 1) { scanf("%d", &ti[i]); fw[i] = -1; } RREP (i, n, 1) { int r = min(n, t - ti[i] + i); if (ti[i] > t) r = -1; if (r != -1) { mxto(r, query(r)); } incre(i, r); lst[i] = r; } int cnt = n + 1; id[n + 1] = n + 1; val[n + 1] = n + 1; RREP (i, n, 1) { id[i] = i; val[i] = i; if (lst[i] != -1) { if (lst[i] == i) { id[i] = ++cnt; val[cnt] = i; p[0][i] = MP(id[i + 1], 0); p[0][cnt] = MP(i + 1, 1); } else { p[0][i] = MP(lst[i], lst[i] - i + 1); } } else { p[0][i] = MP(id[i + 1], 0); } } p[0][n + 1] = MP(-1, 0); REP (k, 1, MAXL) { REP (i, 1, cnt + 2) { if (p[k - 1][i].FI == -1) { p[k][i] = p[k - 1][i]; } else { p[k][i] = p[k - 1][p[k - 1][i].FI]; p[k][i].SE += p[k - 1][i].SE; } } } REP (i, 1, n + 1) { dp[0][i] = cost(1, i); } REP (i, 1, d + 1) { dnc(i, 1, n, 1, n); } printf("%lld\n", dp[d & 1][n]); return 0; } /* 5 1 42 13 37 47 11 42 5 2 5 1 9 4 6 7 */

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

prison.cpp:4: warning: ignoring '#pragma ( once' [-Wunknown-pragmas]
    4 | #pragma(once)
      | 
prison.cpp: In function 'void dnc(int, int, int, int, int)':
prison.cpp:64:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |  int j = lo + hi >> 1;
      |          ~~~^~~~
prison.cpp: In function 'int main()':
prison.cpp:78:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |  scanf("%d%d%d", &n, &d, &t);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
prison.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |   scanf("%d", &ti[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...