답안 #435931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
435931 2021-06-24T01:40:13 Z dqhungdl 사탕 분배 (IOI21_candies) C++17
29 / 100
171 ms 12100 KB
#include "candies.h"

#include <bits/stdc++.h>
using namespace std;

std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
    int n=c.size(),m=v.size();
	vector<long long> S(m+1),Pmin(m+1),Pmax(m+1);
	S[1]=v[0];
	for(int i=2;i<=m;i++)
		S[i]=S[i-1]+v[i-1];
	Pmin.back()=Pmax.back()=S.back();
	for(int i=m-1;i>=0;i--) {
		Pmin[i]=min(Pmin[i+1],S[i]);
		Pmax[i]=max(Pmax[i+1],S[i]);
	}
	vector<int> rs(n);
	for(int i=0;i<n;i++) {
		// If all updates are in range
		if(Pmax[0]-Pmin[0]<=c[i]) {
			int l=1,r=m,pivot=0;
			long long limit=Pmin[0];
			while(l<=r) {
				int mid=(l+r)/2;
				if(Pmin[mid]==limit) {
					l=mid+1;
					pivot=mid;
				}
				else
					r=mid-1;
			}
			rs[i]=S.back()-S[pivot];
			continue;
		}
		int l=0,r=m,pivot;
		while(l<=r) {
			int mid=(l+r)/2;
			if(Pmax[mid]-Pmin[mid]>c[i]) {
				pivot=mid;
				l=mid+1;
			} else
				r=mid-1;
		}
		// Find the last time touching the upper wall
		if(Pmin[pivot]==S[pivot]) {
			l=pivot+1,r=m;
			long long limit=Pmax[pivot];
			while(l<=r) {
				int mid=(l+r)/2;
				if(Pmax[mid]==limit) {
					pivot=mid;
					l=mid+1;
				} else
					r=mid-1;
			}
			rs[i]=c[i]+S.back()-S[pivot];
		} else { // Find the last time touching the lower wall
			l=pivot+1,r=m;
			long long limit=Pmin[pivot];
			while(l<=r) {
				int mid=(l+r)/2;
				if(Pmin[mid]==limit) {
					pivot=mid;
					l=mid+1;
				} else
					r=mid-1;
			}
			rs[i]=S.back()-S[pivot];
		}
	}
	return rs;
}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:47:5: warning: 'pivot' may be used uninitialized in this function [-Wmaybe-uninitialized]
   47 |    l=pivot+1,r=m;
      |    ~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 149 ms 12000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 65 ms 9688 KB Output is correct
4 Correct 70 ms 2852 KB Output is correct
5 Correct 171 ms 11960 KB Output is correct
6 Correct 151 ms 12100 KB Output is correct
7 Correct 139 ms 12012 KB Output is correct
8 Correct 135 ms 11972 KB Output is correct
9 Correct 142 ms 11972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -