답안 #837608

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
837608 2023-08-25T12:46:22 Z Antekb Cookies (JOI23_cookies) C++17
25 / 100
67 ms 1576 KB
#include<bits/stdc++.h>
#define st first
#define nd second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define pp pop_back
#define mp make_pair
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vii = vector<pii>;
using ld = long double;
void debug(){cerr<<"\n";}
template<typename H, typename... T>
void debug(H h, T... t){
	cerr<<h;
	if(sizeof...(t)){
		cerr<<", ";
	}
	debug(t...);
}
#define deb(x...) cerr<<#x<<" = ";debug(x);

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=15005;
vi par[N];
int opt[N], tim[N], ile[N], str[N];
int main(){
	int n, m;
	cin>>n;
	vii V(n);
	int M=0;
	for(int i=0;i<n; i++){
		cin>>V[i].st;
		M=max(M, V[i].st);
		for(int j=0; j<V[i].st; j++)ile[j]++;
		V[i].nd=i+1;
	}
	sort(all(V));
	int s=0;
	for(int i=0; i<M; i++){
		for(int j=s; j<s+ile[M-i-1]; j++){
			tim[j]=i;
		}
		s+=ile[M-i-1];
	}
	tim[s]=M;
	for(int i=1; i<=s; i++){
		opt[i]=-1e9;
		//deb(i, tim[i]);
	}
	cin>>m;
	vi V2(m);
	for(int &i:V2){
		cin>>i;
	}
	sort(all(V2));
	opt[0]=0;
	for(int c:V2){
		for(int i=c; i<=s; i++){
			if(opt[i]<min(opt[i-c]+1, tim[i])){
				opt[i]=min(opt[i-c]+1, tim[i]);
				par[i].pb(c);
				str[i]=str[i-c]+max(opt[i-c]+1-tim[i], 0);
			}
			else if(opt[i]==min(opt[i-c]+1, tim[i]) && str[i-c]+max(opt[i-c]+1-tim[i], 0)<str[i]){
				str[i]=str[i-c]+max(opt[i-c]+1-tim[i], 0);
				par[i].pb(c);
			}
		}
		//for(int i=0; i<=s; i++){deb(i, tim[i], opt[i]);}
	}
	if(opt[s]<M){
		cout<<-1;
		return 0;
	}
	vi siz;
	int prv=1e9;
	while(s){
		while(par[s].back()>prv)par[s].pp();
		prv=par[s].back();
		deb(prv);
		siz.pb(prv);
		s-=prv;
	}
	cout<<siz.size()<<"\n";
	//for(int i:siz)cout<<i<<" ";
	//return 0;
	priority_queue<pair<int, int> > Q;
	for(auto &i:V)Q.push(i);
	for(int j:siz){
		cout<<j<<" ";
		vii todo;
		for(int i=0; i<j; i++){
			assert(Q.size());
			todo.pb(Q.top());
			Q.pop();
			cout<<todo.back().nd<<" ";
			todo.back().st--;
		}
		cout<<"\n";
		for(auto i:todo){
			if(i.st)Q.push(i);
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 0 ms 596 KB Output is correct
6 Correct 1 ms 616 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 0 ms 596 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 12 ms 820 KB Output is correct
10 Correct 67 ms 1576 KB Output is correct
11 Correct 0 ms 596 KB Output is correct
12 Correct 0 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 0 ms 596 KB Output is correct
15 Correct 0 ms 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 0 ms 596 KB Output is correct
18 Correct 17 ms 1324 KB Output is correct
19 Correct 22 ms 1360 KB Output is correct
20 Correct 4 ms 1364 KB Output is correct
21 Correct 3 ms 1364 KB Output is correct
22 Correct 3 ms 1236 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 0 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 0 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 0 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 0 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 0 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 0 ms 596 KB Output is correct
18 Correct 0 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 668 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 668 KB Output is correct
31 Correct 1 ms 668 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 1 ms 664 KB Output is correct
36 Correct 1 ms 668 KB Output is correct
37 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 0 ms 596 KB Output is correct
6 Correct 1 ms 616 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 0 ms 596 KB Output is correct
30 Correct 0 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 0 ms 596 KB Output is correct
35 Correct 1 ms 596 KB Output is correct
36 Correct 0 ms 596 KB Output is correct
37 Correct 1 ms 596 KB Output is correct
38 Correct 0 ms 596 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
41 Correct 0 ms 596 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 1 ms 596 KB Output is correct
44 Correct 1 ms 596 KB Output is correct
45 Correct 0 ms 596 KB Output is correct
46 Correct 0 ms 596 KB Output is correct
47 Correct 1 ms 596 KB Output is correct
48 Correct 1 ms 668 KB Output is correct
49 Correct 1 ms 596 KB Output is correct
50 Correct 1 ms 596 KB Output is correct
51 Correct 1 ms 724 KB Output is correct
52 Correct 1 ms 596 KB Output is correct
53 Correct 1 ms 596 KB Output is correct
54 Correct 1 ms 596 KB Output is correct
55 Correct 1 ms 596 KB Output is correct
56 Correct 1 ms 596 KB Output is correct
57 Correct 1 ms 596 KB Output is correct
58 Correct 1 ms 668 KB Output is correct
59 Correct 1 ms 668 KB Output is correct
60 Correct 1 ms 596 KB Output is correct
61 Correct 1 ms 596 KB Output is correct
62 Correct 1 ms 596 KB Output is correct
63 Correct 1 ms 664 KB Output is correct
64 Correct 1 ms 668 KB Output is correct
65 Correct 1 ms 596 KB Output is correct
66 Correct 1 ms 596 KB Output is correct
67 Correct 3 ms 664 KB Output is correct
68 Correct 1 ms 596 KB Output is correct
69 Correct 1 ms 596 KB Output is correct
70 Correct 1 ms 596 KB Output is correct
71 Incorrect 1 ms 596 KB Output isn't correct
72 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 0 ms 596 KB Output is correct
6 Correct 1 ms 616 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 0 ms 596 KB Output is correct
30 Correct 0 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 0 ms 596 KB Output is correct
35 Correct 1 ms 596 KB Output is correct
36 Correct 0 ms 596 KB Output is correct
37 Correct 1 ms 596 KB Output is correct
38 Correct 0 ms 596 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
41 Correct 0 ms 596 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 1 ms 596 KB Output is correct
44 Correct 1 ms 596 KB Output is correct
45 Correct 0 ms 596 KB Output is correct
46 Correct 0 ms 596 KB Output is correct
47 Correct 1 ms 596 KB Output is correct
48 Correct 1 ms 668 KB Output is correct
49 Correct 1 ms 596 KB Output is correct
50 Correct 1 ms 596 KB Output is correct
51 Correct 1 ms 724 KB Output is correct
52 Correct 1 ms 596 KB Output is correct
53 Correct 1 ms 596 KB Output is correct
54 Correct 1 ms 596 KB Output is correct
55 Correct 1 ms 596 KB Output is correct
56 Correct 1 ms 596 KB Output is correct
57 Correct 1 ms 596 KB Output is correct
58 Correct 1 ms 668 KB Output is correct
59 Correct 1 ms 668 KB Output is correct
60 Correct 1 ms 596 KB Output is correct
61 Correct 1 ms 596 KB Output is correct
62 Correct 1 ms 596 KB Output is correct
63 Correct 1 ms 664 KB Output is correct
64 Correct 1 ms 668 KB Output is correct
65 Correct 1 ms 596 KB Output is correct
66 Correct 1 ms 596 KB Output is correct
67 Correct 3 ms 664 KB Output is correct
68 Correct 1 ms 596 KB Output is correct
69 Correct 1 ms 596 KB Output is correct
70 Correct 1 ms 596 KB Output is correct
71 Incorrect 1 ms 596 KB Output isn't correct
72 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 0 ms 596 KB Output is correct
6 Correct 1 ms 616 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 0 ms 596 KB Output is correct
33 Correct 3 ms 596 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 1 ms 596 KB Output is correct
36 Correct 3 ms 596 KB Output is correct
37 Correct 12 ms 820 KB Output is correct
38 Correct 67 ms 1576 KB Output is correct
39 Correct 0 ms 596 KB Output is correct
40 Correct 0 ms 596 KB Output is correct
41 Correct 1 ms 596 KB Output is correct
42 Correct 0 ms 596 KB Output is correct
43 Correct 0 ms 596 KB Output is correct
44 Correct 1 ms 596 KB Output is correct
45 Correct 0 ms 596 KB Output is correct
46 Correct 17 ms 1324 KB Output is correct
47 Correct 22 ms 1360 KB Output is correct
48 Correct 4 ms 1364 KB Output is correct
49 Correct 3 ms 1364 KB Output is correct
50 Correct 3 ms 1236 KB Output is correct
51 Correct 1 ms 724 KB Output is correct
52 Correct 0 ms 596 KB Output is correct
53 Correct 0 ms 596 KB Output is correct
54 Correct 1 ms 596 KB Output is correct
55 Correct 1 ms 596 KB Output is correct
56 Correct 1 ms 596 KB Output is correct
57 Correct 0 ms 596 KB Output is correct
58 Correct 1 ms 596 KB Output is correct
59 Correct 0 ms 596 KB Output is correct
60 Correct 1 ms 596 KB Output is correct
61 Correct 0 ms 596 KB Output is correct
62 Correct 1 ms 596 KB Output is correct
63 Correct 1 ms 596 KB Output is correct
64 Correct 0 ms 596 KB Output is correct
65 Correct 1 ms 596 KB Output is correct
66 Correct 1 ms 596 KB Output is correct
67 Correct 1 ms 596 KB Output is correct
68 Correct 0 ms 596 KB Output is correct
69 Correct 0 ms 596 KB Output is correct
70 Correct 1 ms 596 KB Output is correct
71 Correct 1 ms 668 KB Output is correct
72 Correct 1 ms 596 KB Output is correct
73 Correct 1 ms 596 KB Output is correct
74 Correct 1 ms 724 KB Output is correct
75 Correct 1 ms 596 KB Output is correct
76 Correct 1 ms 596 KB Output is correct
77 Correct 1 ms 596 KB Output is correct
78 Correct 1 ms 596 KB Output is correct
79 Correct 1 ms 596 KB Output is correct
80 Correct 1 ms 596 KB Output is correct
81 Correct 1 ms 668 KB Output is correct
82 Correct 1 ms 668 KB Output is correct
83 Correct 1 ms 596 KB Output is correct
84 Correct 1 ms 596 KB Output is correct
85 Correct 1 ms 596 KB Output is correct
86 Correct 1 ms 664 KB Output is correct
87 Correct 1 ms 668 KB Output is correct
88 Correct 1 ms 596 KB Output is correct
89 Correct 1 ms 596 KB Output is correct
90 Correct 3 ms 664 KB Output is correct
91 Correct 1 ms 596 KB Output is correct
92 Correct 1 ms 596 KB Output is correct
93 Correct 1 ms 596 KB Output is correct
94 Incorrect 1 ms 596 KB Output isn't correct
95 Halted 0 ms 0 KB -