답안 #286522

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
286522 2020-08-30T14:00:48 Z gs18115 Shopping Plans (CCO20_day2problem3) C++14
25 / 25
377 ms 56960 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,tp.sz-1);
        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 896 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 4 ms 896 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 3 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 5 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 828 KB Output is correct
14 Correct 4 ms 896 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 2 ms 832 KB Output is correct
17 Correct 4 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 2 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 4 ms 896 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 4 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 20344 KB Output is correct
2 Correct 124 ms 20048 KB Output is correct
3 Correct 122 ms 20176 KB Output is correct
4 Correct 118 ms 20176 KB Output is correct
5 Correct 112 ms 13684 KB Output is correct
6 Correct 109 ms 13392 KB Output is correct
7 Correct 124 ms 20048 KB Output is correct
8 Correct 104 ms 20308 KB Output is correct
9 Correct 19 ms 2676 KB Output is correct
10 Correct 122 ms 20176 KB Output is correct
11 Correct 8 ms 1024 KB Output is correct
12 Correct 45 ms 3632 KB Output is correct
13 Correct 118 ms 20240 KB Output is correct
14 Correct 121 ms 20176 KB Output is correct
15 Correct 19 ms 2804 KB Output is correct
16 Correct 124 ms 20116 KB Output is correct
17 Correct 118 ms 20056 KB Output is correct
18 Correct 36 ms 3308 KB Output is correct
19 Correct 124 ms 20372 KB Output is correct
20 Correct 121 ms 20596 KB Output is correct
21 Correct 20 ms 2672 KB Output is correct
22 Correct 105 ms 12180 KB Output is correct
23 Correct 106 ms 20048 KB Output is correct
24 Correct 8 ms 1152 KB Output is correct
25 Correct 8 ms 1152 KB Output is correct
26 Correct 111 ms 12112 KB Output is correct
27 Correct 108 ms 12112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 896 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 4 ms 896 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 3 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 5 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 828 KB Output is correct
14 Correct 4 ms 896 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 2 ms 832 KB Output is correct
17 Correct 4 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 2 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 4 ms 896 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 4 ms 768 KB Output is correct
29 Correct 122 ms 20344 KB Output is correct
30 Correct 124 ms 20048 KB Output is correct
31 Correct 122 ms 20176 KB Output is correct
32 Correct 118 ms 20176 KB Output is correct
33 Correct 112 ms 13684 KB Output is correct
34 Correct 109 ms 13392 KB Output is correct
35 Correct 124 ms 20048 KB Output is correct
36 Correct 104 ms 20308 KB Output is correct
37 Correct 19 ms 2676 KB Output is correct
38 Correct 122 ms 20176 KB Output is correct
39 Correct 8 ms 1024 KB Output is correct
40 Correct 45 ms 3632 KB Output is correct
41 Correct 118 ms 20240 KB Output is correct
42 Correct 121 ms 20176 KB Output is correct
43 Correct 19 ms 2804 KB Output is correct
44 Correct 124 ms 20116 KB Output is correct
45 Correct 118 ms 20056 KB Output is correct
46 Correct 36 ms 3308 KB Output is correct
47 Correct 124 ms 20372 KB Output is correct
48 Correct 121 ms 20596 KB Output is correct
49 Correct 20 ms 2672 KB Output is correct
50 Correct 105 ms 12180 KB Output is correct
51 Correct 106 ms 20048 KB Output is correct
52 Correct 8 ms 1152 KB Output is correct
53 Correct 8 ms 1152 KB Output is correct
54 Correct 111 ms 12112 KB Output is correct
55 Correct 108 ms 12112 KB Output is correct
56 Correct 253 ms 31380 KB Output is correct
57 Correct 241 ms 27804 KB Output is correct
58 Correct 252 ms 29596 KB Output is correct
59 Correct 223 ms 24212 KB Output is correct
60 Correct 258 ms 26740 KB Output is correct
61 Correct 251 ms 32656 KB Output is correct
62 Correct 213 ms 23444 KB Output is correct
63 Correct 181 ms 21596 KB Output is correct
64 Correct 82 ms 5604 KB Output is correct
65 Correct 244 ms 27796 KB Output is correct
66 Correct 76 ms 5624 KB Output is correct
67 Correct 96 ms 7776 KB Output is correct
68 Correct 137 ms 19984 KB Output is correct
69 Correct 257 ms 29580 KB Output is correct
70 Correct 22 ms 2920 KB Output is correct
71 Correct 136 ms 20116 KB Output is correct
72 Correct 223 ms 24212 KB Output is correct
73 Correct 19 ms 2672 KB Output is correct
74 Correct 123 ms 14656 KB Output is correct
75 Correct 255 ms 31764 KB Output is correct
76 Correct 18 ms 2676 KB Output is correct
77 Correct 107 ms 12820 KB Output is correct
78 Correct 168 ms 21864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 12064 KB Output is correct
2 Correct 107 ms 3416 KB Output is correct
3 Correct 28 ms 2800 KB Output is correct
4 Correct 23 ms 2804 KB Output is correct
5 Correct 361 ms 43352 KB Output is correct
6 Correct 335 ms 38672 KB Output is correct
7 Correct 327 ms 40592 KB Output is correct
8 Correct 289 ms 36864 KB Output is correct
9 Correct 367 ms 48268 KB Output is correct
10 Correct 328 ms 39316 KB Output is correct
11 Correct 300 ms 48768 KB Output is correct
12 Correct 177 ms 23636 KB Output is correct
13 Correct 144 ms 14480 KB Output is correct
14 Correct 315 ms 38672 KB Output is correct
15 Correct 335 ms 39552 KB Output is correct
16 Correct 165 ms 20244 KB Output is correct
17 Correct 166 ms 19552 KB Output is correct
18 Correct 377 ms 56960 KB Output is correct
19 Correct 146 ms 19988 KB Output is correct
20 Correct 188 ms 20704 KB Output is correct
21 Correct 298 ms 36844 KB Output is correct
22 Correct 154 ms 20352 KB Output is correct
23 Correct 167 ms 19052 KB Output is correct
24 Correct 334 ms 48268 KB Output is correct
25 Correct 95 ms 13592 KB Output is correct
26 Correct 85 ms 13332 KB Output is correct
27 Correct 201 ms 30224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 896 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 4 ms 896 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 3 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 5 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 828 KB Output is correct
14 Correct 4 ms 896 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 2 ms 832 KB Output is correct
17 Correct 4 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 2 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 4 ms 896 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 4 ms 768 KB Output is correct
29 Correct 122 ms 20344 KB Output is correct
30 Correct 124 ms 20048 KB Output is correct
31 Correct 122 ms 20176 KB Output is correct
32 Correct 118 ms 20176 KB Output is correct
33 Correct 112 ms 13684 KB Output is correct
34 Correct 109 ms 13392 KB Output is correct
35 Correct 124 ms 20048 KB Output is correct
36 Correct 104 ms 20308 KB Output is correct
37 Correct 19 ms 2676 KB Output is correct
38 Correct 122 ms 20176 KB Output is correct
39 Correct 8 ms 1024 KB Output is correct
40 Correct 45 ms 3632 KB Output is correct
41 Correct 118 ms 20240 KB Output is correct
42 Correct 121 ms 20176 KB Output is correct
43 Correct 19 ms 2804 KB Output is correct
44 Correct 124 ms 20116 KB Output is correct
45 Correct 118 ms 20056 KB Output is correct
46 Correct 36 ms 3308 KB Output is correct
47 Correct 124 ms 20372 KB Output is correct
48 Correct 121 ms 20596 KB Output is correct
49 Correct 20 ms 2672 KB Output is correct
50 Correct 105 ms 12180 KB Output is correct
51 Correct 106 ms 20048 KB Output is correct
52 Correct 8 ms 1152 KB Output is correct
53 Correct 8 ms 1152 KB Output is correct
54 Correct 111 ms 12112 KB Output is correct
55 Correct 108 ms 12112 KB Output is correct
56 Correct 253 ms 31380 KB Output is correct
57 Correct 241 ms 27804 KB Output is correct
58 Correct 252 ms 29596 KB Output is correct
59 Correct 223 ms 24212 KB Output is correct
60 Correct 258 ms 26740 KB Output is correct
61 Correct 251 ms 32656 KB Output is correct
62 Correct 213 ms 23444 KB Output is correct
63 Correct 181 ms 21596 KB Output is correct
64 Correct 82 ms 5604 KB Output is correct
65 Correct 244 ms 27796 KB Output is correct
66 Correct 76 ms 5624 KB Output is correct
67 Correct 96 ms 7776 KB Output is correct
68 Correct 137 ms 19984 KB Output is correct
69 Correct 257 ms 29580 KB Output is correct
70 Correct 22 ms 2920 KB Output is correct
71 Correct 136 ms 20116 KB Output is correct
72 Correct 223 ms 24212 KB Output is correct
73 Correct 19 ms 2672 KB Output is correct
74 Correct 123 ms 14656 KB Output is correct
75 Correct 255 ms 31764 KB Output is correct
76 Correct 18 ms 2676 KB Output is correct
77 Correct 107 ms 12820 KB Output is correct
78 Correct 168 ms 21864 KB Output is correct
79 Correct 139 ms 12064 KB Output is correct
80 Correct 107 ms 3416 KB Output is correct
81 Correct 28 ms 2800 KB Output is correct
82 Correct 23 ms 2804 KB Output is correct
83 Correct 361 ms 43352 KB Output is correct
84 Correct 335 ms 38672 KB Output is correct
85 Correct 327 ms 40592 KB Output is correct
86 Correct 289 ms 36864 KB Output is correct
87 Correct 367 ms 48268 KB Output is correct
88 Correct 328 ms 39316 KB Output is correct
89 Correct 300 ms 48768 KB Output is correct
90 Correct 177 ms 23636 KB Output is correct
91 Correct 144 ms 14480 KB Output is correct
92 Correct 315 ms 38672 KB Output is correct
93 Correct 335 ms 39552 KB Output is correct
94 Correct 165 ms 20244 KB Output is correct
95 Correct 166 ms 19552 KB Output is correct
96 Correct 377 ms 56960 KB Output is correct
97 Correct 146 ms 19988 KB Output is correct
98 Correct 188 ms 20704 KB Output is correct
99 Correct 298 ms 36844 KB Output is correct
100 Correct 154 ms 20352 KB Output is correct
101 Correct 167 ms 19052 KB Output is correct
102 Correct 334 ms 48268 KB Output is correct
103 Correct 95 ms 13592 KB Output is correct
104 Correct 85 ms 13332 KB Output is correct
105 Correct 201 ms 30224 KB Output is correct
106 Correct 77 ms 10916 KB Output is correct
107 Correct 95 ms 11792 KB Output is correct
108 Correct 98 ms 7772 KB Output is correct
109 Correct 134 ms 8144 KB Output is correct
110 Correct 343 ms 41924 KB Output is correct
111 Correct 335 ms 54168 KB Output is correct
112 Correct 338 ms 55704 KB Output is correct
113 Correct 304 ms 50952 KB Output is correct
114 Correct 331 ms 42260 KB Output is correct
115 Correct 305 ms 39092 KB Output is correct
116 Correct 293 ms 48260 KB Output is correct
117 Correct 222 ms 31680 KB Output is correct
118 Correct 155 ms 16716 KB Output is correct
119 Correct 87 ms 11896 KB Output is correct
120 Correct 325 ms 54316 KB Output is correct
121 Correct 143 ms 18836 KB Output is correct
122 Correct 154 ms 19196 KB Output is correct
123 Correct 335 ms 53384 KB Output is correct
124 Correct 137 ms 20244 KB Output is correct
125 Correct 160 ms 21988 KB Output is correct
126 Correct 280 ms 34436 KB Output is correct
127 Correct 115 ms 14228 KB Output is correct
128 Correct 139 ms 20244 KB Output is correct
129 Correct 296 ms 39344 KB Output is correct
130 Correct 120 ms 18804 KB Output is correct
131 Correct 139 ms 20108 KB Output is correct
132 Correct 223 ms 30588 KB Output is correct