#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].sc,yyyy+r+p[i].fr));
}
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;
int fff=200;
while (fff--){
int m1 = l+((r-l)/3);
int m2 = r-((r-l)/3);
if (fun((m1)) <= fun((m2))){
r = m2;
}
else l =m1;
}
mn = min(mn,fun(l));
mn = min(mn,fun(r));
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:60:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
60 | main(){
| ^
expgorl.cpp: In function 'int main()':
expgorl.cpp:66: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]
66 | for (i=0;i<s.size();++i){
| ~^~~~~~~~~
expgorl.cpp:63:11: warning: unused variable 'j' [-Wunused-variable]
63 | 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:61:5: note: in expansion of macro 'scan1'
61 | scan1(k)
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |