結果
問題 | No.1077 Noelちゃんと星々4 |
ユーザー | hipotaf |
提出日時 | 2020-06-12 22:55:47 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,933 ms / 2,000 ms |
コード長 | 2,153 bytes |
コンパイル時間 | 894 ms |
コンパイル使用メモリ | 86,304 KB |
実行使用メモリ | 81,992 KB |
最終ジャッジ日時 | 2023-09-06 11:05:19 |
合計ジャッジ時間 | 20,374 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 13 ms
4,380 KB |
testcase_01 | AC | 21 ms
4,440 KB |
testcase_02 | AC | 1,294 ms
57,176 KB |
testcase_03 | AC | 1,676 ms
73,048 KB |
testcase_04 | AC | 507 ms
24,416 KB |
testcase_05 | AC | 378 ms
19,220 KB |
testcase_06 | AC | 660 ms
30,664 KB |
testcase_07 | AC | 796 ms
34,884 KB |
testcase_08 | AC | 560 ms
26,352 KB |
testcase_09 | AC | 473 ms
23,252 KB |
testcase_10 | AC | 1,726 ms
73,228 KB |
testcase_11 | AC | 1,086 ms
48,544 KB |
testcase_12 | AC | 922 ms
40,532 KB |
testcase_13 | AC | 356 ms
18,452 KB |
testcase_14 | AC | 1,650 ms
71,512 KB |
testcase_15 | AC | 871 ms
39,440 KB |
testcase_16 | AC | 565 ms
27,040 KB |
testcase_17 | AC | 968 ms
44,188 KB |
testcase_18 | AC | 1,733 ms
74,424 KB |
testcase_19 | AC | 345 ms
17,808 KB |
testcase_20 | AC | 4 ms
4,380 KB |
testcase_21 | AC | 1,933 ms
81,992 KB |
ソースコード
#include <iostream> #include <string> #include <vector> #include <climits> #include <cmath> using namespace std; using ll = long long; template <class T> using grid = vector<vector<T>>; #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) #define input(...) __VA_ARGS__; in(__VA_ARGS__) void print() { std::cout << std::endl; } template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { std::cout << head << " "; print(std::forward<Tail>(tail)...); } void in() { } template <class Head, class... Tail> void in(Head&& head, Tail&&... tail) { cin >> head; in(std::forward<Tail>(tail)...); } #define NEUTRAL LLONG_MAX #define OP min class SegTree { public: int t = 1; vector<long long> table; SegTree(int n) { while (t <= n) { t *= 2; } table = vector<long long>(t * 2 - 1, NEUTRAL); } int up(int node) { return (node - 1) / 2; } int down(int node) { return (node * 2) + 1; } void update(int i, long long x) { i += t - 1; table[i] = x; while (i != 0) { i = up(i); int c = down(i); table[i] = OP(table[c], table[c + 1]); } } long long find(int l, int r, int node=0, int sl=0, int sr=-1) { if (sr < 0) sr = t; if (sr <= l || r <= sl) { return NEUTRAL; } if (l <= sl && sr <= r) { return table[node]; } int sc = (sl + sr) / 2; int c = down(node); return OP(find(l, r, c, sl, sc), find(l, r, c + 1, sc, sr)); } }; int main() { ll input(n); vector<ll> y(n); REP(i, n) cin >> y[i]; ll YMAX = 10000; vector<vector<ll>> table(n + 1); REP(i, n + 1) { if (i == n) table[i] = vector<ll>(YMAX + 1, 0); else table[i] = vector<ll>(YMAX + 1); } REPD(i, n) { SegTree seg(YMAX + 1); FOR(j, 0, YMAX) { seg.update(j, table[i + 1][j] + abs(y[i] - j)); } FORD(h, YMAX, 0) { table[i][h] = seg.find(h, YMAX + 1); } } print(table[0][0]); }