답안 #1089881

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089881 2024-09-17T11:04:21 Z KALARRY Tricks of the Trade (CEOI23_trade) C++14
25 / 100
1566 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;
        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

trade.cpp: In function 'int main()':
trade.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%lld%lld",&N,&K);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
trade.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         scanf("%lld",&a[i]);
      |         ~~~~~^~~~~~~~~~~~~~
trade.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         scanf("%lld",&b[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 480 ms 1203792 KB Output is correct
2 Correct 472 ms 1203792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 452 ms 1204092 KB Output is correct
2 Correct 500 ms 1203840 KB Output is correct
3 Correct 477 ms 1203952 KB Output is correct
4 Correct 446 ms 1204880 KB Output is correct
5 Correct 424 ms 1205748 KB Output is correct
6 Correct 421 ms 1204308 KB Output is correct
7 Correct 439 ms 1204692 KB Output is correct
8 Correct 443 ms 1204816 KB Output is correct
9 Correct 438 ms 1204724 KB Output is correct
10 Correct 440 ms 1204560 KB Output is correct
11 Correct 466 ms 1204508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 452 ms 1204092 KB Output is correct
2 Correct 500 ms 1203840 KB Output is correct
3 Correct 477 ms 1203952 KB Output is correct
4 Correct 446 ms 1204880 KB Output is correct
5 Correct 424 ms 1205748 KB Output is correct
6 Correct 421 ms 1204308 KB Output is correct
7 Correct 439 ms 1204692 KB Output is correct
8 Correct 443 ms 1204816 KB Output is correct
9 Correct 438 ms 1204724 KB Output is correct
10 Correct 440 ms 1204560 KB Output is correct
11 Correct 466 ms 1204508 KB Output is correct
12 Correct 514 ms 1203796 KB Output is correct
13 Correct 468 ms 1203964 KB Output is correct
14 Correct 472 ms 1203792 KB Output is correct
15 Correct 475 ms 1204820 KB Output is correct
16 Correct 481 ms 1205584 KB Output is correct
17 Correct 479 ms 1204308 KB Output is correct
18 Correct 472 ms 1204560 KB Output is correct
19 Correct 491 ms 1204816 KB Output is correct
20 Correct 481 ms 1204852 KB Output is correct
21 Correct 482 ms 1204576 KB Output is correct
22 Correct 469 ms 1204564 KB Output is correct
23 Partially correct 1439 ms 1551104 KB Partially correct
24 Correct 472 ms 1216008 KB Output is correct
25 Partially correct 1004 ms 1309008 KB Partially correct
26 Correct 487 ms 1236052 KB Output is correct
27 Partially correct 1566 ms 1484624 KB Partially correct
28 Correct 428 ms 1214032 KB Output is correct
29 Partially correct 1368 ms 1390164 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Correct 659 ms 1203768 KB Output is correct
2 Correct 745 ms 1676120 KB Output is correct
3 Correct 669 ms 1627888 KB Output is correct
4 Correct 682 ms 1627984 KB Output is correct
5 Correct 812 ms 1697044 KB Output is correct
6 Correct 733 ms 1678896 KB Output is correct
7 Correct 825 ms 1865240 KB Output is correct
8 Correct 650 ms 1627996 KB Output is correct
9 Correct 704 ms 1626256 KB Output is correct
10 Correct 665 ms 1677304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 659 ms 1203768 KB Output is correct
2 Correct 745 ms 1676120 KB Output is correct
3 Correct 669 ms 1627888 KB Output is correct
4 Correct 682 ms 1627984 KB Output is correct
5 Correct 812 ms 1697044 KB Output is correct
6 Correct 733 ms 1678896 KB Output is correct
7 Correct 825 ms 1865240 KB Output is correct
8 Correct 650 ms 1627996 KB Output is correct
9 Correct 704 ms 1626256 KB Output is correct
10 Correct 665 ms 1677304 KB Output is correct
11 Correct 422 ms 1203792 KB Output is correct
12 Correct 674 ms 1676452 KB Output is correct
13 Correct 627 ms 1627876 KB Output is correct
14 Correct 673 ms 1627984 KB Output is correct
15 Correct 750 ms 1696860 KB Output is correct
16 Correct 753 ms 1678888 KB Output is correct
17 Correct 807 ms 1865296 KB Output is correct
18 Correct 692 ms 1627944 KB Output is correct
19 Correct 689 ms 1626396 KB Output is correct
20 Correct 770 ms 1677208 KB Output is correct
21 Correct 482 ms 1203880 KB Output is correct
22 Correct 490 ms 1203796 KB Output is correct
23 Correct 504 ms 1204824 KB Output is correct
24 Correct 480 ms 1205584 KB Output is correct
25 Correct 459 ms 1204304 KB Output is correct
26 Correct 497 ms 1204520 KB Output is correct
27 Correct 487 ms 1204872 KB Output is correct
28 Correct 436 ms 1204816 KB Output is correct
29 Correct 430 ms 1204564 KB Output is correct
30 Correct 437 ms 1204560 KB Output is correct
31 Runtime error 1133 ms 2097152 KB Execution killed with signal 9
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 480 ms 1203792 KB Output is correct
2 Correct 472 ms 1203792 KB Output is correct
3 Correct 452 ms 1204092 KB Output is correct
4 Correct 500 ms 1203840 KB Output is correct
5 Correct 477 ms 1203952 KB Output is correct
6 Correct 446 ms 1204880 KB Output is correct
7 Correct 424 ms 1205748 KB Output is correct
8 Correct 421 ms 1204308 KB Output is correct
9 Correct 439 ms 1204692 KB Output is correct
10 Correct 443 ms 1204816 KB Output is correct
11 Correct 438 ms 1204724 KB Output is correct
12 Correct 440 ms 1204560 KB Output is correct
13 Correct 466 ms 1204508 KB Output is correct
14 Correct 514 ms 1203796 KB Output is correct
15 Correct 468 ms 1203964 KB Output is correct
16 Correct 472 ms 1203792 KB Output is correct
17 Correct 475 ms 1204820 KB Output is correct
18 Correct 481 ms 1205584 KB Output is correct
19 Correct 479 ms 1204308 KB Output is correct
20 Correct 472 ms 1204560 KB Output is correct
21 Correct 491 ms 1204816 KB Output is correct
22 Correct 481 ms 1204852 KB Output is correct
23 Correct 482 ms 1204576 KB Output is correct
24 Correct 469 ms 1204564 KB Output is correct
25 Partially correct 1439 ms 1551104 KB Partially correct
26 Correct 472 ms 1216008 KB Output is correct
27 Partially correct 1004 ms 1309008 KB Partially correct
28 Correct 487 ms 1236052 KB Output is correct
29 Partially correct 1566 ms 1484624 KB Partially correct
30 Correct 428 ms 1214032 KB Output is correct
31 Partially correct 1368 ms 1390164 KB Partially correct
32 Correct 659 ms 1203768 KB Output is correct
33 Correct 745 ms 1676120 KB Output is correct
34 Correct 669 ms 1627888 KB Output is correct
35 Correct 682 ms 1627984 KB Output is correct
36 Correct 812 ms 1697044 KB Output is correct
37 Correct 733 ms 1678896 KB Output is correct
38 Correct 825 ms 1865240 KB Output is correct
39 Correct 650 ms 1627996 KB Output is correct
40 Correct 704 ms 1626256 KB Output is correct
41 Correct 665 ms 1677304 KB Output is correct
42 Correct 422 ms 1203792 KB Output is correct
43 Correct 674 ms 1676452 KB Output is correct
44 Correct 627 ms 1627876 KB Output is correct
45 Correct 673 ms 1627984 KB Output is correct
46 Correct 750 ms 1696860 KB Output is correct
47 Correct 753 ms 1678888 KB Output is correct
48 Correct 807 ms 1865296 KB Output is correct
49 Correct 692 ms 1627944 KB Output is correct
50 Correct 689 ms 1626396 KB Output is correct
51 Correct 770 ms 1677208 KB Output is correct
52 Correct 482 ms 1203880 KB Output is correct
53 Correct 490 ms 1203796 KB Output is correct
54 Correct 504 ms 1204824 KB Output is correct
55 Correct 480 ms 1205584 KB Output is correct
56 Correct 459 ms 1204304 KB Output is correct
57 Correct 497 ms 1204520 KB Output is correct
58 Correct 487 ms 1204872 KB Output is correct
59 Correct 436 ms 1204816 KB Output is correct
60 Correct 430 ms 1204564 KB Output is correct
61 Correct 437 ms 1204560 KB Output is correct
62 Runtime error 1133 ms 2097152 KB Execution killed with signal 9
63 Halted 0 ms 0 KB -