Submission #639518

# Submission time Handle Problem Language Result Execution time Memory
639518 2022-09-10T11:54:22 Z Benmath A Difficult(y) Choice (BOI21_books) C++14
60 / 100
2 ms 1072 KB
#include <bits/stdc++.h>
 
#include "books.h"
 
using namespace std;
//
// --- Sample implementation for the task books ---
//
// To compile this program with the sample grader, place:
//     books.h books_sample.cpp sample_grader.cpp
// in a single folder and run:
//     g++ books_sample.cpp sample_grader.cpp
// in this folder.
//
 
void solve(int N, int K, long long A, int S) {
    // TODO implement this function
  long long  int so[N+1];
    for(int i=0;i<=N;i++){
    	so[i]=-1;
	}
    int l=1;
    int r=N;
    int t1=N;
    int brojac=0;
    while(l<=r){
    	int mid=l+(r-l)/2;
   so[mid]=skim(mid);
   
   brojac++;
	if(so[mid]>A){
	
		t1=min(t1,mid);
		r=mid-1;
	}else{
		l=mid+1;
	}
	}

	long long int sum1=0;
	long long int sum=0;
	for(int i=1;i<=K;i++){
		if(so[i]==-1){
		
		so[i]=skim(i);
	}
		sum1=sum1+so[i];
	}
	if(sum1>2*A){
		impossible();
		return;
	}else if(sum1>=A){
		vector<int>v;
		for(int i=1;i<=K;i++){
			v.push_back(i);
		}
		answer(v);
		return;
	}else{
		vector<int>v;
		sum=0;
		for(int i=1;i<K;i++){
			sum=sum+so[i];
			v.push_back(i);
		}
		sum=sum+so[t1];
		v.push_back(t1);
		if(sum>=A and sum<=2*A){
			answer(v);
			return;
		}
		
		vector<int>v1;
		sum=0;
		for(int i=t1-K+1;i<=t1;i++){
		
			if(so[i]==-1){
				so[i]=skim(i);
			}
			sum=sum+so[i];
			v1.push_back(i);
		}
		if(sum>=A and sum<=2*A){
			answer(v1);
			return;
		}
		
		vector<int>v2;
		sum=0;
		if(t1>K){
		
		for(int i=t1-K;i<=(t1-1);i++){
			if(so[i]==-1){
				so[i]=skim(i);
			}
			sum=sum+so[i];
			v2.push_back(i);
		}
		if(sum>=A and sum<=2*A){
			answer(v2);
			return;
		}
	}
	}
	impossible();
	/*
	if(t1==(N+1)){
		impossible();
		return;
	}else{
		long long int sum=0;
		vector<int>v;
		for(int i=1;i<K;i++){
			v.push_back(i);
			long long int r=so[i];
			if(r==-1){
				r=skim(i);
				so[i]=r;
			}
			sum=sum+r;
		}
		v.push_back(t1+K-1);
		long long int r1=so[t1+K-1];
		if(r1==-1){
			r1=skim(t1+K-1);
		}
		sum=sum+r1;
		if(sum<=2*A){
			answer(v);
		}else{
			impossible();
		}
	}
	/*
    int n=N;
  long long int arr[n];
  for(int i=0;i<n;i++){
    arr[i]=skim(i+1);
  }
  long long int sum=0;
  for(int i=0;i<K;i++){
    sum=sum+arr[i];
  }
  if(sum>=A and sum<=2*A){
    vector<int>v;
    for(int i=0;i<K;i++){
        v.push_back(i+1);
    }
    answer(v);
    return;
  }
  for(int i=K;i<N;i++){
    sum=sum+arr[i]-arr[i-K];
    if(sum>=A and sum<=2*A){
    vector<int>v;
    for(int j=i-K+1;j<=i;j++){
        v.push_back(j+1);
    }
    answer(v);
    return;
  }
  if(sum>2*A){
    sum=0;
    vector<int>v;
    for(int j=0;j<(K-1);j++){
        sum=sum+arr[j];
        v.push_back(j+1);
    }
    v.push_back(i+1);
    sum=sum+arr[i];
    if(sum>=A and sum<=2*A){
        answer(v);
        return ;
    }else{
    impossible();
    return;
    }
  }
  }
  impossible();
  */
}

Compilation message

books.cpp:134:2: warning: "/*" within comment [-Wcomment]
  134 |  /*
      |
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 416 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 420 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 976 KB Output is correct
2 Correct 1 ms 976 KB Output is correct
3 Correct 2 ms 976 KB Output is correct
4 Correct 1 ms 976 KB Output is correct
5 Correct 1 ms 1056 KB Output is correct
6 Correct 1 ms 976 KB Output is correct
7 Correct 1 ms 976 KB Output is correct
8 Correct 1 ms 976 KB Output is correct
9 Correct 1 ms 1060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 976 KB Output is correct
2 Correct 1 ms 976 KB Output is correct
3 Correct 2 ms 976 KB Output is correct
4 Correct 1 ms 976 KB Output is correct
5 Correct 1 ms 1056 KB Output is correct
6 Correct 1 ms 976 KB Output is correct
7 Correct 1 ms 976 KB Output is correct
8 Correct 1 ms 976 KB Output is correct
9 Correct 1 ms 1060 KB Output is correct
10 Correct 1 ms 976 KB Output is correct
11 Correct 1 ms 1060 KB Output is correct
12 Correct 1 ms 1064 KB Output is correct
13 Correct 1 ms 976 KB Output is correct
14 Correct 1 ms 1060 KB Output is correct
15 Correct 1 ms 1060 KB Output is correct
16 Correct 1 ms 1060 KB Output is correct
17 Correct 1 ms 1060 KB Output is correct
18 Correct 1 ms 1060 KB Output is correct
19 Correct 1 ms 1060 KB Output is correct
20 Correct 1 ms 976 KB Output is correct
21 Correct 1 ms 976 KB Output is correct
22 Correct 1 ms 1056 KB Output is correct
23 Correct 1 ms 976 KB Output is correct
24 Correct 1 ms 1052 KB Output is correct
25 Correct 1 ms 1056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 976 KB Output is correct
2 Correct 1 ms 976 KB Output is correct
3 Correct 2 ms 976 KB Output is correct
4 Correct 1 ms 976 KB Output is correct
5 Correct 1 ms 1056 KB Output is correct
6 Correct 1 ms 976 KB Output is correct
7 Correct 1 ms 976 KB Output is correct
8 Correct 1 ms 976 KB Output is correct
9 Correct 1 ms 1060 KB Output is correct
10 Correct 1 ms 976 KB Output is correct
11 Correct 1 ms 1060 KB Output is correct
12 Correct 1 ms 1064 KB Output is correct
13 Correct 1 ms 976 KB Output is correct
14 Correct 1 ms 1060 KB Output is correct
15 Correct 1 ms 1060 KB Output is correct
16 Correct 1 ms 1060 KB Output is correct
17 Correct 1 ms 1060 KB Output is correct
18 Correct 1 ms 1060 KB Output is correct
19 Correct 1 ms 1060 KB Output is correct
20 Correct 1 ms 976 KB Output is correct
21 Correct 1 ms 976 KB Output is correct
22 Correct 1 ms 1056 KB Output is correct
23 Correct 1 ms 976 KB Output is correct
24 Correct 1 ms 1052 KB Output is correct
25 Correct 1 ms 1056 KB Output is correct
26 Correct 1 ms 1064 KB Output is correct
27 Correct 1 ms 976 KB Output is correct
28 Correct 2 ms 1056 KB Output is correct
29 Correct 1 ms 976 KB Output is correct
30 Correct 1 ms 1028 KB Output is correct
31 Correct 1 ms 1060 KB Output is correct
32 Correct 1 ms 1060 KB Output is correct
33 Correct 1 ms 1060 KB Output is correct
34 Correct 1 ms 1056 KB Output is correct
35 Correct 1 ms 1052 KB Output is correct
36 Correct 1 ms 976 KB Output is correct
37 Correct 1 ms 976 KB Output is correct
38 Correct 1 ms 1060 KB Output is correct
39 Correct 1 ms 976 KB Output is correct
40 Correct 1 ms 976 KB Output is correct
41 Correct 1 ms 976 KB Output is correct
42 Correct 1 ms 976 KB Output is correct
43 Correct 1 ms 976 KB Output is correct
44 Correct 1 ms 976 KB Output is correct
45 Correct 1 ms 976 KB Output is correct
46 Correct 1 ms 1060 KB Output is correct
47 Correct 1 ms 976 KB Output is correct
48 Correct 1 ms 976 KB Output is correct
49 Correct 1 ms 1064 KB Output is correct
50 Correct 1 ms 1064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 976 KB Output is correct
2 Correct 1 ms 976 KB Output is correct
3 Correct 2 ms 976 KB Output is correct
4 Correct 1 ms 976 KB Output is correct
5 Correct 1 ms 1056 KB Output is correct
6 Correct 1 ms 976 KB Output is correct
7 Correct 1 ms 976 KB Output is correct
8 Correct 1 ms 976 KB Output is correct
9 Correct 1 ms 1060 KB Output is correct
10 Correct 1 ms 976 KB Output is correct
11 Correct 1 ms 1060 KB Output is correct
12 Correct 1 ms 1064 KB Output is correct
13 Correct 1 ms 976 KB Output is correct
14 Correct 1 ms 1060 KB Output is correct
15 Correct 1 ms 1060 KB Output is correct
16 Correct 1 ms 1060 KB Output is correct
17 Correct 1 ms 1060 KB Output is correct
18 Correct 1 ms 1060 KB Output is correct
19 Correct 1 ms 1060 KB Output is correct
20 Correct 1 ms 976 KB Output is correct
21 Correct 1 ms 976 KB Output is correct
22 Correct 1 ms 1056 KB Output is correct
23 Correct 1 ms 976 KB Output is correct
24 Correct 1 ms 1052 KB Output is correct
25 Correct 1 ms 1056 KB Output is correct
26 Correct 1 ms 976 KB Output is correct
27 Correct 1 ms 1060 KB Output is correct
28 Correct 1 ms 1024 KB Output is correct
29 Correct 1 ms 1060 KB Output is correct
30 Correct 1 ms 976 KB Output is correct
31 Correct 1 ms 976 KB Output is correct
32 Correct 1 ms 976 KB Output is correct
33 Correct 1 ms 1060 KB Output is correct
34 Correct 1 ms 976 KB Output is correct
35 Correct 1 ms 1056 KB Output is correct
36 Correct 1 ms 1064 KB Output is correct
37 Correct 1 ms 1056 KB Output is correct
38 Correct 1 ms 1072 KB Output is correct
39 Correct 1 ms 976 KB Output is correct
40 Correct 1 ms 1068 KB Output is correct
41 Correct 1 ms 976 KB Output is correct
42 Correct 1 ms 1056 KB Output is correct
43 Correct 1 ms 976 KB Output is correct
44 Correct 1 ms 976 KB Output is correct
45 Correct 1 ms 976 KB Output is correct
46 Incorrect 1 ms 976 KB Incorrect
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 976 KB Output is correct
2 Correct 1 ms 976 KB Output is correct
3 Correct 2 ms 976 KB Output is correct
4 Correct 1 ms 976 KB Output is correct
5 Correct 1 ms 1056 KB Output is correct
6 Correct 1 ms 976 KB Output is correct
7 Correct 1 ms 976 KB Output is correct
8 Correct 1 ms 976 KB Output is correct
9 Correct 1 ms 1060 KB Output is correct
10 Correct 1 ms 976 KB Output is correct
11 Correct 1 ms 1060 KB Output is correct
12 Correct 1 ms 1064 KB Output is correct
13 Correct 1 ms 976 KB Output is correct
14 Correct 1 ms 1060 KB Output is correct
15 Correct 1 ms 1060 KB Output is correct
16 Correct 1 ms 1060 KB Output is correct
17 Correct 1 ms 1060 KB Output is correct
18 Correct 1 ms 1060 KB Output is correct
19 Correct 1 ms 1060 KB Output is correct
20 Correct 1 ms 976 KB Output is correct
21 Correct 1 ms 976 KB Output is correct
22 Correct 1 ms 1056 KB Output is correct
23 Correct 1 ms 976 KB Output is correct
24 Correct 1 ms 1052 KB Output is correct
25 Correct 1 ms 1056 KB Output is correct
26 Correct 1 ms 1064 KB Output is correct
27 Correct 1 ms 976 KB Output is correct
28 Correct 2 ms 1056 KB Output is correct
29 Correct 1 ms 976 KB Output is correct
30 Correct 1 ms 1028 KB Output is correct
31 Correct 1 ms 1060 KB Output is correct
32 Correct 1 ms 1060 KB Output is correct
33 Correct 1 ms 1060 KB Output is correct
34 Correct 1 ms 1056 KB Output is correct
35 Correct 1 ms 1052 KB Output is correct
36 Correct 1 ms 976 KB Output is correct
37 Correct 1 ms 976 KB Output is correct
38 Correct 1 ms 1060 KB Output is correct
39 Correct 1 ms 976 KB Output is correct
40 Correct 1 ms 976 KB Output is correct
41 Correct 1 ms 976 KB Output is correct
42 Correct 1 ms 976 KB Output is correct
43 Correct 1 ms 976 KB Output is correct
44 Correct 1 ms 976 KB Output is correct
45 Correct 1 ms 976 KB Output is correct
46 Correct 1 ms 1060 KB Output is correct
47 Correct 1 ms 976 KB Output is correct
48 Correct 1 ms 976 KB Output is correct
49 Correct 1 ms 1064 KB Output is correct
50 Correct 1 ms 1064 KB Output is correct
51 Correct 1 ms 976 KB Output is correct
52 Correct 1 ms 1060 KB Output is correct
53 Correct 1 ms 1024 KB Output is correct
54 Correct 1 ms 1060 KB Output is correct
55 Correct 1 ms 976 KB Output is correct
56 Correct 1 ms 976 KB Output is correct
57 Correct 1 ms 976 KB Output is correct
58 Correct 1 ms 1060 KB Output is correct
59 Correct 1 ms 976 KB Output is correct
60 Correct 1 ms 1056 KB Output is correct
61 Correct 1 ms 1064 KB Output is correct
62 Correct 1 ms 1056 KB Output is correct
63 Correct 1 ms 1072 KB Output is correct
64 Correct 1 ms 976 KB Output is correct
65 Correct 1 ms 1068 KB Output is correct
66 Correct 1 ms 976 KB Output is correct
67 Correct 1 ms 1056 KB Output is correct
68 Correct 1 ms 976 KB Output is correct
69 Correct 1 ms 976 KB Output is correct
70 Correct 1 ms 976 KB Output is correct
71 Incorrect 1 ms 976 KB Incorrect
72 Halted 0 ms 0 KB -