Submission #1009450

# Submission time Handle Problem Language Result Execution time Memory
1009450 2024-06-27T14:17:53 Z tarpent Experiments with Gorlum (IZhO13_expgorl) C++14
100 / 100
1 ms 492 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
using namespace std;
long long n,gx,gy,lx,ly,tgx,tgy,lo,up,mid,pgx,pgy,trx,tryi,mi;
string pu,k;
double ma,tr,miko,mako;
char e;
long double naj(long long mik){
	pgy=gy+mik*tgy;
	pgx=gx+mik*tgx;
	miko=INT_MAX;
	if(abs(lx-pgx)*abs(lx-pgx)+abs(ly-pgy)*abs(ly-pgy)<miko) miko = abs(lx-pgx)*abs(lx-pgx)+abs(ly-pgy)*abs(ly-pgy);
	for(int i = 0; i<pu.size(); i++){
		e=pu[i];
		if(e=='L'){
			pgx-=1;
		}
		else if(e=='R'){
			pgx+=1;
		}
		else if(e=='F'){
			pgy+=1;
		}
		else if(e=='B'){
			pgy-=1;
		}
		if(abs(lx-pgx)*abs(lx-pgx)+abs(ly-pgy)*abs(ly-pgy)<miko) miko = abs(lx-pgx)*abs(lx-pgx)+abs(ly-pgy)*abs(ly-pgy);
	}
	return(miko);
}
long double vec(long long mik){
	pgy=gy+mik*tgy;
	pgx=gx+mik*tgx;
	mako=0;
	if(abs(lx-pgx)*abs(lx-pgx)+abs(ly-pgy)*abs(ly-pgy)>mako) mako = abs(lx-pgx)*abs(lx-pgx)+abs(ly-pgy)*abs(ly-pgy);
	for(int i = 0; i<pu.size(); i++){
		e=pu[i];
		if(e=='L'){
			pgx-=1;
		}
		else if(e=='R'){
			pgx+=1;
		}
		else if(e=='F'){
			pgy+=1;
		}
		else if(e=='B'){
			pgy-=1;
		}
		if(abs(lx-pgx)*abs(lx-pgx)+abs(ly-pgy)*abs(ly-pgy)>mako) mako = abs(lx-pgx)*abs(lx-pgx)+abs(ly-pgy)*abs(ly-pgy);
	}
	return(mako);
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	cin>>n;
	cin>>pu;
	cin>>lx>>ly>>gx>>gy;
	pgx=gx;pgy=gy;
	tgy=0;
	tgx=0;
	mi= INT_MAX;
	ma=0;
	int siz;
	char e;
	for(int i = 0; i<pu.size(); i++){
		e=pu[i];
		if(e=='L'){
			tgx-=1;
		}
		else if(e=='R'){
			tgx+=1;
		}
		else if(e=='F'){
			tgy+=1;
		}
		else if(e=='B'){
			tgy-=1;
		}
	}
	mi=INT_MAX;
	ma=max(vec(0),vec(n-1));
	pgx=gx;
	pgy=gy;
	for(int i = 0; i<pu.size(); i++){
		lo=0;
		up=n-1;
		mid=up/2;
		e=pu[i];
		
		while(lo<up){
			trx=pgx+tgx*mid;
			tryi=pgy+tgy*mid;
			
			long long dist1 = abs(trx-lx)*abs(trx-lx)+abs(tryi-ly)*abs(tryi-ly);
			trx+=tgx;
			tryi+=tgy;
			long long dist2 = abs(trx-lx)*abs(trx-lx)+abs(tryi-ly)*abs(tryi-ly);
			if(dist1<dist2) up=mid;
			else{
				lo=mid+1;
			}
			mid=(lo+up)/2;
		}
		mi=min(mi,abs((pgx+mid*tgx)-lx)*abs((pgx+mid*tgx)-lx)+abs((pgy+mid*tgy)-ly)*abs((pgy+mid*tgy)-ly));
		if(e=='L'){
			pgx-=1;
		}
		else if(e=='R'){
			pgx+=1;
		}
		else if(e=='F'){
			pgy+=1;
		}
		else if(e=='B'){
			pgy-=1;
		}
		
	}
	
	
	siz=k.size();
	
	cout<<fixed;
	cout<<setprecision(12);
	cout<<sqrt(mi)<<' '<<sqrt(ma);
	
	
}

Compilation message

expgorl.cpp: In function 'long double naj(long long int)':
expgorl.cpp:14:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i = 0; i<pu.size(); i++){
      |                 ~^~~~~~~~~~
expgorl.cpp: In function 'long double vec(long long int)':
expgorl.cpp:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for(int i = 0; i<pu.size(); i++){
      |                 ~^~~~~~~~~~
expgorl.cpp: In function 'int main()':
expgorl.cpp:69:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |  for(int i = 0; i<pu.size(); i++){
      |                 ~^~~~~~~~~~
expgorl.cpp:88:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |  for(int i = 0; i<pu.size(); i++){
      |                 ~^~~~~~~~~~
expgorl.cpp:67:6: warning: variable 'siz' set but not used [-Wunused-but-set-variable]
   67 |  int siz;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 468 KB Output is correct