Submission #1040754

# Submission time Handle Problem Language Result Execution time Memory
1040754 2024-08-01T08:56:27 Z 정희우(#10998) Tricks of the Trade (CEOI23_trade) C++17
10 / 100
8000 ms 3464 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;
using lint = long long;
using intp = pair<int,int>;
using vint = vector<int>;

const int MAX_N=250010;
const int MAX_K=210;
const lint INF=1e+9*MAX_N;

int n,k;
int c[MAX_N],p[MAX_N];
priority_queue<int,vint,greater<int>> pq;
lint lv[MAX_K],rv[MAX_K];
lint ans;
int check[MAX_K];
int possi[MAX_N];

void calc(int s,int e)
{
    if(e-s<k)return;
    int m=(s+e)>>1;
    fill(lv,lv+MAX_K,-INF);
    fill(rv,rv+MAX_K,-INF);
    lv[0]=rv[0]=0;
    for(int i=1;i<=k;i++)
    {
        lint cnt=0;
        for(int j=m-1;j>=s;j--)
        {
            cnt+=p[j]-c[j];
            pq.push(p[j]);
            while(!pq.empty() && pq.size()>i)
            {
                cnt-=pq.top();
                pq.pop();
            }
            if(!pq.empty() && pq.size()==i)
                lv[i]=max(lv[i],cnt);
        }
        while(!pq.empty())pq.pop();
        cnt=0;
        for(int j=m;j<e;j++)
        {
            cnt+=p[j]-c[j];
            pq.push(p[j]);
            while(!pq.empty() && pq.size()>i)
            {
                cnt-=pq.top();
                pq.pop();
            }
            if(!pq.empty() && pq.size()==i)
                rv[i]=max(rv[i],cnt);
        }
        while(!pq.empty())pq.pop();
    }
    for(int i=0;i<=k;i++)
        ans=max(ans,lv[i]+rv[k-i]);
    calc(s,m);
    calc(m,e);
}

void bt(int s,int e)
{
    if(e-s<k)return;
    int m=(s+e)>>1;
    fill(lv,lv+MAX_K,-INF);
    fill(rv,rv+MAX_K,-INF);
    lv[0]=rv[0]=0;
    for(int i=1;i<=k;i++)
    {
        lint cnt=0;
        for(int j=m-1;j>=s;j--)
        {
            cnt+=p[j]-c[j];
            pq.push(p[j]);
            while(!pq.empty() && pq.size()>i)
            {
                cnt-=pq.top();
                pq.pop();
            }
            if(!pq.empty() && pq.size()==i)
                lv[i]=max(lv[i],cnt);
        }
        while(!pq.empty())pq.pop();
        cnt=0;
        for(int j=m;j<e;j++)
        {
            cnt+=p[j]-c[j];
            pq.push(p[j]);
            while(!pq.empty() && pq.size()>i)
            {
                cnt-=pq.top();
                pq.pop();
            }
            if(!pq.empty() && pq.size()==i)
                rv[i]=max(rv[i],cnt);
        }
        while(!pq.empty())pq.pop();
    }
    fill(check,check+MAX_K,0);
    for(int i=0;i<=k;i++)
        if(lv[i]+rv[k-i]==ans)check[i]=1;
}

int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n >> k;
    for(int i=0;i<n;i++)
        cin >> c[i];
    for(int i=0;i<n;i++)
        cin >> p[i];
    ans=-INF;
    calc(0,n);
    cout << ans << '\n';
    for(int i=0;i<n;i++)
        cout << possi[i];
    return 0;
}

Compilation message

trade.cpp: In function 'void calc(int, int)':
trade.cpp:37:43: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |             while(!pq.empty() && pq.size()>i)
      |                                  ~~~~~~~~~^~
trade.cpp:42:40: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |             if(!pq.empty() && pq.size()==i)
      |                               ~~~~~~~~~^~~
trade.cpp:51:43: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   51 |             while(!pq.empty() && pq.size()>i)
      |                                  ~~~~~~~~~^~
trade.cpp:56:40: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   56 |             if(!pq.empty() && pq.size()==i)
      |                               ~~~~~~~~~^~~
trade.cpp: In function 'void bt(int, int)':
trade.cpp:81:43: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   81 |             while(!pq.empty() && pq.size()>i)
      |                                  ~~~~~~~~~^~
trade.cpp:86:40: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   86 |             if(!pq.empty() && pq.size()==i)
      |                               ~~~~~~~~~^~~
trade.cpp:95:43: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   95 |             while(!pq.empty() && pq.size()>i)
      |                                  ~~~~~~~~~^~
trade.cpp:100:40: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  100 |             if(!pq.empty() && pq.size()==i)
      |                               ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2392 KB Partially correct
