답안 #727095

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
727095 2023-04-20T03:46:37 Z Baytoro Measures (CEOI22_measures) C++17
0 / 100
1500 ms 588 KB
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define ll long long
#define int long long
void fopn(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=1e9+9,N=2e5+5;
int d;
int calc(vector<int> vec){
	sort(all(vec));
	int n=vec.size();
	int l=-1,r=2e9;
	while(r-l>1){
		int md=(l+r)/2;
		vector<int> a=vec;
		for(int i=0;i<n;i++){
			if(!i){
				a[i]-=md;
				continue;
			}
			int x=abs((a[i-1]+d)-a[i]);
			//cout<<x<<endl;
			if(x>md){
				if(a[i-1]+d>a[i]) a[i]+=md;
				else a[i]-=md;
			}
			else{
				if(a[i-1]+d>a[i]) a[i]+=x;
				else a[i]-=x;
			}
			/*cout<<md<<endl;
			for(auto it: a)
				cout<<it<<' ';
			cout<<endl;*/
		}
		bool check=1;
		for(int i=1;i<n && check;i++)
			check&=(a[i]-a[i-1]>=d);
		if(check) r=md;
		else l=md;
	}
	return r;
}
void solve(){
	int n,m;cin>>n>>m>>d;
	d*=2;
	vector<int> vec(n);
	for(int i=0;i<n;i++){
		cin>>vec[i];
		vec[i]*=2;
	}
	for(int i=0;i<m;i++){
		int x;cin>>x;
		vec.pb(2*x);
		cout<<(double)calc(vec)/2.0<<' ';
	}
}
main(){
	//fopn("friendcross");
	ios;
	int T=1;
	//cin>>T;
	for(int i=1;i<=T;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}

Compilation message

Main.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main(){
      | ^~~~
Main.cpp: In function 'void fopn(std::string)':
Main.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 340 KB Output is correct
2 Incorrect 4 ms 400 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 340 KB Output is correct
2 Incorrect 4 ms 400 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1553 ms 588 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1553 ms 588 KB Time limit exceeded
2 Halted 0 ms 0 KB -