답안 #286518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
286518 2020-08-30T13:59:16 Z gs18115 Shopping Plans (CCO20_day2problem3) C++14
15 / 25
256 ms 32752 KB
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
struct type
{
    int x,y;
    int sz;
    vector<int>lst;
    int fdif;
    type(){}
};
struct node
{
    ll val;
    int ci,cn;
    int ith,pos,mx;
    bool fi;
    node(ll val,int ci,int cn,int ith,int pos,int mx,bool fi=0):
    val(val),ci(ci),cn(cn),ith(ith),pos(pos),mx(mx),fi(fi){}
    bool operator<(const node&x)const
    {
        return val==x.val?fi&&!x.fi:val>x.val;
    }
};
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m,k;
    cin>>n>>m>>k;
    vector<vector<int> >vv(m);
    for(int i=0;i<n;i++)
    {
        int a,c;
        cin>>a>>c;
        vv[a-1].eb(c);
    }
    vector<type>tpv;
    ll fi=0;
    for(auto&v:vv)
    {
        int x,y;
        cin>>x>>y;
        sort(all(v));
        y=min(y,(int)v.size());
        if(x>y)
        {
            for(int i=0;i<k;i++)
                cout<<"-1\n";
            return 0;
        }
        for(int i=0;i<x;i++)
            fi+=v[i];
        if((int)v.size()>x)
        {
            tpv.eb(type());
            if(x==0)
                tpv.back().fdif=v[0];
            else
                tpv.back().fdif=v[x]-v[x-1];
            tpv.back().x=x,tpv.back().y=y;
            tpv.back().lst=v;
            tpv.back().sz=v.size();
        }
    }
    sort(all(tpv),[](const type&x,const type&y){return x.fdif<y.fdif;});
    vector<ll>ansv;
    ansv.eb(fi);
    priority_queue<node>pq;
    if(!tpv.empty())
    {
        if(tpv[0].x==0)
            pq.ep(fi+tpv[0].fdif,0,0,-1,-1,-1,1);
        else
            pq.ep(fi+tpv[0].fdif,0,tpv[0].x,tpv[0].x-1,tpv[0].x-1,tpv[0].sz-1,1);
    }
    int tps=tpv.size();
    while(!pq.empty()&&(int)ansv.size()<k)
    {
        node cur=pq.top();
        pq.pop();
        const type&tp=tpv[cur.ci];
        if(cur.first)
            cur.val-=tp.fdif;
        else
            ansv.eb(cur.val);
        if(cur.ith>0&&cur.pos>cur.ith)
            pq.ep(cur.val-tp.lst[cur.ith-1]+tp.lst[cur.ith],cur.ci,cur.cn,cur.ith-1,cur.ith,cur.pos-1);
        if(cur.pos<cur.mx)
            pq.ep(cur.val-tp.lst[cur.pos]+tp.lst[cur.pos+1],cur.ci,cur.cn,cur.ith,cur.pos+1,cur.mx);
        if(cur.ith==cur.cn-1&&cur.pos==cur.cn-1&&cur.cn<tp.y)
            pq.ep(cur.val+tp.lst[cur.cn],cur.ci,cur.cn+1,cur.cn,cur.cn,cur.mx);
        if(cur.ci+1<tps)
        {
            const type&ntp=tpv[cur.ci+1];
            if(ntp.x==0)
                pq.ep(cur.val+ntp.fdif,cur.ci+1,0,-1,-1,-1,1);
            else
                pq.ep(cur.val+ntp.fdif,cur.ci+1,ntp.x,ntp.x-1,ntp.x-1,ntp.sz-1,1);
        }
    }
    while((int)ansv.size()<k)
        ansv.eb(-1);
    for(ll&t:ansv)
        cout<<t<<'\n';
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:16:8: warning: '<anonymous>.type::x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   16 | struct type
      |        ^~~~
