답안 #286514

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
286514 2020-08-30T13:57:21 Z gs18115 Shopping Plans (CCO20_day2problem3) C++14
15 / 25
289 ms 32916 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,tpv[0].x,0,-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.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,ntp.x,0,-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 896 KB Output is correct
4 Correct 4 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 816 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 4 ms 928 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 5 ms 896 KB Output is correct
15 Correct 2 ms 656 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 2 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 3 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 20340 KB Output is correct
2 Correct 127 ms 20048 KB Output is correct
3 Correct 145 ms 20172 KB Output is correct
4 Correct 123 ms 20176 KB Output is correct
5 Correct 116 ms 13684 KB Output is correct
6 Correct 117 ms 13392 KB Output is correct
7 Correct 135 ms 20048 KB Output is correct
8 Correct 111 ms 20304 KB Output is correct
9 Correct 19 ms 2660 KB Output is correct
10 Correct 126 ms 20176 KB Output is correct
11 Correct 8 ms 1024 KB Output is correct
12 Correct 44 ms 3616 KB Output is correct
13 Correct 127 ms 20240 KB Output is correct
14 Correct 129 ms 20176 KB Output is correct
15 Correct 19 ms 2836 KB Output is correct
16 Correct 122 ms 20116 KB Output is correct
17 Correct 124 ms 20048 KB Output is correct
18 Correct 35 ms 3176 KB Output is correct
19 Correct 130 ms 20372 KB Output is correct
20 Correct 122 ms 20604 KB Output is correct
21 Correct 20 ms 2672 KB Output is correct
22 Correct 111 ms 12180 KB Output is correct
23 Correct 109 ms 20048 KB Output is correct
24 Correct 9 ms 1152 KB Output is correct
25 Correct 8 ms 1152 KB Output is correct
26 Correct 115 ms 12112 KB Output is correct
27 Correct 111 ms 12112 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 896 KB Output is correct
4 Correct 4 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 816 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 4 ms 928 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 5 ms 896 KB Output is correct
15 Correct 2 ms 656 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 2 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 3 ms 768 KB Output is correct
29 Correct 125 ms 20340 KB Output is correct
30 Correct 127 ms 20048 KB Output is correct
31 Correct 145 ms 20172 KB Output is correct
32 Correct 123 ms 20176 KB Output is correct
33 Correct 116 ms 13684 KB Output is correct
34 Correct 117 ms 13392 KB Output is correct
35 Correct 135 ms 20048 KB Output is correct
36 Correct 111 ms 20304 KB Output is correct
37 Correct 19 ms 2660 KB Output is correct
38 Correct 126 ms 20176 KB Output is correct
39 Correct 8 ms 1024 KB Output is correct
40 Correct 44 ms 3616 KB Output is correct
41 Correct 127 ms 20240 KB Output is correct
42 Correct 129 ms 20176 KB Output is correct
43 Correct 19 ms 2836 KB Output is correct
44 Correct 122 ms 20116 KB Output is correct
45 Correct 124 ms 20048 KB Output is correct
46 Correct 35 ms 3176 KB Output is correct
47 Correct 130 ms 20372 KB Output is correct
48 Correct 122 ms 20604 KB Output is correct
49 Correct 20 ms 2672 KB Output is correct
50 Correct 111 ms 12180 KB Output is correct
51 Correct 109 ms 20048 KB Output is correct
52 Correct 9 ms 1152 KB Output is correct
53 Correct 8 ms 1152 KB Output is correct
54 Correct 115 ms 12112 KB Output is correct
55 Correct 111 ms 12112 KB Output is correct
56 Correct 262 ms 31328 KB Output is correct
57 Correct 253 ms 27828 KB Output is correct
58 Correct 258 ms 29596 KB Output is correct
59 Correct 235 ms 24212 KB Output is correct
60 Correct 257 ms 26652 KB Output is correct
61 Correct 289 ms 32916 KB Output is correct
62 Correct 251 ms 23440 KB Output is correct
63 Correct 193 ms 21596 KB Output is correct
64 Correct 84 ms 5608 KB Output is correct
65 Correct 253 ms 27872 KB Output is correct
66 Correct 81 ms 5624 KB Output is correct
67 Correct 93 ms 7780 KB Output is correct
68 Correct 149 ms 19988 KB Output is correct
69 Correct 260 ms 29544 KB Output is correct
70 Correct 23 ms 2920 KB Output is correct
71 Correct 139 ms 20120 KB Output is correct
72 Correct 225 ms 24276 KB Output is correct
73 Correct 19 ms 2672 KB Output is correct
74 Correct 143 ms 14540 KB Output is correct
75 Correct 285 ms 31772 KB Output is correct
76 Correct 19 ms 2676 KB Output is correct
77 Correct 122 ms 12824 KB Output is correct
78 Correct 171 ms 21868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 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 896 KB Output is correct
4 Correct 4 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 816 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 4 ms 928 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 5 ms 896 KB Output is correct
15 Correct 2 ms 656 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 2 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 3 ms 768 KB Output is correct
29 Correct 125 ms 20340 KB Output is correct
30 Correct 127 ms 20048 KB Output is correct
31 Correct 145 ms 20172 KB Output is correct
32 Correct 123 ms 20176 KB Output is correct
33 Correct 116 ms 13684 KB Output is correct
34 Correct 117 ms 13392 KB Output is correct
35 Correct 135 ms 20048 KB Output is correct
36 Correct 111 ms 20304 KB Output is correct
37 Correct 19 ms 2660 KB Output is correct
38 Correct 126 ms 20176 KB Output is correct
39 Correct 8 ms 1024 KB Output is correct
40 Correct 44 ms 3616 KB Output is correct
41 Correct 127 ms 20240 KB Output is correct
42 Correct 129 ms 20176 KB Output is correct
43 Correct 19 ms 2836 KB Output is correct
44 Correct 122 ms 20116 KB Output is correct
45 Correct 124 ms 20048 KB Output is correct
46 Correct 35 ms 3176 KB Output is correct
47 Correct 130 ms 20372 KB Output is correct
48 Correct 122 ms 20604 KB Output is correct
49 Correct 20 ms 2672 KB Output is correct
50 Correct 111 ms 12180 KB Output is correct
51 Correct 109 ms 20048 KB Output is correct
52 Correct 9 ms 1152 KB Output is correct
53 Correct 8 ms 1152 KB Output is correct
54 Correct 115 ms 12112 KB Output is correct
55 Correct 111 ms 12112 KB Output is correct
56 Correct 262 ms 31328 KB Output is correct
57 Correct 253 ms 27828 KB Output is correct
58 Correct 258 ms 29596 KB Output is correct
59 Correct 235 ms 24212 KB Output is correct
60 Correct 257 ms 26652 KB Output is correct
61 Correct 289 ms 32916 KB Output is correct
62 Correct 251 ms 23440 KB Output is correct
63 Correct 193 ms 21596 KB Output is correct
64 Correct 84 ms 5608 KB Output is correct
65 Correct 253 ms 27872 KB Output is correct
66 Correct 81 ms 5624 KB Output is correct
67 Correct 93 ms 7780 KB Output is correct
68 Correct 149 ms 19988 KB Output is correct
69 Correct 260 ms 29544 KB Output is correct
70 Correct 23 ms 2920 KB Output is correct
71 Correct 139 ms 20120 KB Output is correct
72 Correct 225 ms 24276 KB Output is correct
73 Correct 19 ms 2672 KB Output is correct
74 Correct 143 ms 14540 KB Output is correct
75 Correct 285 ms 31772 KB Output is correct
76 Correct 19 ms 2676 KB Output is correct
77 Correct 122 ms 12824 KB Output is correct
78 Correct 171 ms 21868 KB Output is correct
79 Incorrect 20 ms 2684 KB Output isn't correct
80 Halted 0 ms 0 KB -