답안 #1089891

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

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]);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 2 ms 1884 KB Output is correct
5 Correct 3 ms 2908 KB Output is correct
6 Partially correct 1 ms 860 KB Partially correct
7 Partially correct 1 ms 1372 KB Partially correct
8 Partially correct 2 ms 1628 KB Partially correct
9 Partially correct 1 ms 1372 KB Partially correct
10 Correct 1 ms 1116 KB Output is correct
11 Partially correct 1 ms 1116 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 2 ms 1884 KB Output is correct
5 Correct 3 ms 2908 KB Output is correct
6 Partially correct 1 ms 860 KB Partially correct
7 Partially correct 1 ms 1372 KB Partially correct
8 Partially correct 2 ms 1628 KB Partially correct
9 Partially correct 1 ms 1372 KB Partially correct
10 Correct 1 ms 1116 KB Output is correct
11 Partially correct 1 ms 1116 KB Partially correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 452 KB Output is correct
15 Correct 2 ms 1884 KB Output is correct
16 Correct 3 ms 2908 KB Output is correct
17 Partially correct 1 ms 604 KB Partially correct
18 Partially correct 1 ms 1372 KB Partially correct
19 Partially correct 2 ms 1628 KB Partially correct
20 Partially correct 1 ms 1480 KB Partially correct
21 Correct 1 ms 1116 KB Output is correct
22 Partially correct 1 ms 1116 KB Partially correct
23 Correct 2601 ms 2001504 KB Output is correct
24 Partially correct 7 ms 11960 KB Partially correct
25 Partially correct 445 ms 340440 KB Partially correct
26 Partially correct 52 ms 43688 KB Partially correct
27 Partially correct 1519 ms 859056 KB Partially correct
28 Correct 6 ms 11444 KB Output is correct
29 Correct 1327 ms 999400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 265 ms 465612 KB Output is correct
3 Correct 249 ms 467072 KB Output is correct
4 Correct 251 ms 467148 KB Output is correct
5 Partially correct 250 ms 467144 KB Partially correct
6 Partially correct 253 ms 466940 KB Partially correct
7 Partially correct 239 ms 466380 KB Partially correct
8 Correct 254 ms 466892 KB Output is correct
9 Correct 262 ms 465960 KB Output is correct
10 Correct 247 ms 466628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 265 ms 465612 KB Output is correct
3 Correct 249 ms 467072 KB Output is correct
4 Correct 251 ms 467148 KB Output is correct
5 Partially correct 250 ms 467144 KB Partially correct
6 Partially correct 253 ms 466940 KB Partially correct
7 Partially correct 239 ms 466380 KB Partially correct
8 Correct 254 ms 466892 KB Output is correct
9 Correct 262 ms 465960 KB Output is correct
10 Correct 247 ms 466628 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 253 ms 465596 KB Output is correct
13 Correct 269 ms 467404 KB Output is correct
14 Correct 224 ms 467356 KB Output is correct
15 Partially correct 229 ms 467384 KB Partially correct
16 Partially correct 241 ms 467120 KB Partially correct
17 Partially correct 224 ms 466636 KB Partially correct
18 Correct 233 ms 467396 KB Output is correct
19 Correct 217 ms 465960 KB Output is correct
20 Correct 229 ms 466632 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 1924 KB Output is correct
24 Correct 3 ms 2908 KB Output is correct
25 Partially correct 1 ms 856 KB Partially correct
26 Partially correct 1 ms 1116 KB Partially correct
27 Partially correct 2 ms 1628 KB Partially correct
28 Partially correct 1 ms 1372 KB Partially correct
29 Correct 1 ms 1116 KB Output is correct
30 Partially correct 1 ms 1116 KB Partially correct
31 Runtime error 1259 ms 2097152 KB Execution killed with signal 9
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
6 Correct 2 ms 1884 KB Output is correct
7 Correct 3 ms 2908 KB Output is correct
8 Partially correct 1 ms 860 KB Partially correct
9 Partially correct 1 ms 1372 KB Partially correct
10 Partially correct 2 ms 1628 KB Partially correct
11 Partially correct 1 ms 1372 KB Partially correct
12 Correct 1 ms 1116 KB Output is correct
13 Partially correct 1 ms 1116 KB Partially correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 452 KB Output is correct
17 Correct 2 ms 1884 KB Output is correct
18 Correct 3 ms 2908 KB Output is correct
19 Partially correct 1 ms 604 KB Partially correct
20 Partially correct 1 ms 1372 KB Partially correct
21 Partially correct 2 ms 1628 KB Partially correct
22 Partially correct 1 ms 1480 KB Partially correct
23 Correct 1 ms 1116 KB Output is correct
24 Partially correct 1 ms 1116 KB Partially correct
25 Correct 2601 ms 2001504 KB Output is correct
26 Partially correct 7 ms 11960 KB Partially correct
27 Partially correct 445 ms 340440 KB Partially correct
28 Partially correct 52 ms 43688 KB Partially correct
29 Partially correct 1519 ms 859056 KB Partially correct
30 Correct 6 ms 11444 KB Output is correct
31 Correct 1327 ms 999400 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 265 ms 465612 KB Output is correct
34 Correct 249 ms 467072 KB Output is correct
35 Correct 251 ms 467148 KB Output is correct
36 Partially correct 250 ms 467144 KB Partially correct
37 Partially correct 253 ms 466940 KB Partially correct
38 Partially correct 239 ms 466380 KB Partially correct
39 Correct 254 ms 466892 KB Output is correct
40 Correct 262 ms 465960 KB Output is correct
41 Correct 247 ms 466628 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 253 ms 465596 KB Output is correct
44 Correct 269 ms 467404 KB Output is correct
45 Correct 224 ms 467356 KB Output is correct
46 Partially correct 229 ms 467384 KB Partially correct
47 Partially correct 241 ms 467120 KB Partially correct
48 Partially correct 224 ms 466636 KB Partially correct
49 Correct 233 ms 467396 KB Output is correct
50 Correct 217 ms 465960 KB Output is correct
51 Correct 229 ms 466632 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 1924 KB Output is correct
55 Correct 3 ms 2908 KB Output is correct
56 Partially correct 1 ms 856 KB Partially correct
57 Partially correct 1 ms 1116 KB Partially correct
58 Partially correct 2 ms 1628 KB Partially correct
59 Partially correct 1 ms 1372 KB Partially correct
60 Correct 1 ms 1116 KB Output is correct
61 Partially correct 1 ms 1116 KB Partially correct
62 Runtime error 1259 ms 2097152 KB Execution killed with signal 9
63 Halted 0 ms 0 KB -