Main.cpp:16:8: warning: '<anonymous>.type::y' may be used uninitialized in this function [-Wmaybe-uninitialized]
Main.cpp:16:8: warning: '<anonymous>.type::sz' may be used uninitialized in this function [-Wmaybe-uninitialized]
Main.cpp:16:8: warning: '<anonymous>.type::fdif' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1024 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 4 ms 928 KB Output is correct
4 Correct 3 ms 892 KB Output is correct
5 Correct 4 ms 896 KB Output is correct
6 Correct 4 ms 1024 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 4 ms 896 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 956 KB Output is correct
14 Correct 4 ms 896 KB Output is correct
15 Correct 2 ms 768 KB Output is correct
16 Correct 2 ms 832 KB Output is correct
17 Correct 3 ms 892 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 832 KB Output is correct
20 Correct 4 ms 1056 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 2 ms 768 KB Output is correct
23 Correct 3 ms 768 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 4 ms 896 KB Output is correct
27 Correct 3 ms 768 KB Output is correct
28 Correct 3 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 20340 KB Output is correct
2 Correct 124 ms 20048 KB Output is correct
3 Correct 121 ms 20176 KB Output is correct
4 Correct 118 ms 20176 KB Output is correct
5 Correct 114 ms 13684 KB Output is correct
6 Correct 110 ms 13392 KB Output is correct
7 Correct 120 ms 20048 KB Output is correct
8 Correct 96 ms 20304 KB Output is correct
9 Correct 19 ms 2676 KB Output is correct
10 Correct 120 ms 20232 KB Output is correct
11 Correct 8 ms 1024 KB Output is correct
12 Correct 43 ms 3628 KB Output is correct
13 Correct 121 ms 20268 KB Output is correct
14 Correct 123 ms 20176 KB Output is correct
15 Correct 18 ms 2796 KB Output is correct
16 Correct 119 ms 20248 KB Output is correct
17 Correct 119 ms 20048 KB Output is correct
18 Correct 35 ms 3180 KB Output is correct
19 Correct 126 ms 20372 KB Output is correct
20 Correct 118 ms 20596 KB Output is correct
21 Correct 20 ms 2672 KB Output is correct
22 Correct 109 ms 12180 KB Output is correct
23 Correct 104 ms 20052 KB Output is correct
24 Correct 8 ms 1152 KB Output is correct
25 Correct 8 ms 1152 KB Output is correct
26 Correct 108 ms 12116 KB Output is correct
27 Correct 106 ms 12144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1024 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 4 ms 928 KB Output is correct
4 Correct 3 ms 892 KB Output is correct
5 Correct 4 ms 896 KB Output is correct
6 Correct 4 ms 1024 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 4 ms 896 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 956 KB Output is correct
14 Correct 4 ms 896 KB Output is correct
15 Correct 2 ms 768 KB Output is correct
16 Correct 2 ms 832 KB Output is correct
17 Correct 3 ms 892 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 832 KB Output is correct
20 Correct 4 ms 1056 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 2 ms 768 KB Output is correct
23 Correct 3 ms 768 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 4 ms 896 KB Output is correct
27 Correct 3 ms 768 KB Output is correct
28 Correct 3 ms 768 KB Output is correct
29 Correct 121 ms 20340 KB Output is correct
30 Correct 124 ms 20048 KB Output is correct
31 Correct 121 ms 20176 KB Output is correct
32 Correct 118 ms 20176 KB Output is correct
33 Correct 114 ms 13684 KB Output is correct
34 Correct 110 ms 13392 KB Output is correct
35 Correct 120 ms 20048 KB Output is correct
36 Correct 96 ms 20304 KB Output is correct
37 Correct 19 ms 2676 KB Output is correct
38 Correct 120 ms 20232 KB Output is correct
39 Correct 8 ms 1024 KB Output is correct
40 Correct 43 ms 3628 KB Output is correct
41 Correct 121 ms 20268 KB Output is correct
42 Correct 123 ms 20176 KB Output is correct
43 Correct 18 ms 2796 KB Output is correct
44 Correct 119 ms 20248 KB Output is correct
45 Correct 119 ms 20048 KB Output is correct
46 Correct 35 ms 3180 KB Output is correct
47 Correct 126 ms 20372 KB Output is correct
48 Correct 118 ms 20596 KB Output is correct
49 Correct 20 ms 2672 KB Output is correct
50 Correct 109 ms 12180 KB Output is correct
51 Correct 104 ms 20052 KB Output is correct
52 Correct 8 ms 1152 KB Output is correct
53 Correct 8 ms 1152 KB Output is correct
54 Correct 108 ms 12116 KB Output is correct
55 Correct 106 ms 12144 KB Output is correct
56 Correct 251 ms 31548 KB Output is correct
57 Correct 238 ms 27804 KB Output is correct
58 Correct 243 ms 29740 KB Output is correct
59 Correct 219 ms 24316 KB Output is correct
60 Correct 248 ms 26772 KB Output is correct
61 Correct 247 ms 32752 KB Output is correct
62 Correct 215 ms 23444 KB Output is correct
63 Correct 182 ms 21596 KB Output is correct
64 Correct 82 ms 5608 KB Output is correct
65 Correct 244 ms 27796 KB Output is correct
66 Correct 77 ms 5624 KB Output is correct
67 Correct 91 ms 7780 KB Output is correct
68 Correct 135 ms 20108 KB Output is correct
69 Correct 252 ms 29604 KB Output is correct
70 Correct 22 ms 2924 KB Output is correct
71 Correct 135 ms 20020 KB Output is correct
72 Correct 222 ms 24224 KB Output is correct
73 Correct 19 ms 2672 KB Output is correct
74 Correct 121 ms 14628 KB Output is correct
75 Correct 256 ms 31772 KB Output is correct
76 Correct 18 ms 2676 KB Output is correct
77 Correct 107 ms 12820 KB Output is correct
78 Correct 163 ms 21860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 2684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1024 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 4 ms 928 KB Output is correct
4 Correct 3 ms 892 KB Output is correct
5 Correct 4 ms 896 KB Output is correct
6 Correct 4 ms 1024 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 4 ms 896 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 956 KB Output is correct
14 Correct 4 ms 896 KB Output is correct
15 Correct 2 ms 768 KB Output is correct
16 Correct 2 ms 832 KB Output is correct
17 Correct 3 ms 892 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 832 KB Output is correct
20 Correct 4 ms 1056 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 2 ms 768 KB Output is correct
23 Correct 3 ms 768 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 4 ms 896 KB Output is correct
27 Correct 3 ms 768 KB Output is correct
28 Correct 3 ms 768 KB Output is correct
29 Correct 121 ms 20340 KB Output is correct
30 Correct 124 ms 20048 KB Output is correct
31 Correct 121 ms 20176 KB Output is correct
32 Correct 118 ms 20176 KB Output is correct
33 Correct 114 ms 13684 KB Output is correct
34 Correct 110 ms 13392 KB Output is correct
35 Correct 120 ms 20048 KB Output is correct
36 Correct 96 ms 20304 KB Output is correct
37 Correct 19 ms 2676 KB Output is correct
38 Correct 120 ms 20232 KB Output is correct
39 Correct 8 ms 1024 KB Output is correct
40 Correct 43 ms 3628 KB Output is correct
41 Correct 121 ms 20268 KB Output is correct
42 Correct 123 ms 20176 KB Output is correct
43 Correct 18 ms 2796 KB Output is correct
44 Correct 119 ms 20248 KB Output is correct
45 Correct 119 ms 20048 KB Output is correct
46 Correct 35 ms 3180 KB Output is correct
47 Correct 126 ms 20372 KB Output is correct
48 Correct 118 ms 20596 KB Output is correct
49 Correct 20 ms 2672 KB Output is correct
50 Correct 109 ms 12180 KB Output is correct
51 Correct 104 ms 20052 KB Output is correct
52 Correct 8 ms 1152 KB Output is correct
53 Correct 8 ms 1152 KB Output is correct
54 Correct 108 ms 12116 KB Output is correct
55 Correct 106 ms 12144 KB Output is correct
56 Correct 251 ms 31548 KB Output is correct
57 Correct 238 ms 27804 KB Output is correct
58 Correct 243 ms 29740 KB Output is correct
59 Correct 219 ms 24316 KB Output is correct
60 Correct 248 ms 26772 KB Output is correct
61 Correct 247 ms 32752 KB Output is correct
62 Correct 215 ms 23444 KB Output is correct
63 Correct 182 ms 21596 KB Output is correct
64 Correct 82 ms 5608 KB Output is correct
65 Correct 244 ms 27796 KB Output is correct
66 Correct 77 ms 5624 KB Output is correct
67 Correct 91 ms 7780 KB Output is correct
68 Correct 135 ms 20108 KB Output is correct
69 Correct 252 ms 29604 KB Output is correct
70 Correct 22 ms 2924 KB Output is correct
71 Correct 135 ms 20020 KB Output is correct
72 Correct 222 ms 24224 KB Output is correct
73 Correct 19 ms 2672 KB Output is correct
74 Correct 121 ms 14628 KB Output is correct
75 Correct 256 ms 31772 KB Output is correct
76 Correct 18 ms 2676 KB Output is correct
77 Correct 107 ms 12820 KB Output is correct
78 Correct 163 ms 21860 KB Output is correct
79 Incorrect 17 ms 2684 KB Output isn't correct
80 Halted 0 ms 0 KB -