Submission #1089890

# Submission time Handle Problem Language Result Execution time Memory
1089890 2024-09-17T11:18:14 Z KALARRY Tricks of the Trade (CEOI23_trade) C++14
30 / 100
3005 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)
            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);
    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

trade.cpp: In function 'int main()':
trade.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf("%lld%lld",&N,&K);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
trade.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         scanf("%lld",&a[i]);
      |         ~~~~~^~~~~~~~~~~~~~
trade.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         scanf("%lld",&b[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 452 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 0 ms 860 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 3 ms 1884 KB Output is correct
9 Correct 2 ms 1624 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 452 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 0 ms 860 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 3 ms 1884 KB Output is correct
9 Correct 2 ms 1624 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1372 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 1884 KB Output is correct
16 Correct 3 ms 3016 KB Output is correct
17 Correct 1 ms 860 KB Output is correct
18 Correct 1 ms 1372 KB Output is correct
19 Correct 4 ms 1884 KB Output is correct
20 Correct 2 ms 1628 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1372 KB Output is correct
23 Correct 3005 ms 2005980 KB Output is correct
24 Correct 7 ms 12468 KB Output is correct
25 Correct 542 ms 343216 KB Output is correct
26 Correct 75 ms 45996 KB Output is correct
27 Correct 2593 ms 862256 KB Output is correct
28 Correct 7 ms 11448 KB Output is correct
29 Correct 1405 ms 1001544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 261 ms 465708 KB Output is correct
3 Correct 251 ms 467408 KB Output is correct
4 Correct 251 ms 467404 KB Output is correct
5 Correct 279 ms 486352 KB Output is correct
6 Correct 261 ms 468220 KB Output is correct
7 Correct 348 ms 654580 KB Output is correct
8 Correct 234 ms 467400 KB Output is correct
9 Correct 216 ms 465892 KB Output is correct
10 Correct 243 ms 466780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 261 ms 465708 KB Output is correct
3 Correct 251 ms 467408 KB Output is correct
4 Correct 251 ms 467404 KB Output is correct
5 Correct 279 ms 486352 KB Output is correct
6 Correct 261 ms 468220 KB Output is correct
7 Correct 348 ms 654580 KB Output is correct
8 Correct 234 ms 467400 KB Output is correct
9 Correct 216 ms 465892 KB Output is correct
10 Correct 243 ms 466780 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 231 ms 465524 KB Output is correct
13 Correct 224 ms 467404 KB Output is correct
14 Correct 231 ms 467408 KB Output is correct
15 Correct 274 ms 486356 KB Output is correct
16 Correct 243 ms 468260 KB Output is correct
17 Correct 350 ms 654540 KB Output is correct
18 Correct 241 ms 467404 KB Output is correct
19 Correct 248 ms 465864 KB Output is correct
20 Correct 255 ms 466632 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 2 ms 1884 KB Output is correct
24 Correct 3 ms 2908 KB Output is correct
25 Correct 1 ms 856 KB Output is correct
26 Correct 1 ms 1372 KB Output is correct
27 Correct 3 ms 1884 KB Output is correct
28 Correct 2 ms 1628 KB Output is correct
29 Correct 1 ms 1116 KB Output is correct
30 Correct 1 ms 1112 KB Output is correct
31 Runtime error 1257 ms 2097152 KB Execution killed with signal 9
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 452 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 0 ms 860 KB Output is correct
9 Correct 1 ms 1372 KB Output is correct
10 Correct 3 ms 1884 KB Output is correct
11 Correct 2 ms 1624 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 1884 KB Output is correct
18 Correct 3 ms 3016 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 1 ms 1372 KB Output is correct
21 Correct 4 ms 1884 KB Output is correct
22 Correct 2 ms 1628 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1372 KB Output is correct
25 Correct 3005 ms 2005980 KB Output is correct
26 Correct 7 ms 12468 KB Output is correct
27 Correct 542 ms 343216 KB Output is correct
28 Correct 75 ms 45996 KB Output is correct
29 Correct 2593 ms 862256 KB Output is correct
30 Correct 7 ms 11448 KB Output is correct
31 Correct 1405 ms 1001544 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 261 ms 465708 KB Output is correct
34 Correct 251 ms 467408 KB Output is correct
35 Correct 251 ms 467404 KB Output is correct
36 Correct 279 ms 486352 KB Output is correct
37 Correct 261 ms 468220 KB Output is correct
38 Correct 348 ms 654580 KB Output is correct
39 Correct 234 ms 467400 KB Output is correct
40 Correct 216 ms 465892 KB Output is correct
41 Correct 243 ms 466780 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 231 ms 465524 KB Output is correct
44 Correct 224 ms 467404 KB Output is correct
45 Correct 231 ms 467408 KB Output is correct
46 Correct 274 ms 486356 KB Output is correct
47 Correct 243 ms 468260 KB Output is correct
48 Correct 350 ms 654540 KB Output is correct
49 Correct 241 ms 467404 KB Output is correct
50 Correct 248 ms 465864 KB Output is correct
51 Correct 255 ms 466632 KB Output is correct
52 Correct 1 ms 344 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 2 ms 1884 KB Output is correct
55 Correct 3 ms 2908 KB Output is correct
56 Correct 1 ms 856 KB Output is correct
57 Correct 1 ms 1372 KB Output is correct
58 Correct 3 ms 1884 KB Output is correct
59 Correct 2 ms 1628 KB Output is correct
60 Correct 1 ms 1116 KB Output is correct
61 Correct 1 ms 1112 KB Output is correct
62 Runtime error 1257 ms 2097152 KB Execution killed with signal 9
63 Halted 0 ms 0 KB -