#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;
double laser1,laser2,xxxx,yyyy;
string s;
double disting(double x,double y,double x1,double y1){
ret (x-x1)*(x-x1)+(y-y1)*(y-y1);
}
void answer(double &ans){
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(laser1,laser2,xxxx+l,yyyy+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(laser1,laser2,xxxx+l,yyyy+r));
}
}
double fun(int x){
double l = (x-1)*p[s.size()-1].fr;
double r = (x-1)*p[s.size()-1].sc;
double ans=INF;
for (int i=0;i<s.size();++i){
ans = min(ans,disting(laser1,laser2,xxxx+l+p[i].fr,yyyy+r+p[i].sc));
}
ret ans;
}
main(){
scan1(k)
cin>>s>>laser1>>laser2>>xxxx>>yyyy;
int i,j;
double mx=disting(laser1,laser2,xxxx,yyyy),mn=disting(laser1,laser2,xxxx,yyyy);
answer(mx);
for (i=0;i<s.size();++i){
if (i != 0)
p[i] = p[i-1];
if (s[i] == 'L')p[i].fr--;
if (s[i] == 'R')p[i].fr++;
if (s[i] == 'F')p[i].sc++;
if (s[i] == 'B')p[i].sc--;
}
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:52: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]
52 | for (int i=0;i<s.size();++i){
| ~^~~~~~~~~
expgorl.cpp: At global scope:
expgorl.cpp:58:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
58 | main(){
| ^
expgorl.cpp: In function 'int main()':
expgorl.cpp:64: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]
64 | for (i=0;i<s.size();++i){
| ~^~~~~~~~~
expgorl.cpp:61:11: warning: unused variable 'j' [-Wunused-variable]
61 | 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:59:5: note: in expansion of macro 'scan1'
59 | scan1(k)
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |