답안 #987891

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987891 2024-05-23T18:39:56 Z activedeltorre Shopping Plans (CCO20_day2problem3) C++14
25 / 25
276 ms 72888 KB
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
//ifstream cin("a.in");
//ofstream cout("a.out");
long long inf=1e9+10;
struct node
{
    long long  layer,sum,bitipref,lst,rghtbord,biti;
    //  node(long long a,long long b,long long c,long long d,long long e) : layer(a),sum(b),bitipref(c),lst(d),rghtbord(e){}
};
struct  cmp
{
    bool operator()(node a,node  b)
    {
        return a.sum>b.sum;
    }
};
priority_queue<node,vector<node>,cmp>pq;
vector<long long >arr;
vector<long long >adj[200005];
long long cost[200005];
vector<long long>ord;
bool cmp2(long long a,long long b)
{
    return cost[a]<cost[b];
}
long long y[200005];
long long x[200005];
long long init[200005];
node special(node curr)
{
    long long g,g2;
    g=ord[curr.layer];
    g2=ord[curr.layer+1];
    curr.lst=0;
    curr.sum+=adj[g2][0];
    curr.layer++;
    curr.biti=1;
    curr.bitipref=0;
    curr.rghtbord=adj[g2].size()-1;
    return curr;
}
node skip(node curr)
{
    long long g,g2;
    g=ord[curr.layer];
    g2=ord[curr.layer+1];
    if(x[g]==0)
    {
       curr.sum=curr.sum-adj[g][curr.lst];
    }
    else
        curr.sum=curr.sum-adj[g][curr.lst]+adj[g][curr.lst-1];
    if(x[g2]==0)
    {
        return special(curr);
    }
    curr.layer++;
    curr.biti=x[g2];
    curr.lst=x[g2];
    curr.bitipref=x[g2]-1;
    curr.rghtbord=adj[g2].size()-1;
    curr.sum=curr.sum+adj[g2][curr.lst]-adj[g2][curr.lst-1];
    return curr;
}
node godown(node curr)
{
    long long g,g2;
    g=ord[curr.layer];
    g2=ord[curr.layer+1];
    if(x[g2]==0)
    {
        return special(curr);
    }
    curr.layer++;
    curr.biti=x[g2];
    curr.lst=x[g2];
    curr.bitipref=x[g2]-1;
    curr.rghtbord=adj[g2].size()-1;
    curr.sum=curr.sum+adj[g2][curr.lst]-adj[g2][curr.lst-1];
    return curr;
}
node shift(node curr)
{
    long long g;
    g=ord[curr.layer];
    curr.lst++;
    curr.sum=curr.sum+adj[g][curr.lst]-adj[g][curr.lst-1];
    return curr;
}
node fixborderandshift(node curr)
{
    long long g;
    g=ord[curr.layer];
    curr.rghtbord=curr.lst-1;
    curr.lst=curr.bitipref;
    curr.bitipref--;
    curr.sum=curr.sum+adj[g][curr.lst]-adj[g][curr.lst-1];
    return curr;
}
node fixborderandcreate(node curr)
{
    long long g;
    g=ord[curr.layer];
    curr.rghtbord=curr.lst-1;
    curr.lst=0;
    curr.biti++;
    curr.sum=curr.sum+init[g];
    return curr;
}
signed  main()
{
    long long  n,m,k,i,a,b;
    long long sum=0;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m>>k;
    for(i=1; i<=n; i++)
    {
        cin>>a>>b;
        adj[a].push_back(b);
    }
    long long imp=0,minim=inf,poz=m;
    for(i=1; i<=m; i++)
    {
        cin>>x[i]>>y[i];
        if(y[i]==0)
        {
            cost[i]=inf;
        }
        else
        {
            sort(adj[i].begin(),adj[i].end());
            if(adj[i].size()<x[i])
            {
                for(long long j=1; j<=k; j++)
                {
                    cout<<-1<<'\n';
                }
                return 0;
            }
            if(x[i]==0)
            {
                if(adj[i].size()==0)
                {
                    cost[i]=inf;
                }
                else
                {
                    init[i]=adj[i][0];
                    cost[i]=adj[i][0];
                }
            }
            else
            {
                long long vkuk=adj[i][0];
                init[i]=adj[i][0];
                for(long long j=0; j<adj[i].size(); j++)
                {
                    if(j+1<=x[i])
                    {
                        sum+=adj[i][j];
                    }
                    adj[i][j]-=vkuk;
                }
                if(adj[i].size()==x[i])
                {
                    cost[i]=inf;
                }
                else
                {
                    cost[i]=adj[i][x[i]]-adj[i][x[i]-1];
                }
            }
        }
        ord.push_back(i);
    }
    sort(ord.begin(),ord.end(),cmp2);
    m--;
    for(i=0; i<ord.size(); i++)
    {
        if(cost[ord[i]]==inf)
        {
            m=i-1;
            break;
        }
    }
    node curr,curr2;
    cout<<sum<<'\n';
    k--;
    if(m>=0)
    {
        long long g=ord[0];
        if(x[g]==0)
        {
            curr.layer=0;
            curr.sum=adj[g][0];
            curr.bitipref=0;
            curr.lst=0;
            curr.biti=1;
            curr.rghtbord=adj[g].size()-1;
            pq.push(curr);
        }
        else
        {
            curr.layer=0;
            curr.sum=adj[g][x[g]]-adj[g][x[g]-1];
            curr.bitipref=x[g]-1;
            curr.lst=x[g];
            curr.rghtbord=adj[g].size()-1;
            curr.biti=x[g];
            pq.push(curr);
        }
        while(pq.size() && k && imp==0)
        {
            curr=pq.top();
            pq.pop();
            k--;
            cout<<curr.sum+sum<<'\n';
            g=ord[curr.layer];
            if(x[g]==0 && curr.biti==1 && curr.layer+1<=m && curr.lst==0)
            {
                curr2=skip(curr);
                pq.push(curr2);
            }
            if(curr.lst==x[g] && curr.bitipref==x[g]-1 && curr.biti==x[g] && curr.layer+1<=m)
            {
                curr2=skip(curr);
                pq.push(curr2);
            }
            if(curr.lst+1<=curr.rghtbord)
            {
                curr2=shift(curr);
                pq.push(curr2);
            }
            if(curr.bitipref>=1 && curr.lst>=curr.bitipref+1)
            {
                curr2=fixborderandshift(curr);
                pq.push(curr2);
            }
            if(curr.bitipref==0 && curr.lst>=1 && curr.biti+1<=y[g])
            {
                curr2=fixborderandcreate(curr);
                pq.push(curr2);
            }
            if(curr.layer+1<=m)
            {
                curr2=godown(curr);
                pq.push(curr2);
            }
        }
    }
    while(k)
    {
        k--;
        cout<<-1<<'\n';
    }
    return 0;
}
/*
5 2 33
1 5
1 3
2 3
1 6
2 1
0 3
0 2*/

Compilation message

Main.cpp: In function 'node special(node)':
Main.cpp:36:15: warning: variable 'g' set but not used [-Wunused-but-set-variable]
   36 |     long long g,g2;
      |               ^
Main.cpp: In function 'node godown(node)':
Main.cpp:72:15: warning: variable 'g' set but not used [-Wunused-but-set-variable]
   72 |     long long g,g2;
      |               ^
Main.cpp: In function 'int main()':
Main.cpp:138:29: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  138 |             if(adj[i].size()<x[i])
      |                ~~~~~~~~~~~~~^~~~~
Main.cpp:162:37: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  162 |                 for(long long j=0; j<adj[i].size(); j++)
      |                                    ~^~~~~~~~~~~~~~
Main.cpp:170:33: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  170 |                 if(adj[i].size()==x[i])
      |                    ~~~~~~~~~~~~~^~~~~~
Main.cpp:184:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  184 |     for(i=0; i<ord.size(); i++)
      |              ~^~~~~~~~~~~
Main.cpp:127:21: warning: unused variable 'minim' [-Wunused-variable]
  127 |     long long imp=0,minim=inf,poz=m;
      |                     ^~~~~
Main.cpp:127:31: warning: unused variable 'poz' [-Wunused-variable]
  127 |     long long imp=0,minim=inf,poz=m;
      |                               ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 11824 KB Output is correct
