Submission #411134

# Submission time Handle Problem Language Result Execution time Memory
411134 2021-05-24T12:15:04 Z blacktulip A Difficult(y) Choice (BOI21_books) C++17
65 / 100
632 ms 792 KB
#include <bits/stdc++.h>
 
#include "books.h"
 
using namespace std;
typedef long long int lo;
typedef pair<int,int> PII;
 
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
 
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;
 
lo a[li],PS[li];
int cev;
vector<int> v;
 
void solve(int N, int K, long long A, int S) {
    lo sum=0;
    if(S==N){
		for(int i=1;i<=N;i++){a[i]=skim(i);PS[i]=PS[i-1]+a[i];}
		for(int i=1;i<=N;i++){
			if(i+K-1>N)break;
			lo at=0;
			for(int j=i;j<i+K;j++)at+=a[j];
			int r=i+K-1;
			int flag=0;
			while(r<N && at<A){flag=1;at-=a[r];r++;at+=a[r];}
			if(at>=A && at<=2*A){
				for(int j=i;j<i+K;j++)v.pb(j);
				v[K-1]=r;
				answer(v);
			}
			if(flag==0){
				int l=i;
				while(l>1 && at>2*A){at-=a[l];l--;at+=a[l];}
				if(at>=A && at<=2*A){
					for(int j=i;j<i+K;j++)v.pb(j);
					v[0]=l;
					answer(v);
				}
			}
		}
		impossible();
	}
    //~ cout<<"***\n";
    for(int i=N;i>=N-K+1;i--){
		a[i]=skim(i);
		sum+=a[i];
		v.pb(i);
	}
	//~ cout<<"***\n";
	if(sum<A){impossible();}
	for(int i=0;i<(int)v.size();i++){
		if(sum<=2*A)break;
		if(a[i+1]==0)a[i+1]=skim(i+1);
		if(sum-a[v[i]]+a[i+1]>=A){
			sum-=a[v[i]];
			v[i]=i+1;
			sum+=a[v[i]];
			continue;
		}
		int bas=i+2;
		int son=N-K;;
		while(bas<=son){
			//~ cout<<ort<<" :: "<<bas<<" :: "<<son<<endl;
			if(a[ort]==0)a[ort]=skim(ort);
			if(sum-a[v[i]]+a[ort]<A)bas=ort+1;
			else son=ort-1;
		}
		sum-=a[v[i]];
		son=min(bas,N-K);
		if(a[bas]==0)a[bas]=skim(bas);
		sum+=a[bas];
		v[i]=bas;
	}
	if(sum<A || sum>2*A)impossible();
	else answer(v);
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 200 KB Output is correct
2 Correct 14 ms 296 KB Output is correct
3 Correct 13 ms 316 KB Output is correct
4 Correct 13 ms 316 KB Output is correct
5 Correct 9 ms 324 KB Output is correct
6 Correct 10 ms 308 KB Output is correct
7 Correct 9 ms 200 KB Output is correct
8 Correct 14 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 200 KB Output is correct
2 Correct 9 ms 200 KB Output is correct
3 Correct 9 ms 200 KB Output is correct
4 Correct 10 ms 200 KB Output is correct
5 Correct 7 ms 316 KB Output is correct
6 Correct 14 ms 320 KB Output is correct
7 Correct 12 ms 312 KB Output is correct
8 Correct 13 ms 200 KB Output is correct
9 Correct 252 ms 784 KB Output is correct
10 Correct 279 ms 628 KB Output is correct
11 Correct 259 ms 700 KB Output is correct
12 Correct 632 ms 724 KB Output is correct
13 Correct 214 ms 792 KB Output is correct
14 Correct 238 ms 632 KB Output is correct
15 Correct 231 ms 680 KB Output is correct
16 Correct 597 ms 704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 280 KB Output is correct
2 Correct 1 ms 276 KB Output is correct
3 Correct 1 ms 276 KB Output is correct
4 Correct 1 ms 272 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 280 KB Output is correct
2 Correct 1 ms 276 KB Output is correct
3 Correct 1 ms 276 KB Output is correct
4 Correct 1 ms 272 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 276 KB Output is correct
10 Correct 1 ms 276 KB Output is correct
11 Correct 2 ms 296 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 276 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 1 ms 292 KB Output is correct
17 Correct 1 ms 200 KB Output is correct
18 Correct 1 ms 200 KB Output is correct
19 Correct 1 ms 220 KB Output is correct
20 Correct 2 ms 292 KB Output is correct
21 Correct 2 ms 296 KB Output is correct
22 Correct 1 ms 200 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 280 KB Output is correct
2 Correct 1 ms 276 KB Output is correct
3 Correct 1 ms 276 KB Output is correct
4 Correct 1 ms 272 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 276 KB Output is correct
10 Correct 1 ms 276 KB Output is correct
11 Correct 2 ms 296 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 276 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 1 ms 292 KB Output is correct
17 Correct 1 ms 200 KB Output is correct
18 Correct 1 ms 200 KB Output is correct
19 Correct 1 ms 220 KB Output is correct
20 Correct 2 ms 292 KB Output is correct
21 Correct 2 ms 296 KB Output is correct
22 Correct 1 ms 200 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 1 ms 200 KB Output is correct
27 Correct 1 ms 200 KB Output is correct
28 Correct 1 ms 292 KB Output is correct
29 Correct 1 ms 412 KB Output is correct
30 Correct 1 ms 280 KB Output is correct
31 Correct 1 ms 288 KB Output is correct
32 Correct 1 ms 300 KB Output is correct
33 Correct 1 ms 292 KB Output is correct
34 Correct 1 ms 200 KB Output is correct
35 Correct 1 ms 200 KB Output is correct
36 Correct 1 ms 288 KB Output is correct
37 Correct 1 ms 292 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 296 KB Output is correct
40 Correct 1 ms 328 KB Output is correct
41 Correct 1 ms 296 KB Output is correct
42 Correct 1 ms 288 KB Output is correct
43 Correct 1 ms 288 KB Output is correct
44 Correct 1 ms 200 KB Output is correct
45 Correct 1 ms 276 KB Output is correct
46 Correct 1 ms 288 KB Output is correct
47 Incorrect 1 ms 292 KB Incorrect
48 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 280 KB Output is correct
2 Correct 1 ms 276 KB Output is correct
3 Correct 1 ms 276 KB Output is correct
4 Correct 1 ms 272 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 276 KB Output is correct
10 Correct 1 ms 276 KB Output is correct
11 Correct 2 ms 296 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 276 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 1 ms 292 KB Output is correct
17 Correct 1 ms 200 KB Output is correct
18 Correct 1 ms 200 KB Output is correct
19 Correct 1 ms 220 KB Output is correct
20 Correct 2 ms 292 KB Output is correct
21 Correct 2 ms 296 KB Output is correct
22 Correct 1 ms 200 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 1 ms 200 KB Output is correct
27 Correct 1 ms 292 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 1 ms 292 KB Output is correct
30 Correct 1 ms 292 KB Output is correct
31 Correct 1 ms 292 KB Output is correct
32 Correct 1 ms 292 KB Output is correct
33 Correct 1 ms 200 KB Output is correct
34 Correct 1 ms 304 KB Output is correct
35 Correct 1 ms 200 KB Output is correct
36 Correct 2 ms 320 KB Output is correct
37 Correct 1 ms 328 KB Output is correct
38 Correct 1 ms 292 KB Output is correct
39 Correct 1 ms 328 KB Output is correct
40 Correct 1 ms 328 KB Output is correct
41 Correct 1 ms 288 KB Output is correct
42 Correct 1 ms 276 KB Output is correct
43 Correct 1 ms 296 KB Output is correct
44 Correct 1 ms 296 KB Output is correct
45 Correct 1 ms 288 KB Output is correct
46 Correct 1 ms 292 KB Output is correct
47 Correct 1 ms 200 KB Output is correct
48 Correct 1 ms 292 KB Output is correct
49 Correct 1 ms 300 KB Output is correct
50 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 280 KB Output is correct
2 Correct 1 ms 276 KB Output is correct
3 Correct 1 ms 276 KB Output is correct
4 Correct 1 ms 272 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 276 KB Output is correct
10 Correct 1 ms 276 KB Output is correct
11 Correct 2 ms 296 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 276 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 1 ms 292 KB Output is correct
17 Correct 1 ms 200 KB Output is correct
18 Correct 1 ms 200 KB Output is correct
19 Correct 1 ms 220 KB Output is correct
20 Correct 2 ms 292 KB Output is correct
21 Correct 2 ms 296 KB Output is correct
22 Correct 1 ms 200 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 1 ms 200 KB Output is correct
27 Correct 1 ms 200 KB Output is correct
28 Correct 1 ms 292 KB Output is correct
29 Correct 1 ms 412 KB Output is correct
30 Correct 1 ms 280 KB Output is correct
31 Correct 1 ms 288 KB Output is correct
32 Correct 1 ms 300 KB Output is correct
33 Correct 1 ms 292 KB Output is correct
34 Correct 1 ms 200 KB Output is correct
35 Correct 1 ms 200 KB Output is correct
36 Correct 1 ms 288 KB Output is correct
37 Correct 1 ms 292 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 296 KB Output is correct
40 Correct 1 ms 328 KB Output is correct
41 Correct 1 ms 296 KB Output is correct
42 Correct 1 ms 288 KB Output is correct
43 Correct 1 ms 288 KB Output is correct
44 Correct 1 ms 200 KB Output is correct
45 Correct 1 ms 276 KB Output is correct
46 Correct 1 ms 288 KB Output is correct
47 Incorrect 1 ms 292 KB Incorrect
48 Halted 0 ms 0 KB -