# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1089884 | 2024-09-17T11:08:38 Z | KALARRY | Tricks of the Trade (CEOI23_trade) | C++14 | 1574 ms | 2097152 KB |
//chockolateman #include<bits/stdc++.h> using namespace std; long long N,K,a[250005],b[250005],dp[250005][205]; vector<pair<int,int>> adj[250005][205]; bool visited[250005][205]; 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]) return; visited[v][j] = true; if(j==0) return; for(auto e : adj[v][j]) { int u = e.first; int newj = e.second; if(newj==(j-1)) used[v] = true; dfs(u,newj); } } } int main() { scanf("%lld%lld",&N,&K); 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 479 ms | 1203808 KB | Output is correct |
2 | Correct | 467 ms | 1204052 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 501 ms | 1203796 KB | Output is correct |
2 | Correct | 497 ms | 1203792 KB | Output is correct |
3 | Correct | 495 ms | 1203812 KB | Output is correct |
4 | Correct | 497 ms | 1204804 KB | Output is correct |
5 | Correct | 443 ms | 1205604 KB | Output is correct |
6 | Correct | 440 ms | 1204304 KB | Output is correct |
7 | Correct | 430 ms | 1204572 KB | Output is correct |
8 | Correct | 439 ms | 1204932 KB | Output is correct |
9 | Correct | 428 ms | 1204728 KB | Output is correct |
10 | Correct | 429 ms | 1204560 KB | Output is correct |
11 | Correct | 474 ms | 1204604 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 501 ms | 1203796 KB | Output is correct |
2 | Correct | 497 ms | 1203792 KB | Output is correct |
3 | Correct | 495 ms | 1203812 KB | Output is correct |
4 | Correct | 497 ms | 1204804 KB | Output is correct |
5 | Correct | 443 ms | 1205604 KB | Output is correct |
6 | Correct | 440 ms | 1204304 KB | Output is correct |
7 | Correct | 430 ms | 1204572 KB | Output is correct |
8 | Correct | 439 ms | 1204932 KB | Output is correct |
9 | Correct | 428 ms | 1204728 KB | Output is correct |
10 | Correct | 429 ms | 1204560 KB | Output is correct |
11 | Correct | 474 ms | 1204604 KB | Output is correct |
12 | Correct | 490 ms | 1203764 KB | Output is correct |
13 | Correct | 528 ms | 1203980 KB | Output is correct |
14 | Correct | 473 ms | 1203820 KB | Output is correct |
15 | Correct | 492 ms | 1204996 KB | Output is correct |
16 | Correct | 464 ms | 1205840 KB | Output is correct |
17 | Correct | 487 ms | 1204308 KB | Output is correct |
18 | Correct | 467 ms | 1204560 KB | Output is correct |
19 | Correct | 430 ms | 1204816 KB | Output is correct |
20 | Correct | 432 ms | 1204676 KB | Output is correct |
21 | Correct | 473 ms | 1204392 KB | Output is correct |
22 | Correct | 431 ms | 1204560 KB | Output is correct |
23 | Partially correct | 1361 ms | 1551168 KB | Partially correct |
24 | Correct | 478 ms | 1216008 KB | Output is correct |
25 | Partially correct | 996 ms | 1308924 KB | Partially correct |
26 | Correct | 507 ms | 1236092 KB | Output is correct |
27 | Partially correct | 1574 ms | 1484624 KB | Partially correct |
28 | Correct | 448 ms | 1214036 KB | Output is correct |
29 | Partially correct | 1243 ms | 1390216 KB | Partially correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 513 ms | 1203792 KB | Output is correct |
2 | Correct | 765 ms | 1676368 KB | Output is correct |
3 | Correct | 697 ms | 1627984 KB | Output is correct |
4 | Correct | 680 ms | 1627944 KB | Output is correct |
5 | Correct | 711 ms | 1696852 KB | Output is correct |
6 | Correct | 698 ms | 1678928 KB | Output is correct |
7 | Correct | 925 ms | 1865232 KB | Output is correct |
8 | Correct | 621 ms | 1627984 KB | Output is correct |
9 | Correct | 622 ms | 1626452 KB | Output is correct |
10 | Correct | 737 ms | 1677392 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 513 ms | 1203792 KB | Output is correct |
2 | Correct | 765 ms | 1676368 KB | Output is correct |
3 | Correct | 697 ms | 1627984 KB | Output is correct |
4 | Correct | 680 ms | 1627944 KB | Output is correct |
5 | Correct | 711 ms | 1696852 KB | Output is correct |
6 | Correct | 698 ms | 1678928 KB | Output is correct |
7 | Correct | 925 ms | 1865232 KB | Output is correct |
8 | Correct | 621 ms | 1627984 KB | Output is correct |
9 | Correct | 622 ms | 1626452 KB | Output is correct |
10 | Correct | 737 ms | 1677392 KB | Output is correct |
11 | Correct | 494 ms | 1203936 KB | Output is correct |
12 | Correct | 742 ms | 1676456 KB | Output is correct |
13 | Correct | 688 ms | 1628244 KB | Output is correct |
14 | Correct | 679 ms | 1628288 KB | Output is correct |
15 | Correct | 743 ms | 1696856 KB | Output is correct |
16 | Correct | 668 ms | 1678928 KB | Output is correct |
17 | Correct | 757 ms | 1865300 KB | Output is correct |
18 | Correct | 619 ms | 1627984 KB | Output is correct |
19 | Correct | 616 ms | 1626392 KB | Output is correct |
20 | Correct | 718 ms | 1677368 KB | Output is correct |
21 | Correct | 462 ms | 1203792 KB | Output is correct |
22 | Correct | 463 ms | 1203792 KB | Output is correct |
23 | Correct | 471 ms | 1204808 KB | Output is correct |
24 | Correct | 463 ms | 1205588 KB | Output is correct |
25 | Correct | 487 ms | 1204240 KB | Output is correct |
26 | Correct | 428 ms | 1204560 KB | Output is correct |
27 | Correct | 442 ms | 1204820 KB | Output is correct |
28 | Correct | 438 ms | 1204860 KB | Output is correct |
29 | Correct | 449 ms | 1204564 KB | Output is correct |
30 | Correct | 444 ms | 1204672 KB | Output is correct |
31 | Runtime error | 1206 ms | 2097152 KB | Execution killed with signal 9 |
32 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 479 ms | 1203808 KB | Output is correct |
2 | Correct | 467 ms | 1204052 KB | Output is correct |
3 | Correct | 501 ms | 1203796 KB | Output is correct |
4 | Correct | 497 ms | 1203792 KB | Output is correct |
5 | Correct | 495 ms | 1203812 KB | Output is correct |
6 | Correct | 497 ms | 1204804 KB | Output is correct |
7 | Correct | 443 ms | 1205604 KB | Output is correct |
8 | Correct | 440 ms | 1204304 KB | Output is correct |
9 | Correct | 430 ms | 1204572 KB | Output is correct |
10 | Correct | 439 ms | 1204932 KB | Output is correct |
11 | Correct | 428 ms | 1204728 KB | Output is correct |
12 | Correct | 429 ms | 1204560 KB | Output is correct |
13 | Correct | 474 ms | 1204604 KB | Output is correct |
14 | Correct | 490 ms | 1203764 KB | Output is correct |
15 | Correct | 528 ms | 1203980 KB | Output is correct |
16 | Correct | 473 ms | 1203820 KB | Output is correct |
17 | Correct | 492 ms | 1204996 KB | Output is correct |
18 | Correct | 464 ms | 1205840 KB | Output is correct |
19 | Correct | 487 ms | 1204308 KB | Output is correct |
20 | Correct | 467 ms | 1204560 KB | Output is correct |
21 | Correct | 430 ms | 1204816 KB | Output is correct |
22 | Correct | 432 ms | 1204676 KB | Output is correct |
23 | Correct | 473 ms | 1204392 KB | Output is correct |
24 | Correct | 431 ms | 1204560 KB | Output is correct |
25 | Partially correct | 1361 ms | 1551168 KB | Partially correct |
26 | Correct | 478 ms | 1216008 KB | Output is correct |
27 | Partially correct | 996 ms | 1308924 KB | Partially correct |
28 | Correct | 507 ms | 1236092 KB | Output is correct |
29 | Partially correct | 1574 ms | 1484624 KB | Partially correct |
30 | Correct | 448 ms | 1214036 KB | Output is correct |
31 | Partially correct | 1243 ms | 1390216 KB | Partially correct |
32 | Correct | 513 ms | 1203792 KB | Output is correct |
33 | Correct | 765 ms | 1676368 KB | Output is correct |
34 | Correct | 697 ms | 1627984 KB | Output is correct |
35 | Correct | 680 ms | 1627944 KB | Output is correct |
36 | Correct | 711 ms | 1696852 KB | Output is correct |
37 | Correct | 698 ms | 1678928 KB | Output is correct |
38 | Correct | 925 ms | 1865232 KB | Output is correct |
39 | Correct | 621 ms | 1627984 KB | Output is correct |
40 | Correct | 622 ms | 1626452 KB | Output is correct |
41 | Correct | 737 ms | 1677392 KB | Output is correct |
42 | Correct | 494 ms | 1203936 KB | Output is correct |
43 | Correct | 742 ms | 1676456 KB | Output is correct |
44 | Correct | 688 ms | 1628244 KB | Output is correct |
45 | Correct | 679 ms | 1628288 KB | Output is correct |
46 | Correct | 743 ms | 1696856 KB | Output is correct |
47 | Correct | 668 ms | 1678928 KB | Output is correct |
48 | Correct | 757 ms | 1865300 KB | Output is correct |
49 | Correct | 619 ms | 1627984 KB | Output is correct |
50 | Correct | 616 ms | 1626392 KB | Output is correct |
51 | Correct | 718 ms | 1677368 KB | Output is correct |
52 | Correct | 462 ms | 1203792 KB | Output is correct |
53 | Correct | 463 ms | 1203792 KB | Output is correct |
54 | Correct | 471 ms | 1204808 KB | Output is correct |
55 | Correct | 463 ms | 1205588 KB | Output is correct |
56 | Correct | 487 ms | 1204240 KB | Output is correct |
57 | Correct | 428 ms | 1204560 KB | Output is correct |
58 | Correct | 442 ms | 1204820 KB | Output is correct |
59 | Correct | 438 ms | 1204860 KB | Output is correct |
60 | Correct | 449 ms | 1204564 KB | Output is correct |
61 | Correct | 444 ms | 1204672 KB | Output is correct |
62 | Runtime error | 1206 ms | 2097152 KB | Execution killed with signal 9 |
63 | Halted | 0 ms | 0 KB | - |