#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-12
const int N = 3e5+12,INF=1e9+7;
pair<double,double> p[N];
int k, tx, ty;
double laser1, laser2, gx, gy;
string s;
double disting(double x,double y){
ret (x - laser1)*(x-laser1)+(y-laser2)*(y-laser2);
}
void answer(double &ans){
ans = max(ans, disting(gx, gy));
double l=0,r=0,i;
for (i=0;i<s.size();++i){
if (s[i] == 'L')l--;
if (s[i] == 'R')l++;
if (s[i] == 'F')r++;
if (s[i] == 'B')r--;
ans = max(ans,disting(gx+l,gy+r));
}
l*=k-1;
r*=k-1;
for (i=0;i<s.size();++i){
if (s[i] == 'L')l--;
if (s[i] == 'R')l++;
if (s[i] == 'F')r++;
if (s[i] == 'B')r--;
ans = max(ans,disting(gx+l, gy+r));
}
}
double fun(int a){
double x = a*tx + gx;
double y = a*ty + gy;
double ans=INF;
ans = min(ans,disting(x, y));
for (int i=0;i<s.size();++i){
if (s[i] == 'L')x--;
if (s[i] == 'R')x++;
if (s[i] == 'F')y++;
if (s[i] == 'B')y--;
ans = min(ans, disting(x, y));
}
ret ans;
}
main(){
scan1(k)
cin>>s>>laser1>>laser2>>gx>>gy;
int i,j;
double mx = 0, mn = INF;
answer(mx);
for (i=0;i<s.size();++i){
if (s[i] == 'L')tx--;
if (s[i] == 'R')tx++;
if (s[i] == 'F')ty++;
if (s[i] == 'B')ty--;
}
int l=0,r=k-1;
while (l+1 < r){
int m = (l + r)>>1;
if(fun(m) <= fun(m+1)) r = m;
else l = m;
}
mn = min(fun(l), fun(r));
cout <<fixed<<setprecision(12);
cout <<sqrt(mn)<<" "<<sqrt(mx);
}
Compilation message
expgorl.cpp: In function 'double fun(long long int)':
expgorl.cpp:54:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i=0;i<s.size();++i){
| ~^~~~~~~~~
expgorl.cpp: At global scope:
expgorl.cpp:64:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
64 | main(){
| ^
expgorl.cpp: In function 'int main()':
expgorl.cpp:70:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for (i=0;i<s.size();++i){
| ~^~~~~~~~~
expgorl.cpp:67:11: warning: unused variable 'j' [-Wunused-variable]
67 | int i,j;
| ^
expgorl.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
11 | #define scan1(a) scanf("%lld",&a);
| ~~~~~^~~~~~~~~~~
expgorl.cpp:65:5: note: in expansion of macro 'scan1'
65 | scan1(k)
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
3 ms |
364 KB |
Output is correct |
11 |
Correct |
3 ms |
364 KB |
Output is correct |
12 |
Correct |
4 ms |
364 KB |
Output is correct |
13 |
Correct |
3 ms |
364 KB |
Output is correct |
14 |
Correct |
3 ms |
364 KB |
Output is correct |
15 |
Correct |
3 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
3 ms |
364 KB |
Output is correct |
19 |
Correct |
3 ms |
364 KB |
Output is correct |
20 |
Correct |
4 ms |
364 KB |
Output is correct |