# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1073199 | 2024-08-24T10:15:39 Z | vjudge1 | Tricks of the Trade (CEOI23_trade) | C++17 | 5496 ms | 2097152 KB |
#include <bits/stdc++.h> #define all(x) (x).begin(),(x).end() using namespace std; using ll = long long; using ld = long double; //#define int ll #define sz(x) ((int)(x).size()) using pii = pair<int,int>; using tii = tuple<int,int,int>; const int nmax = 25e4 + 5; int K; template<typename T> struct Deq { vector<T> v; void push_front(T x) { v.emplace_back(x); } T& operator[](const int& x) { return rbegin(v)[x]; } void resize(int k) { if(k >= sz(v)) return; v.erase(begin(v), begin(v) + sz(v) - k); return; } int size() { return sz(v); } }; // trebuie facut persistent struct Tree { vector<int> g[nmax]; int p[nmax]; void add_edge(int a, int b) { g[a].emplace_back(b); p[b] = a; } struct mdeq : Deq<ll> { ll lazy = 0; }; mdeq dp[nmax]; int calculated[nmax]; Tree() { memset(calculated, 0, sizeof(calculated)); } template<class CB, class CB2> void calcdp(CB&& cost, CB2 atr, int node) { if(calculated[node]) return; calculated[node] = 1; for(auto x : g[node]) { cerr << node << " <-- " << x << '\n'; calcdp(cost, atr, x); dp[x].resize(K); bool swapped = 0; auto T = dp[x]; if(sz(T) > sz(dp[node])) swap(T, dp[node]); for(int i = 0; i < sz(T); i++) dp[node][i] = max(T[i] + T.lazy - dp[node].lazy, dp[node][i]); } dp[node].push_front(cost(node) - dp[node].lazy); dp[node].lazy += atr(node); //cerr << node << ' ' << cost(node) << ' ' << atr(node) << ": "; //for(int i = 0; i < sz(dp[node]); i++) cerr << dp[node][i] + dp[node].lazy << ' '; //cerr << '\n'; return; } }; ll spart[nmax]; signed main() { cin.tie(0) -> sync_with_stdio(0); int n; cin >> n >> K; for(int i = 1, x; i <= n; i++) { cin >> spart[i]; spart[i] += spart[i - 1]; } vector<int> v(n + 1); for(int i = 1; i <= n; i++) cin >> v[i]; Tree toleft, toright; vector<int> st; for(int i = 1; i <= n; i++) { while(sz(st) && v[st.back()] <= v[i]) st.pop_back(); if(sz(st) == 0) toleft.add_edge(0, i); else toleft.add_edge(st.back(), i), toright.add_edge(i, st.back()); st.emplace_back(i); } st.clear(); for(int i = n; i > 0; i--) { while(sz(st) && v[st.back()] < v[i]) st.pop_back(); if(sz(st) == 0) toright.add_edge(0, i); else toright.add_edge(st.back(), i), toleft.add_edge(i, st.back()); st.emplace_back(i); } st.clear(); toleft.calcdp([&](int x) { return x == 0? 0 : -spart[x]; }, [&](int x) { return v[x]; }, 0); toright.calcdp([&](int x) { return x == 0? 0 : spart[x - 1]; }, [&](int x) { return v[x]; }, 0); ll best_cost = -1e18; for(int P = 1; P <= n; P++) { auto& X = toleft.dp[P]; auto& Y = toright.dp[P]; //cerr << sz(X) << ' ' << sz(Y) << '\n'; if(sz(X) > sz(Y)) swap(X, Y); for(int i = 0; i < min(K, sz(X)); i++) { int j = K - i - 1; if(j >= sz(Y)) continue; best_cost = max(best_cost, X[i] + Y[j] + X.lazy + Y.lazy - v[P]); } } cout << best_cost << '\n'; } /** Töte es durch genaue Untersuchung\Töte es kann es nur noch schlimmer machen\Es lässt es irgendwie atmen -- */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Partially correct | 18 ms | 31576 KB | Partially correct |
2 | Partially correct | 20 ms | 31580 KB | Partially correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Partially correct | 19 ms | 31580 KB | Partially correct |
2 | Partially correct | 22 ms | 31580 KB | Partially correct |
3 | Partially correct | 20 ms | 31576 KB | Partially correct |
4 | Partially correct | 29 ms | 32348 KB | Partially correct |
5 | Partially correct | 23 ms | 32348 KB | Partially correct |
6 | Partially correct | 24 ms | 31844 KB | Partially correct |
7 | Partially correct | 23 ms | 32092 KB | Partially correct |
8 | Partially correct | 23 ms | 32092 KB | Partially correct |
9 | Partially correct | 24 ms | 32092 KB | Partially correct |
10 | Partially correct | 23 ms | 31932 KB | Partially correct |
11 | Partially correct | 26 ms | 32004 KB | Partially correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Partially correct | 19 ms | 31580 KB | Partially correct |
2 | Partially correct | 22 ms | 31580 KB | Partially correct |
3 | Partially correct | 20 ms | 31576 KB | Partially correct |
4 | Partially correct | 29 ms | 32348 KB | Partially correct |
5 | Partially correct | 23 ms | 32348 KB | Partially correct |
6 | Partially correct | 24 ms | 31844 KB | Partially correct |
7 | Partially correct | 23 ms | 32092 KB | Partially correct |
8 | Partially correct | 23 ms | 32092 KB | Partially correct |
9 | Partially correct | 24 ms | 32092 KB | Partially correct |
10 | Partially correct | 23 ms | 31932 KB | Partially correct |
11 | Partially correct | 26 ms | 32004 KB | Partially correct |
12 | Partially correct | 22 ms | 31576 KB | Partially correct |
13 | Partially correct | 21 ms | 31580 KB | Partially correct |
14 | Partially correct | 22 ms | 31572 KB | Partially correct |
15 | Partially correct | 25 ms | 32348 KB | Partially correct |
16 | Partially correct | 24 ms | 32336 KB | Partially correct |
17 | Partially correct | 23 ms | 31764 KB | Partially correct |
18 | Partially correct | 31 ms | 32008 KB | Partially correct |
19 | Partially correct | 33 ms | 32080 KB | Partially correct |
20 | Partially correct | 24 ms | 32092 KB | Partially correct |
21 | Partially correct | 24 ms | 31832 KB | Partially correct |
22 | Partially correct | 25 ms | 31836 KB | Partially correct |
23 | Partially correct | 335 ms | 389716 KB | Partially correct |
24 | Partially correct | 122 ms | 34084 KB | Partially correct |
25 | Partially correct | 203 ms | 166928 KB | Partially correct |
26 | Partially correct | 131 ms | 52204 KB | Partially correct |
27 | Partially correct | 280 ms | 304440 KB | Partially correct |
28 | Partially correct | 134 ms | 33832 KB | Partially correct |
29 | Partially correct | 303 ms | 297324 KB | Partially correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Partially correct | 20 ms | 31576 KB | Partially correct |
2 | Partially correct | 3869 ms | 128644 KB | Partially correct |
3 | Partially correct | 4476 ms | 133476 KB | Partially correct |
4 | Partially correct | 4380 ms | 134864 KB | Partially correct |
5 | Partially correct | 4380 ms | 134196 KB | Partially correct |
6 | Partially correct | 4831 ms | 134364 KB | Partially correct |
7 | Partially correct | 4630 ms | 133444 KB | Partially correct |
8 | Partially correct | 4595 ms | 133660 KB | Partially correct |
9 | Partially correct | 4645 ms | 132184 KB | Partially correct |
10 | Partially correct | 4199 ms | 131016 KB | Partially correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Partially correct | 20 ms | 31576 KB | Partially correct |
2 | Partially correct | 3869 ms | 128644 KB | Partially correct |
3 | Partially correct | 4476 ms | 133476 KB | Partially correct |
4 | Partially correct | 4380 ms | 134864 KB | Partially correct |
5 | Partially correct | 4380 ms | 134196 KB | Partially correct |
6 | Partially correct | 4831 ms | 134364 KB | Partially correct |
7 | Partially correct | 4630 ms | 133444 KB | Partially correct |
8 | Partially correct | 4595 ms | 133660 KB | Partially correct |
9 | Partially correct | 4645 ms | 132184 KB | Partially correct |
10 | Partially correct | 4199 ms | 131016 KB | Partially correct |
11 | Partially correct | 20 ms | 31576 KB | Partially correct |
12 | Partially correct | 3967 ms | 129208 KB | Partially correct |
13 | Partially correct | 4439 ms | 133624 KB | Partially correct |
14 | Partially correct | 4456 ms | 134864 KB | Partially correct |
15 | Partially correct | 4351 ms | 134224 KB | Partially correct |
16 | Partially correct | 4562 ms | 134224 KB | Partially correct |
17 | Partially correct | 4535 ms | 133456 KB | Partially correct |
18 | Partially correct | 4657 ms | 133724 KB | Partially correct |
19 | Partially correct | 4622 ms | 132004 KB | Partially correct |
20 | Partially correct | 4244 ms | 131008 KB | Partially correct |
21 | Partially correct | 24 ms | 31580 KB | Partially correct |
22 | Partially correct | 20 ms | 31580 KB | Partially correct |
23 | Partially correct | 25 ms | 32348 KB | Partially correct |
24 | Partially correct | 21 ms | 32372 KB | Partially correct |
25 | Partially correct | 25 ms | 31856 KB | Partially correct |
26 | Partially correct | 21 ms | 32092 KB | Partially correct |
27 | Partially correct | 21 ms | 32284 KB | Partially correct |
28 | Partially correct | 21 ms | 32092 KB | Partially correct |
29 | Partially correct | 21 ms | 31928 KB | Partially correct |
30 | Partially correct | 21 ms | 31836 KB | Partially correct |
31 | Partially correct | 5454 ms | 1675200 KB | Partially correct |
32 | Partially correct | 4659 ms | 141908 KB | Partially correct |
33 | Partially correct | 5282 ms | 1682764 KB | Partially correct |
34 | Partially correct | 5328 ms | 1682840 KB | Partially correct |
35 | Partially correct | 5496 ms | 1682304 KB | Partially correct |
36 | Partially correct | 5346 ms | 1681536 KB | Partially correct |
37 | Partially correct | 5159 ms | 1683792 KB | Partially correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Partially correct | 18 ms | 31576 KB | Partially correct |
2 | Partially correct | 20 ms | 31580 KB | Partially correct |
3 | Partially correct | 19 ms | 31580 KB | Partially correct |
4 | Partially correct | 22 ms | 31580 KB | Partially correct |
5 | Partially correct | 20 ms | 31576 KB | Partially correct |
6 | Partially correct | 29 ms | 32348 KB | Partially correct |
7 | Partially correct | 23 ms | 32348 KB | Partially correct |
8 | Partially correct | 24 ms | 31844 KB | Partially correct |
9 | Partially correct | 23 ms | 32092 KB | Partially correct |
10 | Partially correct | 23 ms | 32092 KB | Partially correct |
11 | Partially correct | 24 ms | 32092 KB | Partially correct |
12 | Partially correct | 23 ms | 31932 KB | Partially correct |
13 | Partially correct | 26 ms | 32004 KB | Partially correct |
14 | Partially correct | 22 ms | 31576 KB | Partially correct |
15 | Partially correct | 21 ms | 31580 KB | Partially correct |
16 | Partially correct | 22 ms | 31572 KB | Partially correct |
17 | Partially correct | 25 ms | 32348 KB | Partially correct |
18 | Partially correct | 24 ms | 32336 KB | Partially correct |
19 | Partially correct | 23 ms | 31764 KB | Partially correct |
20 | Partially correct | 31 ms | 32008 KB | Partially correct |
21 | Partially correct | 33 ms | 32080 KB | Partially correct |
22 | Partially correct | 24 ms | 32092 KB | Partially correct |
23 | Partially correct | 24 ms | 31832 KB | Partially correct |
24 | Partially correct | 25 ms | 31836 KB | Partially correct |
25 | Partially correct | 335 ms | 389716 KB | Partially correct |
26 | Partially correct | 122 ms | 34084 KB | Partially correct |
27 | Partially correct | 203 ms | 166928 KB | Partially correct |
28 | Partially correct | 131 ms | 52204 KB | Partially correct |
29 | Partially correct | 280 ms | 304440 KB | Partially correct |
30 | Partially correct | 134 ms | 33832 KB | Partially correct |
31 | Partially correct | 303 ms | 297324 KB | Partially correct |
32 | Partially correct | 20 ms | 31576 KB | Partially correct |
33 | Partially correct | 3869 ms | 128644 KB | Partially correct |
34 | Partially correct | 4476 ms | 133476 KB | Partially correct |
35 | Partially correct | 4380 ms | 134864 KB | Partially correct |
36 | Partially correct | 4380 ms | 134196 KB | Partially correct |
37 | Partially correct | 4831 ms | 134364 KB | Partially correct |
38 | Partially correct | 4630 ms | 133444 KB | Partially correct |
39 | Partially correct | 4595 ms | 133660 KB | Partially correct |
40 | Partially correct | 4645 ms | 132184 KB | Partially correct |
41 | Partially correct | 4199 ms | 131016 KB | Partially correct |
42 | Partially correct | 20 ms | 31576 KB | Partially correct |
43 | Partially correct | 3967 ms | 129208 KB | Partially correct |
44 | Partially correct | 4439 ms | 133624 KB | Partially correct |
45 | Partially correct | 4456 ms | 134864 KB | Partially correct |
46 | Partially correct | 4351 ms | 134224 KB | Partially correct |
47 | Partially correct | 4562 ms | 134224 KB | Partially correct |
48 | Partially correct | 4535 ms | 133456 KB | Partially correct |
49 | Partially correct | 4657 ms | 133724 KB | Partially correct |
50 | Partially correct | 4622 ms | 132004 KB | Partially correct |
51 | Partially correct | 4244 ms | 131008 KB | Partially correct |
52 | Partially correct | 24 ms | 31580 KB | Partially correct |
53 | Partially correct | 20 ms | 31580 KB | Partially correct |
54 | Partially correct | 25 ms | 32348 KB | Partially correct |
55 | Partially correct | 21 ms | 32372 KB | Partially correct |
56 | Partially correct | 25 ms | 31856 KB | Partially correct |
57 | Partially correct | 21 ms | 32092 KB | Partially correct |
58 | Partially correct | 21 ms | 32284 KB | Partially correct |
59 | Partially correct | 21 ms | 32092 KB | Partially correct |
60 | Partially correct | 21 ms | 31928 KB | Partially correct |
61 | Partially correct | 21 ms | 31836 KB | Partially correct |
62 | Partially correct | 5454 ms | 1675200 KB | Partially correct |
63 | Partially correct | 4659 ms | 141908 KB | Partially correct |
64 | Partially correct | 5282 ms | 1682764 KB | Partially correct |
65 | Partially correct | 5328 ms | 1682840 KB | Partially correct |
66 | Partially correct | 5496 ms | 1682304 KB | Partially correct |
67 | Partially correct | 5346 ms | 1681536 KB | Partially correct |
68 | Partially correct | 5159 ms | 1683792 KB | Partially correct |
69 | Partially correct | 20 ms | 31580 KB | Partially correct |
70 | Partially correct | 4064 ms | 129228 KB | Partially correct |
71 | Partially correct | 4508 ms | 133544 KB | Partially correct |
72 | Partially correct | 4379 ms | 134920 KB | Partially correct |
73 | Partially correct | 4534 ms | 134120 KB | Partially correct |
74 | Partially correct | 4406 ms | 134248 KB | Partially correct |
75 | Partially correct | 4579 ms | 133416 KB | Partially correct |
76 | Partially correct | 4501 ms | 133480 KB | Partially correct |
77 | Partially correct | 4484 ms | 132144 KB | Partially correct |
78 | Partially correct | 3939 ms | 131020 KB | Partially correct |
79 | Partially correct | 24 ms | 31580 KB | Partially correct |
80 | Partially correct | 18 ms | 31580 KB | Partially correct |
81 | Partially correct | 22 ms | 32308 KB | Partially correct |
82 | Partially correct | 22 ms | 32396 KB | Partially correct |
83 | Partially correct | 25 ms | 31836 KB | Partially correct |
84 | Partially correct | 31 ms | 32020 KB | Partially correct |
85 | Partially correct | 26 ms | 32096 KB | Partially correct |
86 | Partially correct | 32 ms | 32080 KB | Partially correct |
87 | Partially correct | 24 ms | 31836 KB | Partially correct |
88 | Partially correct | 25 ms | 31836 KB | Partially correct |
89 | Partially correct | 5343 ms | 1675112 KB | Partially correct |
90 | Partially correct | 4318 ms | 141884 KB | Partially correct |
91 | Partially correct | 5256 ms | 1682768 KB | Partially correct |
92 | Partially correct | 5329 ms | 1682744 KB | Partially correct |
93 | Partially correct | 5442 ms | 1682500 KB | Partially correct |
94 | Partially correct | 5472 ms | 1681676 KB | Partially correct |
95 | Partially correct | 5142 ms | 1683996 KB | Partially correct |
96 | Partially correct | 335 ms | 389716 KB | Partially correct |
97 | Partially correct | 120 ms | 34148 KB | Partially correct |
98 | Partially correct | 220 ms | 166992 KB | Partially correct |
99 | Partially correct | 132 ms | 52304 KB | Partially correct |
100 | Partially correct | 284 ms | 304464 KB | Partially correct |
101 | Partially correct | 123 ms | 34048 KB | Partially correct |
102 | Partially correct | 349 ms | 297556 KB | Partially correct |
103 | Runtime error | 2720 ms | 2097152 KB | Execution killed with signal 9 |
104 | Halted | 0 ms | 0 KB | - |