답안 #416607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
416607 2021-06-02T17:00:24 Z REALITYNB Autobahn (COI21_autobahn) C++14
0 / 100
2 ms 332 KB
#include <bits/stdc++.h> 
#define int long long 
#define inf 1e18
#define all(a) a.begin(),a.end()
using namespace std; 
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);
	#ifndef ONLINE_JUDGE 
		freopen("in.txt","r",stdin); 
		freopen("out.txt","w",stdout); 
	#endif 
	int n,k,x ; 
	cin>>n>>k>>x;
	vector<int> l(n) ,t(n) , r(n) , events ; 
	for(int i=0;i<n;i++){
		cin>>l[i]>>t[i]>>r[i] ; 
		int le = l[i],re=r[i],rr  = l[i]+t[i]-1 ; 
		events.push_back(le) ; 
		events.push_back(re) ; 
		events.push_back(re+1) ; 
		events.push_back(rr+1) ; 
		events.push_back(re-x+1) ; 
		events.push_back(rr-x+1) ; 
		events.push_back(le-x+1); 
	}
	events.push_back(inf) ; 
	sort(all(events)) ; 
	auto it = unique(all(events)) ; 
	events.resize(distance(events.begin(),it)) ; 

	vector<int> illegals(events.size()) ; 
	vector<int> num(events.size()) ; 
	for(int i=0;i<n;i++){
		int j = lower_bound(all(events),l[i])-events.begin() ; 
		num[j]++ ; 
		int k = lower_bound(all(events),r[i]+1)-events.begin() ; 
		num[k]-- ; 
	}
	for(int i=0;i<n;i++){
		int le = l[i],re=r[i] ,rr=l[i]+t[i]-1 ; 
		if(rr<=re){
			int j = lower_bound(all(events),rr+1)-events.begin(); 
			illegals[j]++; 
			j = lower_bound(all(events),re+1)-events.begin() ; 
			illegals[j]--; 
		}
	}
	for(int i=1;i<events.size();i++) num[i]+=num[i-1],illegals[i]+=illegals[i-1] ; 
	int curl = events[0] , curr =-inf, val = 0 , j = 0 , ans = 0 ;  
/*	for(int i=0;i<events.size();i++){
		cout << "minute :" << events[i] << " " << num[i] << "  "<< illegals[i] << endl ; 
	}*/
	cout << endl ; 
	for(int i=0;i+1<events.size();i++){
		curl=events[i] ; 
		if(curr<curl){
			curr = curl ; 
			val = (num[i]>=k)*illegals[i]; 
			j=i ; 
		}
		else{
			val-=(events[i]-events[i-1])*(illegals[i-1])*(num[i-1]>=k) ; 
		}
		while(curr-curl+1<x){
			if(events[j]-curl>=x){
				val+=(curl+x-1-curr)*(illegals[j-1])*(num[j-1]>=k) ; 
				curr = curl+x-1 ; 
				break ; 
			}
			++j; 
			val+=(min(events[j]-1,curl+x-1)-curr)*(num[j-1]>=k)*illegals[j-1] ; 
			curr = min(events[j]-1,curl+x-1) ; 
		}
		ans=max(ans,val) ; 
	//	cout <<events[i] << " " << val << " " << j << " " << curr << endl ; 
	}
	cout << ans  ; 
	
	return 0; 
}

Compilation message

autobahn.cpp: In function 'int main()':
autobahn.cpp:41:7: warning: unused variable 'le' [-Wunused-variable]
   41 |   int le = l[i],re=r[i] ,rr=l[i]+t[i]-1 ;
      |       ^~
autobahn.cpp:49:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |  for(int i=1;i<events.size();i++) num[i]+=num[i-1],illegals[i]+=illegals[i-1] ;
      |              ~^~~~~~~~~~~~~~
autobahn.cpp:55:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |  for(int i=0;i+1<events.size();i++){
      |              ~~~^~~~~~~~~~~~~~
autobahn.cpp:10:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |   freopen("in.txt","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~
autobahn.cpp:11:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |   freopen("out.txt","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -