답안 #339516

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
339516 2020-12-25T14:41:50 Z beksultan04 생물 실험 (IZhO13_expgorl) C++14
100 / 100
2 ms 640 KB
#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)*p[s.size()-1].fr;
    double r = (x)*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)
      |     ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 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 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct