답안 #1002860

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1002860 2024-06-19T20:52:42 Z leanchec Autobahn (COI21_autobahn) C++17
0 / 100
3 ms 6236 KB
#include<bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, k, x;
	cin >> n >> k >> x;

	vector<pair<int,int>> sweep;
	sweep.push_back({0, 0});
	int qtd[300100]={}, il[300100]={}, c[300100]={};

	for(int i=0; i<n; i++){
		int l, t, r;
		cin >> l >> t >> r;
		sweep.push_back({l, 0});
		sweep.push_back({min(l+t-1, r), 1});
		sweep.push_back({r, 2});
	}

	sort(sweep.begin(), sweep.end());

	for(int i=1; i<sweep.size(); i++){
		if(qtd[i-1]>=k){
			c[i]=il[i-1]*(sweep[i].first-sweep[i-1].first);
		}
		if(sweep[i].second==0){
			qtd[i]=qtd[i-1]+1;
			il[i]=il[i-1];
		}
		else if(sweep[i].second==1){
			qtd[i]=qtd[i-1];
			il[i]=il[i-1]+1;
		}
		else{
			qtd[i]=qtd[i-1]-1;
			il[i]=il[i-1]-1;
		}
	}

	int pref[300100]={}, suf[300100]={};

	for(int i=1; i<sweep.size(); i++){
		pref[i]=pref[i-1]+c[i];
	}
	for(int i=sweep.size()-2; i>0; i--){
		suf[i]=suf[i+1]+c[i+1];
	}

	int resp=0;
	for(int i=1; i<sweep.size(); i++){
		if(sweep[i].first<=x)resp=max(resp, pref[i]);
		else{
			int ini=1, fim=i;
			int pos=0;
			while(ini<=fim){
				int mid=(ini+fim)/2;

				if(sweep[i].first-sweep[mid].first<=x){
					pos=mid;
					fim=mid-1;
				}
				else ini=mid+1;
			}

			int cr=pref[i]-pref[pos];
			cr+=(qtd[pos-1]>=k)*il[pos-1]*(x-(sweep[i].first-sweep[pos].first));
			if(pos!=0)resp=max(resp, cr);
		}
		if(sweep.back().first-sweep[i].first<=x)resp=max(resp, suf[i]);
		else{
			int ini=i, fim=sweep.size()-2;
			int pos=0;

			while(ini<=fim){
				int mid=(ini+fim)/2;

				if(sweep[mid].first-sweep[i].first<=x){
					pos=mid;
					ini=mid+1;
				}
				else fim=mid-1;
			}
			int cr=suf[i]-suf[pos];
			cr+=(qtd[pos]>=k)*il[pos]*(x-(sweep[pos].first-sweep[i].first));
			if(pos!=0)resp=max(cr, resp);
		}
	}

	cout << resp << '\n';
}

Compilation message

autobahn.cpp: In function 'int main()':
autobahn.cpp:23:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for(int i=1; i<sweep.size(); i++){
      |               ~^~~~~~~~~~~~~
autobahn.cpp:43:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for(int i=1; i<sweep.size(); i++){
      |               ~^~~~~~~~~~~~~
autobahn.cpp:51:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for(int i=1; i<sweep.size(); i++){
      |               ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6236 KB Output is correct
2 Correct 3 ms 6236 KB Output is correct
3 Correct 3 ms 6236 KB Output is correct
4 Incorrect 3 ms 6184 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6236 KB Output is correct
2 Correct 3 ms 6236 KB Output is correct
3 Correct 3 ms 6236 KB Output is correct
4 Incorrect 3 ms 6184 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6236 KB Output is correct
2 Correct 3 ms 6236 KB Output is correct
3 Correct 3 ms 6236 KB Output is correct
4 Incorrect 3 ms 6184 KB Output isn't correct
5 Halted 0 ms 0 KB -