답안 #434917

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
434917 2021-06-22T09:01:49 Z dqhungdl Autobahn (COI21_autobahn) C++17
100 / 100
75 ms 15416 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

typedef pair<int,int> ii;
int N,K,X;
vector<ii> events,overtime,charge;

int read() {
	char c=getchar();
	while(!isdigit(c))
		c=getchar();
	int rs=0;
	while(isdigit(c)) {
		rs=rs*10+c-'0';
		c=getchar();
	}
	return rs;
}

int32_t main() {
#ifdef ACM
	freopen("input","r",stdin);
#endif
	N=read(),K=read(),X=read();
	int l,t,r;
	for(int i=0;i<N;i++) {
		l=read(),t=read(),r=read();
		if(l+t<=r) {
			overtime.push_back({l+t,1});
			overtime.push_back({r+1,-1});
		}
		events.push_back({l,1});
		events.push_back({r+1,-1});
	}
	sort(events.begin(),events.end());
	int people=0,pivot;
	for(ii event:events) {
		people+=event.second;
		if(event.second==1&&people==K)
			pivot=event.first;
		else if(event.second==-1&&people==K-1) {
			overtime.push_back({pivot,2});
			overtime.push_back({event.first,-2});
		}
	}
	sort(overtime.begin(),overtime.end());
	//for(ii tmp:overtime)
	//	cerr<<tmp.first<<' '<<tmp.second<<'\n';
	int numOvertime=0;
	bool overload=false;
	for(ii event:overtime) {
		if(abs(event.second)==1)
			numOvertime+=event.second;
		else
			overload=(event.second==2);
		if(overload) {
			if(charge.size()>0&&charge.back().first==event.first)
				charge.back().second=numOvertime;
			else
				charge.push_back({event.first,numOvertime});
		}
		else if(charge.size()>0&&charge.back().first==event.first)
			charge.back().second=0;
		else
			charge.push_back({event.first,0});
	}
	//for(ii tmp:charge)
	//	cerr<<tmp.first<<' '<<tmp.second<<'\n';
	vector<int> S(charge.size());
	for(int i=0;i<charge.size()-1;i++) {
		S[i]=(charge[i+1].first-charge[i].first)*charge[i].second;
		if(i>0)
			S[i]+=S[i-1];
	}
	int cur=0,rs=0;
	for(int i=0;i<charge.size()-1;i++) {
		while(cur<charge.size()-1&&charge[cur+1].first<=charge[i].first+X-1)
			cur++;
		int sum=0;
		if(cur>0)
			sum=S[cur-1]-(i==0?0:S[i-1]);
		sum+=(charge[i].first+X-charge[cur].first)*charge[cur].second;
		rs=max(rs,sum);
	}
	cur=0;
	for(int i=0;i<charge.size()-1;i++) {
		while(cur<i&&charge[cur].first+X<charge[i+1].first)
			cur++;
		int sum=S[i]-(cur==0?0:S[cur-1]);
		if(cur>0)
			sum+=(charge[cur].first-charge[i+1].first+X)*charge[cur-1].second;
		rs=max(rs,sum);
	}
	cout<<rs;
}

Compilation message

autobahn.cpp: In function 'int32_t main()':
autobahn.cpp:71:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |  for(int i=0;i<charge.size()-1;i++) {
      |              ~^~~~~~~~~~~~~~~~
autobahn.cpp:77:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |  for(int i=0;i<charge.size()-1;i++) {
      |              ~^~~~~~~~~~~~~~~~
autobahn.cpp:78:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |   while(cur<charge.size()-1&&charge[cur+1].first<=charge[i].first+X-1)
      |         ~~~^~~~~~~~~~~~~~~~
autobahn.cpp:87:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |  for(int i=0;i<charge.size()-1;i++) {
      |              ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 73 ms 12736 KB Output is correct
22 Correct 75 ms 15356 KB Output is correct
23 Correct 75 ms 15372 KB Output is correct
24 Correct 70 ms 15392 KB Output is correct
25 Correct 72 ms 15416 KB Output is correct
26 Correct 70 ms 15384 KB Output is correct
27 Correct 75 ms 15380 KB Output is correct
28 Correct 70 ms 15336 KB Output is correct
29 Correct 70 ms 15332 KB Output is correct