답안 #1089886

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089886 2024-09-17T11:11:30 Z KALARRY Tricks of the Trade (CEOI23_trade) C++14
25 / 100
2069 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;   
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);
    adj.resize(N+1);
    for(int i = 1 ; i <= N ; i++)
        adj[i].resize(K+1);
    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:44:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         scanf("%lld",&a[i]);
      |         ~~~~~^~~~~~~~~~~~~~
trade.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         scanf("%lld",&b[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 3164 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 1880 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 3164 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 1880 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 0 ms 348 KB Output is correct
14 Correct 0 ms 448 KB Output is correct
15 Correct 2 ms 1884 KB Output is correct
16 Correct 3 ms 3164 KB Output is correct
17 Correct 1 ms 860 KB Output is correct
18 Correct 1 ms 1372 KB Output is correct
19 Correct 2 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 2 ms 1372 KB Output is correct
23 Correct 2069 ms 2008728 KB Output is correct
24 Correct 8 ms 13328 KB Output is correct
25 Partially correct 508 ms 343160 KB Partially correct
26 Correct 75 ms 46764 KB Output is correct
27 Correct 1359 ms 861364 KB Output is correct
28 Correct 6 ms 11096 KB Output is correct
29 Correct 1238 ms 999504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 229 ms 498004 KB Output is correct
3 Correct 206 ms 449872 KB Output is correct
4 Correct 203 ms 449764 KB Output is correct
5 Correct 273 ms 518748 KB Output is correct
6 Correct 261 ms 500620 KB Output is correct
7 Correct 361 ms 687028 KB Output is correct
8 Correct 227 ms 449908 KB Output is correct
9 Correct 214 ms 448216 KB Output is correct
10 Correct 265 ms 499284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 229 ms 498004 KB Output is correct
3 Correct 206 ms 449872 KB Output is correct
4 Correct 203 ms 449764 KB Output is correct
5 Correct 273 ms 518748 KB Output is correct
6 Correct 261 ms 500620 KB Output is correct
7 Correct 361 ms 687028 KB Output is correct
8 Correct 227 ms 449908 KB Output is correct
9 Correct 214 ms 448216 KB Output is correct
10 Correct 265 ms 499284 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 248 ms 498136 KB Output is correct
13 Correct 222 ms 449888 KB Output is correct
14 Correct 220 ms 450132 KB Output is correct
15 Correct 283 ms 518920 KB Output is correct
16 Correct 269 ms 500816 KB Output is correct
17 Correct 355 ms 687184 KB Output is correct
18 Correct 233 ms 449876 KB Output is correct
19 Correct 232 ms 448180 KB Output is correct
20 Correct 244 ms 499284 KB Output is correct
21 Correct 0 ms 348 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 3160 KB Output is correct
25 Correct 1 ms 860 KB Output is correct
26 Correct 1 ms 1368 KB Output is correct
27 Correct 3 ms 1908 KB Output is correct
28 Correct 2 ms 1628 KB Output is correct
29 Correct 1 ms 1256 KB Output is correct
30 Correct 1 ms 1372 KB Output is correct
31 Runtime error 1128 ms 2097152 KB Execution killed with signal 9
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 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 3164 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 1880 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 0 ms 348 KB Output is correct
16 Correct 0 ms 448 KB Output is correct
17 Correct 2 ms 1884 KB Output is correct
18 Correct 3 ms 3164 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 1 ms 1372 KB Output is correct
21 Correct 2 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 2 ms 1372 KB Output is correct
25 Correct 2069 ms 2008728 KB Output is correct
26 Correct 8 ms 13328 KB Output is correct
27 Partially correct 508 ms 343160 KB Partially correct
28 Correct 75 ms 46764 KB Output is correct
29 Correct 1359 ms 861364 KB Output is correct
30 Correct 6 ms 11096 KB Output is correct
31 Correct 1238 ms 999504 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 229 ms 498004 KB Output is correct
34 Correct 206 ms 449872 KB Output is correct
35 Correct 203 ms 449764 KB Output is correct
36 Correct 273 ms 518748 KB Output is correct
37 Correct 261 ms 500620 KB Output is correct
38 Correct 361 ms 687028 KB Output is correct
39 Correct 227 ms 449908 KB Output is correct
40 Correct 214 ms 448216 KB Output is correct
41 Correct 265 ms 499284 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 248 ms 498136 KB Output is correct
44 Correct 222 ms 449888 KB Output is correct
45 Correct 220 ms 450132 KB Output is correct
46 Correct 283 ms 518920 KB Output is correct
47 Correct 269 ms 500816 KB Output is correct
48 Correct 355 ms 687184 KB Output is correct
49 Correct 233 ms 449876 KB Output is correct
50 Correct 232 ms 448180 KB Output is correct
51 Correct 244 ms 499284 KB Output is correct
52 Correct 0 ms 348 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 3160 KB Output is correct
56 Correct 1 ms 860 KB Output is correct
57 Correct 1 ms 1368 KB Output is correct
58 Correct 3 ms 1908 KB Output is correct
59 Correct 2 ms 1628 KB Output is correct
60 Correct 1 ms 1256 KB Output is correct
61 Correct 1 ms 1372 KB Output is correct
62 Runtime error 1128 ms 2097152 KB Execution killed with signal 9
63 Halted 0 ms 0 KB -