2 Correct 7 ms 11876 KB Output is correct
3 Correct 5 ms 11876 KB Output is correct
4 Correct 5 ms 11868 KB Output is correct
5 Correct 5 ms 11828 KB Output is correct
6 Correct 6 ms 11816 KB Output is correct
7 Correct 5 ms 11804 KB Output is correct
8 Correct 4 ms 11816 KB Output is correct
9 Correct 4 ms 11100 KB Output is correct
10 Correct 5 ms 11876 KB Output is correct
11 Correct 4 ms 11096 KB Output is correct
12 Correct 4 ms 11356 KB Output is correct
13 Correct 5 ms 11744 KB Output is correct
14 Correct 6 ms 11876 KB Output is correct
15 Correct 5 ms 11548 KB Output is correct
16 Correct 4 ms 11808 KB Output is correct
17 Correct 7 ms 11864 KB Output is correct
18 Correct 4 ms 11356 KB Output is correct
19 Correct 5 ms 11808 KB Output is correct
20 Correct 6 ms 11884 KB Output is correct
21 Correct 4 ms 11100 KB Output is correct
22 Correct 4 ms 11800 KB Output is correct
23 Correct 5 ms 11812 KB Output is correct
24 Correct 4 ms 11352 KB Output is correct
25 Correct 4 ms 11352 KB Output is correct
26 Correct 5 ms 11816 KB Output is correct
27 Correct 5 ms 11804 KB Output is correct
28 Correct 4 ms 11816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 37320 KB Output is correct
2 Correct 73 ms 37572 KB Output is correct
3 Correct 73 ms 39092 KB Output is correct
4 Correct 80 ms 38244 KB Output is correct
5 Correct 60 ms 25348 KB Output is correct
6 Correct 60 ms 25612 KB Output is correct
7 Correct 87 ms 38524 KB Output is correct
8 Correct 68 ms 37188 KB Output is correct
9 Correct 14 ms 11868 KB Output is correct
10 Correct 90 ms 39244 KB Output is correct
11 Correct 14 ms 11864 KB Output is correct
12 Correct 40 ms 13020 KB Output is correct
13 Correct 75 ms 38096 KB Output is correct
14 Correct 103 ms 38328 KB Output is correct
15 Correct 15 ms 12008 KB Output is correct
16 Correct 79 ms 37296 KB Output is correct
17 Correct 94 ms 37548 KB Output is correct
18 Correct 31 ms 12376 KB Output is correct
19 Correct 97 ms 39080 KB Output is correct
20 Correct 72 ms 37936 KB Output is correct
21 Correct 14 ms 11848 KB Output is correct
22 Correct 95 ms 24800 KB Output is correct
23 Correct 83 ms 37324 KB Output is correct
24 Correct 16 ms 11748 KB Output is correct
25 Correct 16 ms 11800 KB Output is correct
26 Correct 68 ms 27096 KB Output is correct
27 Correct 65 ms 25788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 11824 KB Output is correct
2 Correct 7 ms 11876 KB Output is correct
3 Correct 5 ms 11876 KB Output is correct
4 Correct 5 ms 11868 KB Output is correct
5 Correct 5 ms 11828 KB Output is correct
6 Correct 6 ms 11816 KB Output is correct
7 Correct 5 ms 11804 KB Output is correct
8 Correct 4 ms 11816 KB Output is correct
9 Correct 4 ms 11100 KB Output is correct
10 Correct 5 ms 11876 KB Output is correct
11 Correct 4 ms 11096 KB Output is correct
12 Correct 4 ms 11356 KB Output is correct
13 Correct 5 ms 11744 KB Output is correct
14 Correct 6 ms 11876 KB Output is correct
15 Correct 5 ms 11548 KB Output is correct
16 Correct 4 ms 11808 KB Output is correct
17 Correct 7 ms 11864 KB Output is correct
18 Correct 4 ms 11356 KB Output is correct
19 Correct 5 ms 11808 KB Output is correct
20 Correct 6 ms 11884 KB Output is correct
21 Correct 4 ms 11100 KB Output is correct
22 Correct 4 ms 11800 KB Output is correct
23 Correct 5 ms 11812 KB Output is correct
24 Correct 4 ms 11352 KB Output is correct
25 Correct 4 ms 11352 KB Output is correct
26 Correct 5 ms 11816 KB Output is correct
27 Correct 5 ms 11804 KB Output is correct
28 Correct 4 ms 11816 KB Output is correct
29 Correct 74 ms 37320 KB Output is correct
30 Correct 73 ms 37572 KB Output is correct
31 Correct 73 ms 39092 KB Output is correct
32 Correct 80 ms 38244 KB Output is correct
33 Correct 60 ms 25348 KB Output is correct
34 Correct 60 ms 25612 KB Output is correct
35 Correct 87 ms 38524 KB Output is correct
36 Correct 68 ms 37188 KB Output is correct
37 Correct 14 ms 11868 KB Output is correct
38 Correct 90 ms 39244 KB Output is correct
39 Correct 14 ms 11864 KB Output is correct
40 Correct 40 ms 13020 KB Output is correct
41 Correct 75 ms 38096 KB Output is correct
42 Correct 103 ms 38328 KB Output is correct
43 Correct 15 ms 12008 KB Output is correct
44 Correct 79 ms 37296 KB Output is correct
45 Correct 94 ms 37548 KB Output is correct
46 Correct 31 ms 12376 KB Output is correct
47 Correct 97 ms 39080 KB Output is correct
48 Correct 72 ms 37936 KB Output is correct
49 Correct 14 ms 11848 KB Output is correct
50 Correct 95 ms 24800 KB Output is correct
51 Correct 83 ms 37324 KB Output is correct
52 Correct 16 ms 11748 KB Output is correct
53 Correct 16 ms 11800 KB Output is correct
54 Correct 68 ms 27096 KB Output is correct
55 Correct 65 ms 25788 KB Output is correct
56 Correct 206 ms 48824 KB Output is correct
57 Correct 171 ms 45468 KB Output is correct
58 Correct 190 ms 46772 KB Output is correct
59 Correct 171 ms 44896 KB Output is correct
60 Correct 199 ms 35952 KB Output is correct
61 Correct 162 ms 46884 KB Output is correct
62 Correct 169 ms 42676 KB Output is correct
63 Correct 164 ms 41456 KB Output is correct
64 Correct 65 ms 16584 KB Output is correct
65 Correct 193 ms 45656 KB Output is correct
66 Correct 54 ms 16968 KB Output is correct
67 Correct 61 ms 16316 KB Output is correct
68 Correct 116 ms 38400 KB Output is correct
69 Correct 196 ms 46696 KB Output is correct
70 Correct 16 ms 12060 KB Output is correct
71 Correct 117 ms 39748 KB Output is correct
72 Correct 191 ms 44836 KB Output is correct
73 Correct 20 ms 11952 KB Output is correct
74 Correct 84 ms 25896 KB Output is correct
75 Correct 194 ms 49176 KB Output is correct
76 Correct 13 ms 11868 KB Output is correct
77 Correct 89 ms 26292 KB Output is correct
78 Correct 141 ms 40920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 16160 KB Output is correct
2 Correct 41 ms 13160 KB Output is correct
3 Correct 21 ms 11868 KB Output is correct
4 Correct 14 ms 12060 KB Output is correct
5 Correct 217 ms 48112 KB Output is correct
6 Correct 184 ms 46744 KB Output is correct
7 Correct 186 ms 46984 KB Output is correct
8 Correct 211 ms 47512 KB Output is correct
9 Correct 165 ms 48348 KB Output is correct
10 Correct 252 ms 46608 KB Output is correct
11 Correct 169 ms 45252 KB Output is correct
12 Correct 135 ms 44728 KB Output is correct
13 Correct 118 ms 20464 KB Output is correct
14 Correct 209 ms 47756 KB Output is correct
15 Correct 199 ms 46360 KB Output is correct
16 Correct 116 ms 25416 KB Output is correct
17 Correct 126 ms 38736 KB Output is correct
18 Correct 239 ms 46128 KB Output is correct
19 Correct 84 ms 39084 KB Output is correct
20 Correct 93 ms 37484 KB Output is correct
21 Correct 192 ms 47308 KB Output is correct
22 Correct 87 ms 25968 KB Output is correct
23 Correct 86 ms 39088 KB Output is correct
24 Correct 189 ms 47428 KB Output is correct
25 Correct 95 ms 38488 KB Output is correct
26 Correct 77 ms 38316 KB Output is correct
27 Correct 174 ms 45720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 11824 KB Output is correct
2 Correct 7 ms 11876 KB Output is correct
3 Correct 5 ms 11876 KB Output is correct
4 Correct 5 ms 11868 KB Output is correct
5 Correct 5 ms 11828 KB Output is correct
6 Correct 6 ms 11816 KB Output is correct
7 Correct 5 ms 11804 KB Output is correct
8 Correct 4 ms 11816 KB Output is correct
9 Correct 4 ms 11100 KB Output is correct
10 Correct 5 ms 11876 KB Output is correct
11 Correct 4 ms 11096 KB Output is correct
12 Correct 4 ms 11356 KB Output is correct
13 Correct 5 ms 11744 KB Output is correct
14 Correct 6 ms 11876 KB Output is correct
15 Correct 5 ms 11548 KB Output is correct
16 Correct 4 ms 11808 KB Output is correct
17 Correct 7 ms 11864 KB Output is correct
18 Correct 4 ms 11356 KB Output is correct
19 Correct 5 ms 11808 KB Output is correct
20 Correct 6 ms 11884 KB Output is correct
21 Correct 4 ms 11100 KB Output is correct
22 Correct 4 ms 11800 KB Output is correct
23 Correct 5 ms 11812 KB Output is correct
24 Correct 4 ms 11352 KB Output is correct
25 Correct 4 ms 11352 KB Output is correct
26 Correct 5 ms 11816 KB Output is correct
27 Correct 5 ms 11804 KB Output is correct
28 Correct 4 ms 11816 KB Output is correct
29 Correct 74 ms 37320 KB Output is correct
30 Correct 73 ms 37572 KB Output is correct
31 Correct 73 ms 39092 KB Output is correct
32 Correct 80 ms 38244 KB Output is correct
33 Correct 60 ms 25348 KB Output is correct
34 Correct 60 ms 25612 KB Output is correct
35 Correct 87 ms 38524 KB Output is correct
36 Correct 68 ms 37188 KB Output is correct
37 Correct 14 ms 11868 KB Output is correct
38 Correct 90 ms 39244 KB Output is correct
39 Correct 14 ms 11864 KB Output is correct
40 Correct 40 ms 13020 KB Output is correct
41 Correct 75 ms 38096 KB Output is correct
42 Correct 103 ms 38328 KB Output is correct
43 Correct 15 ms 12008 KB Output is correct
44 Correct 79 ms 37296 KB Output is correct
45 Correct 94 ms 37548 KB Output is correct
46 Correct 31 ms 12376 KB Output is correct
47 Correct 97 ms 39080 KB Output is correct
48 Correct 72 ms 37936 KB Output is correct
49 Correct 14 ms 11848 KB Output is correct
50 Correct 95 ms 24800 KB Output is correct
51 Correct 83 ms 37324 KB Output is correct
52 Correct 16 ms 11748 KB Output is correct
53 Correct 16 ms 11800 KB Output is correct
54 Correct 68 ms 27096 KB Output is correct
55 Correct 65 ms 25788 KB Output is correct
56 Correct 206 ms 48824 KB Output is correct
57 Correct 171 ms 45468 KB Output is correct
58 Correct 190 ms 46772 KB Output is correct
59 Correct 171 ms 44896 KB Output is correct
60 Correct 199 ms 35952 KB Output is correct
61 Correct 162 ms 46884 KB Output is correct
62 Correct 169 ms 42676 KB Output is correct
63 Correct 164 ms 41456 KB Output is correct
64 Correct 65 ms 16584 KB Output is correct
65 Correct 193 ms 45656 KB Output is correct
66 Correct 54 ms 16968 KB Output is correct
67 Correct 61 ms 16316 KB Output is correct
68 Correct 116 ms 38400 KB Output is correct
69 Correct 196 ms 46696 KB Output is correct
70 Correct 16 ms 12060 KB Output is correct
71 Correct 117 ms 39748 KB Output is correct
72 Correct 191 ms 44836 KB Output is correct
73 Correct 20 ms 11952 KB Output is correct
74 Correct 84 ms 25896 KB Output is correct
75 Correct 194 ms 49176 KB Output is correct
76 Correct 13 ms 11868 KB Output is correct
77 Correct 89 ms 26292 KB Output is correct
78 Correct 141 ms 40920 KB Output is correct
79 Correct 49 ms 16160 KB Output is correct
80 Correct 41 ms 13160 KB Output is correct
81 Correct 21 ms 11868 KB Output is correct
82 Correct 14 ms 12060 KB Output is correct
83 Correct 217 ms 48112 KB Output is correct
84 Correct 184 ms 46744 KB Output is correct
85 Correct 186 ms 46984 KB Output is correct
86 Correct 211 ms 47512 KB Output is correct
87 Correct 165 ms 48348 KB Output is correct
88 Correct 252 ms 46608 KB Output is correct
89 Correct 169 ms 45252 KB Output is correct
90 Correct 135 ms 44728 KB Output is correct
91 Correct 118 ms 20464 KB Output is correct
92 Correct 209 ms 47756 KB Output is correct
93 Correct 199 ms 46360 KB Output is correct
94 Correct 116 ms 25416 KB Output is correct
95 Correct 126 ms 38736 KB Output is correct
96 Correct 239 ms 46128 KB Output is correct
97 Correct 84 ms 39084 KB Output is correct
98 Correct 93 ms 37484 KB Output is correct
99 Correct 192 ms 47308 KB Output is correct
100 Correct 87 ms 25968 KB Output is correct
101 Correct 86 ms 39088 KB Output is correct
102 Correct 189 ms 47428 KB Output is correct
103 Correct 95 ms 38488 KB Output is correct
104 Correct 77 ms 38316 KB Output is correct
105 Correct 174 ms 45720 KB Output is correct
106 Correct 37 ms 12636 KB Output is correct
107 Correct 49 ms 14992 KB Output is correct
108 Correct 46 ms 13272 KB Output is correct
109 Correct 51 ms 15572 KB Output is correct
110 Correct 195 ms 49700 KB Output is correct
111 Correct 255 ms 48904 KB Output is correct
112 Correct 276 ms 48944 KB Output is correct
113 Correct 220 ms 48248 KB Output is correct
114 Correct 194 ms 50888 KB Output is correct
115 Correct 211 ms 48352 KB Output is correct
116 Correct 222 ms 72888 KB Output is correct
117 Correct 178 ms 47648 KB Output is correct
118 Correct 120 ms 25488 KB Output is correct
119 Correct 60 ms 18700 KB Output is correct
120 Correct 215 ms 48428 KB Output is correct
121 Correct 85 ms 38828 KB Output is correct
122 Correct 106 ms 37988 KB Output is correct
123 Correct 272 ms 49004 KB Output is correct
124 Correct 80 ms 26040 KB Output is correct
125 Correct 131 ms 38724 KB Output is correct
126 Correct 202 ms 49052 KB Output is correct
127 Correct 74 ms 26556 KB Output is correct
128 Correct 102 ms 38072 KB Output is correct
129 Correct 216 ms 50308 KB Output is correct
130 Correct 103 ms 39088 KB Output is correct
131 Correct 121 ms 38648 KB Output is correct
132 Correct 162 ms 48120 KB Output is correct