# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1089893 | 2024-09-17T11:20:00 Z | KALARRY | Tricks of the Trade (CEOI23_trade) | C++14 | 2757 ms | 2097152 KB |
//chockolateman #include<bits/stdc++.h> using namespace std; long long N,K,a[250005],b[250005],dp[250005][205]; vector<vector<vector<pair<int,int>>>> adj; vector<vector<bool>> visited; bool used[250005]; void dfs(int startv,int startj) { queue<pair<int,int>> q; q.push({startv,startj}); while(!q.empty()) { int v = q.front().first; int j = q.front().second; q.pop(); if(visited[v][j]) continue; visited[v][j] = true; if(j==0) continue;; for(auto e : adj[v][j]) { int u = e.first; int newj = e.second; if(newj==(j-1)) used[v] = true; q.push({u,newj}); } } } int main() { scanf("%lld%lld",&N,&K); adj.resize(N+1); vector<bool> full_false; for(int j = 0 ; j <= K ; j++) full_false.push_back(false); for(int i = 0 ; i <= N ; i++) { adj[i].resize(K+1); visited.push_back(full_false); } for(long long i = 1 ; i <= N ; i++) scanf("%lld",&a[i]); for(long long i = 1 ; i <= N ; i++) scanf("%lld",&b[i]); for(long long j = 1 ; j <= K ; j++) { dp[0][j%2] = -1e15; for(long long i = 1 ; i <= N ; i++) { dp[i][j%2] = max(dp[i-1][j%2] - a[i],dp[i-1][(j-1)%2] + b[i] - a[i]); if(dp[i][j%2]==dp[i-1][j%2] - a[i]) adj[i][j].push_back({i-1,j}); if(dp[i][j%2] == dp[i-1][(j-1)%2] + b[i] - a[i]) adj[i][j].push_back({i-1,j-1}); } } long long ans = -1e15; for(long long i = 1 ; i <= N ; i++) ans = max(ans,dp[i][K%2]); for(long long i = 1 ; i <= N ; i++) if(dp[i][K%2]==ans) dfs(i,K); printf("%lld\n",ans); for(int i = 1 ; i <= N ; i++) printf("%d",used[i]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 2 ms | 1884 KB | Output is correct |
5 | Correct | 3 ms | 2908 KB | Output is correct |
6 | Correct | 1 ms | 860 KB | Output is correct |
7 | Correct | 1 ms | 1220 KB | Output is correct |
8 | Correct | 2 ms | 1628 KB | Output is correct |
9 | Correct | 3 ms | 1372 KB | Output is correct |
10 | Correct | 1 ms | 1116 KB | Output is correct |
11 | Correct | 1 ms | 1116 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 2 ms | 1884 KB | Output is correct |
5 | Correct | 3 ms | 2908 KB | Output is correct |
6 | Correct | 1 ms | 860 KB | Output is correct |
7 | Correct | 1 ms | 1220 KB | Output is correct |
8 | Correct | 2 ms | 1628 KB | Output is correct |
9 | Correct | 3 ms | 1372 KB | Output is correct |
10 | Correct | 1 ms | 1116 KB | Output is correct |
11 | Correct | 1 ms | 1116 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 1 ms | 456 KB | Output is correct |
14 | Correct | 0 ms | 344 KB | Output is correct |
15 | Correct | 2 ms | 1884 KB | Output is correct |
16 | Correct | 3 ms | 2952 KB | Output is correct |
17 | Correct | 1 ms | 860 KB | Output is correct |
18 | Correct | 1 ms | 1372 KB | Output is correct |
19 | Correct | 3 ms | 1876 KB | Output is correct |
20 | Correct | 1 ms | 1372 KB | Output is correct |
21 | Correct | 1 ms | 1116 KB | Output is correct |
22 | Correct | 1 ms | 1112 KB | Output is correct |
23 | Correct | 2757 ms | 2001580 KB | Output is correct |
24 | Correct | 7 ms | 11956 KB | Output is correct |
25 | Correct | 453 ms | 340280 KB | Output is correct |
26 | Correct | 56 ms | 43692 KB | Output is correct |
27 | Correct | 1407 ms | 859080 KB | Output is correct |
28 | Correct | 6 ms | 11448 KB | Output is correct |
29 | Correct | 1234 ms | 999316 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 261 ms | 465468 KB | Output is correct |
3 | Correct | 234 ms | 467568 KB | Output is correct |
4 | Correct | 252 ms | 467404 KB | Output is correct |
5 | Correct | 271 ms | 467632 KB | Output is correct |
6 | Correct | 257 ms | 467148 KB | Output is correct |
7 | Correct | 250 ms | 466892 KB | Output is correct |
8 | Correct | 247 ms | 467660 KB | Output is correct |
9 | Correct | 243 ms | 465764 KB | Output is correct |
10 | Correct | 250 ms | 466632 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 261 ms | 465468 KB | Output is correct |
3 | Correct | 234 ms | 467568 KB | Output is correct |
4 | Correct | 252 ms | 467404 KB | Output is correct |
5 | Correct | 271 ms | 467632 KB | Output is correct |
6 | Correct | 257 ms | 467148 KB | Output is correct |
7 | Correct | 250 ms | 466892 KB | Output is correct |
8 | Correct | 247 ms | 467660 KB | Output is correct |
9 | Correct | 243 ms | 465764 KB | Output is correct |
10 | Correct | 250 ms | 466632 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 257 ms | 465688 KB | Output is correct |
13 | Correct | 252 ms | 467508 KB | Output is correct |
14 | Correct | 260 ms | 467584 KB | Output is correct |
15 | Correct | 250 ms | 467444 KB | Output is correct |
16 | Correct | 266 ms | 467148 KB | Output is correct |
17 | Correct | 243 ms | 466644 KB | Output is correct |
18 | Correct | 235 ms | 467404 KB | Output is correct |
19 | Correct | 230 ms | 465868 KB | Output is correct |
20 | Correct | 235 ms | 466724 KB | Output is correct |
21 | Correct | 0 ms | 344 KB | Output is correct |
22 | Correct | 0 ms | 344 KB | Output is correct |
23 | Correct | 2 ms | 1884 KB | Output is correct |
24 | Correct | 3 ms | 2868 KB | Output is correct |
25 | Correct | 0 ms | 860 KB | Output is correct |
26 | Correct | 1 ms | 1372 KB | Output is correct |
27 | Correct | 2 ms | 1608 KB | Output is correct |
28 | Correct | 1 ms | 1372 KB | Output is correct |
29 | Correct | 1 ms | 1116 KB | Output is correct |
30 | Correct | 1 ms | 1116 KB | Output is correct |
31 | Runtime error | 1248 ms | 2097152 KB | Execution killed with signal 9 |
32 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 2 ms | 1884 KB | Output is correct |
7 | Correct | 3 ms | 2908 KB | Output is correct |
8 | Correct | 1 ms | 860 KB | Output is correct |
9 | Correct | 1 ms | 1220 KB | Output is correct |
10 | Correct | 2 ms | 1628 KB | Output is correct |
11 | Correct | 3 ms | 1372 KB | Output is correct |
12 | Correct | 1 ms | 1116 KB | Output is correct |
13 | Correct | 1 ms | 1116 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 456 KB | Output is correct |
16 | Correct | 0 ms | 344 KB | Output is correct |
17 | Correct | 2 ms | 1884 KB | Output is correct |
18 | Correct | 3 ms | 2952 KB | Output is correct |
19 | Correct | 1 ms | 860 KB | Output is correct |
20 | Correct | 1 ms | 1372 KB | Output is correct |
21 | Correct | 3 ms | 1876 KB | Output is correct |
22 | Correct | 1 ms | 1372 KB | Output is correct |
23 | Correct | 1 ms | 1116 KB | Output is correct |
24 | Correct | 1 ms | 1112 KB | Output is correct |
25 | Correct | 2757 ms | 2001580 KB | Output is correct |
26 | Correct | 7 ms | 11956 KB | Output is correct |
27 | Correct | 453 ms | 340280 KB | Output is correct |
28 | Correct | 56 ms | 43692 KB | Output is correct |
29 | Correct | 1407 ms | 859080 KB | Output is correct |
30 | Correct | 6 ms | 11448 KB | Output is correct |
31 | Correct | 1234 ms | 999316 KB | Output is correct |
32 | Correct | 1 ms | 344 KB | Output is correct |
33 | Correct | 261 ms | 465468 KB | Output is correct |
34 | Correct | 234 ms | 467568 KB | Output is correct |
35 | Correct | 252 ms | 467404 KB | Output is correct |
36 | Correct | 271 ms | 467632 KB | Output is correct |
37 | Correct | 257 ms | 467148 KB | Output is correct |
38 | Correct | 250 ms | 466892 KB | Output is correct |
39 | Correct | 247 ms | 467660 KB | Output is correct |
40 | Correct | 243 ms | 465764 KB | Output is correct |
41 | Correct | 250 ms | 466632 KB | Output is correct |
42 | Correct | 1 ms | 348 KB | Output is correct |
43 | Correct | 257 ms | 465688 KB | Output is correct |
44 | Correct | 252 ms | 467508 KB | Output is correct |
45 | Correct | 260 ms | 467584 KB | Output is correct |
46 | Correct | 250 ms | 467444 KB | Output is correct |
47 | Correct | 266 ms | 467148 KB | Output is correct |
48 | Correct | 243 ms | 466644 KB | Output is correct |
49 | Correct | 235 ms | 467404 KB | Output is correct |
50 | Correct | 230 ms | 465868 KB | Output is correct |
51 | Correct | 235 ms | 466724 KB | Output is correct |
52 | Correct | 0 ms | 344 KB | Output is correct |
53 | Correct | 0 ms | 344 KB | Output is correct |
54 | Correct | 2 ms | 1884 KB | Output is correct |
55 | Correct | 3 ms | 2868 KB | Output is correct |
56 | Correct | 0 ms | 860 KB | Output is correct |
57 | Correct | 1 ms | 1372 KB | Output is correct |
58 | Correct | 2 ms | 1608 KB | Output is correct |
59 | Correct | 1 ms | 1372 KB | Output is correct |
60 | Correct | 1 ms | 1116 KB | Output is correct |
61 | Correct | 1 ms | 1116 KB | Output is correct |
62 | Runtime error | 1248 ms | 2097152 KB | Execution killed with signal 9 |
63 | Halted | 0 ms | 0 KB | - |