2 Partially correct 1 ms 2392 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2396 KB Partially correct
2 Partially correct 0 ms 2396 KB Partially correct
3 Partially correct 0 ms 2396 KB Partially correct
4 Partially correct 1 ms 2396 KB Partially correct
5 Partially correct 1 ms 2396 KB Partially correct
6 Partially correct 1 ms 2396 KB Partially correct
7 Partially correct 1 ms 2396 KB Partially correct
8 Partially correct 1 ms 2396 KB Partially correct
9 Partially correct 1 ms 2396 KB Partially correct
10 Partially correct 1 ms 2396 KB Partially correct
11 Partially correct 1 ms 2396 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2396 KB Partially correct
2 Partially correct 0 ms 2396 KB Partially correct
3 Partially correct 0 ms 2396 KB Partially correct
4 Partially correct 1 ms 2396 KB Partially correct
5 Partially correct 1 ms 2396 KB Partially correct
6 Partially correct 1 ms 2396 KB Partially correct
7 Partially correct 1 ms 2396 KB Partially correct
8 Partially correct 1 ms 2396 KB Partially correct
9 Partially correct 1 ms 2396 KB Partially correct
10 Partially correct 1 ms 2396 KB Partially correct
11 Partially correct 1 ms 2396 KB Partially correct
12 Partially correct 1 ms 2396 KB Partially correct
13 Partially correct 0 ms 2396 KB Partially correct
14 Partially correct 0 ms 2396 KB Partially correct
15 Partially correct 2 ms 2648 KB Partially correct
16 Partially correct 1 ms 2396 KB Partially correct
17 Partially correct 0 ms 2396 KB Partially correct
18 Partially correct 1 ms 2396 KB Partially correct
19 Partially correct 1 ms 2396 KB Partially correct
20 Partially correct 1 ms 2396 KB Partially correct
21 Partially correct 1 ms 2396 KB Partially correct
22 Partially correct 1 ms 2396 KB Partially correct
23 Incorrect 1815 ms 2752 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2392 KB Partially correct
2 Partially correct 126 ms 3220 KB Partially correct
3 Partially correct 142 ms 3412 KB Partially correct
4 Partially correct 140 ms 3456 KB Partially correct
5 Partially correct 132 ms 3412 KB Partially correct
6 Partially correct 148 ms 3456 KB Partially correct
7 Partially correct 142 ms 3416 KB Partially correct
8 Partially correct 137 ms 3408 KB Partially correct
9 Partially correct 138 ms 3464 KB Partially correct
10 Partially correct 129 ms 3408 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2392 KB Partially correct
2 Partially correct 126 ms 3220 KB Partially correct
3 Partially correct 142 ms 3412 KB Partially correct
4 Partially correct 140 ms 3456 KB Partially correct
5 Partially correct 132 ms 3412 KB Partially correct
6 Partially correct 148 ms 3456 KB Partially correct
7 Partially correct 142 ms 3416 KB Partially correct
8 Partially correct 137 ms 3408 KB Partially correct
9 Partially correct 138 ms 3464 KB Partially correct
10 Partially correct 129 ms 3408 KB Partially correct
11 Partially correct 1 ms 2392 KB Partially correct
12 Partially correct 132 ms 3220 KB Partially correct
13 Partially correct 142 ms 3456 KB Partially correct
14 Partially correct 135 ms 3412 KB Partially correct
15 Partially correct 127 ms 3412 KB Partially correct
16 Partially correct 128 ms 3412 KB Partially correct
17 Partially correct 144 ms 3460 KB Partially correct
18 Partially correct 135 ms 3408 KB Partially correct
19 Partially correct 132 ms 3412 KB Partially correct
20 Partially correct 130 ms 3412 KB Partially correct
21 Partially correct 1 ms 2396 KB Partially correct
22 Partially correct 0 ms 2396 KB Partially correct
23 Partially correct 1 ms 2396 KB Partially correct
24 Partially correct 1 ms 2396 KB Partially correct
25 Partially correct 0 ms 2396 KB Partially correct
26 Partially correct 1 ms 2396 KB Partially correct
27 Partially correct 1 ms 2396 KB Partially correct
28 Partially correct 1 ms 2396 KB Partially correct
29 Partially correct 1 ms 2396 KB Partially correct
30 Partially correct 1 ms 2396 KB Partially correct
31 Execution timed out 8099 ms 3196 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2392 KB Partially correct
2 Partially correct 1 ms 2392 KB Partially correct
3 Partially correct 1 ms 2396 KB Partially correct
4 Partially correct 0 ms 2396 KB Partially correct
5 Partially correct 0 ms 2396 KB Partially correct
6 Partially correct 1 ms 2396 KB Partially correct
7 Partially correct 1 ms 2396 KB Partially correct
8 Partially correct 1 ms 2396 KB Partially correct
9 Partially correct 1 ms 2396 KB Partially correct
10 Partially correct 1 ms 2396 KB Partially correct
11 Partially correct 1 ms 2396 KB Partially correct
12 Partially correct 1 ms 2396 KB Partially correct
13 Partially correct 1 ms 2396 KB Partially correct
14 Partially correct 1 ms 2396 KB Partially correct
15 Partially correct 0 ms 2396 KB Partially correct
16 Partially correct 0 ms 2396 KB Partially correct
17 Partially correct 2 ms 2648 KB Partially correct
18 Partially correct 1 ms 2396 KB Partially correct
19 Partially correct 0 ms 2396 KB Partially correct
20 Partially correct 1 ms 2396 KB Partially correct
21 Partially correct 1 ms 2396 KB Partially correct
22 Partially correct 1 ms 2396 KB Partially correct
23 Partially correct 1 ms 2396 KB Partially correct
24 Partially correct 1 ms 2396 KB Partially correct
25 Incorrect 1815 ms 2752 KB Output isn't correct
26 Halted 0 ms 0 KB -