Submission #477229

# Submission time Handle Problem Language Result Execution time Memory
477229 2021-10-01T06:39:33 Z ogibogi2004 Experiments with Gorlum (IZhO13_expgorl) C++14
100 / 100
13 ms 972 KB
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define y1 fddsfdsd
const ld INF=2e18;
int k;
string s;
struct point
{
    ld x,y;
};
vector<point>v;
ld x1,y1,xa,ya;
ld mindist=INF,maxdist=-INF;
ld calcdist(point p1,ld t)
{
    ld xx=p1.x+t*xa;
    ld yy=p1.y+t*ya;
    return sqrt(xx*xx+yy*yy);
}
ld ts(point p)
{
    int l=0,r=k-1,m1,m2;
    while(r-l>100)
    {
        m1=l+(r-l)/3;
        m2=l+2*(r-l)/3;
        if(calcdist(p,m1)>=calcdist(p,m2))
        {
            l=m1;
        }
        else r=m2;
    }
    ld ret=INF;
    for(int i=l;i<=r;i++)
    {
        ret=min(ret,calcdist(p,i));
    }
    return ret;
}
int main()
{
    cin>>k;
    cin>>s;
    int xl,yl,xg,yg;
    cin>>xl>>yl;
    cin>>xg>>yg;
    x1=xg-xl;y1=yg-yl;
    v.push_back({x1,y1});
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='R')x1++;
        if(s[i]=='L')x1--;
        if(s[i]=='F')y1++;
        if(s[i]=='B')y1--;
        v.push_back({x1,y1});
    }
    //cout<<x1<<" "<<y1<<endl;
    /*for(int i=0;i<k;i++)
    {
        for(int j=0;j<s.size();j++)
        {
            if(s[j]=='R')x1++;
            if(s[j]=='L')x1--;
            if(s[j]=='F')y1++;
            if(s[j]=='B')y1--;
            maxdist=max(maxdist,sqrt(x1*x1+y1*y1));
            mindist=min(mindist,sqrt(x1*x1+y1*y1));
            //cout<<x1<<" "<<y1<<endl;
        }
    }
    cout<<fixed<<setprecision(20)<<mindist<<" "<<fixed<<setprecision(20)<<maxdist<<endl;
    return 0;*/
    xa=v.back().x-v[0].x;ya=v.back().y-v[0].y;
    ld mindist1=INF,maxdist1=-INF;
    //cout<<xa<<" "<<ya<<endl;
    for(int i=0;i<v.size();i++)
    {
        //cout<<v[i].x<<" "<<v[i].y<<endl;
        mindist=min(mindist,ts(v[i]));
        maxdist=max(maxdist,calcdist(v[i],0));
        maxdist=max(maxdist,calcdist(v[i],k-1));
        /*for(int j=0;j<k;j++)
        {
            mindist1=min(mindist1,calcdist(v[i],j));
            maxdist1=max(maxdist1,calcdist(v[i],j));
        }*/
        //cout<<calcdist(v[i],0)<<" "<<calcdist(v[i],k-1)<<endl;
        //cout<<maxdist<<endl;
    }
    //cout<<fixed<<setprecision(11)<<mindist<<" "<<maxdist<<endl;
    cout<<fixed<<setprecision(20)<<mindist<<" "<<fixed<<setprecision(20)<<maxdist<<endl;
return 0;
}

Compilation message

expgorl.cpp: In function 'int main()':
expgorl.cpp:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int i=0;i<s.size();i++)
      |                 ~^~~~~~~~~
expgorl.cpp:77:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
expgorl.cpp:75:8: warning: unused variable 'mindist1' [-Wunused-variable]
   75 |     ld mindist1=INF,maxdist1=-INF;
      |        ^~~~~~~~
expgorl.cpp:75:21: warning: unused variable 'maxdist1' [-Wunused-variable]
   75 |     ld mindist1=INF,maxdist1=-INF;
      |                     ^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 11 ms 588 KB Output is correct
10 Correct 8 ms 972 KB Output is correct
11 Correct 7 ms 592 KB Output is correct
12 Correct 11 ms 972 KB Output is correct
13 Correct 13 ms 972 KB Output is correct
14 Correct 6 ms 680 KB Output is correct
15 Correct 9 ms 720 KB Output is correct
16 Correct 8 ms 972 KB Output is correct
17 Correct 8 ms 972 KB Output is correct
18 Correct 11 ms 936 KB Output is correct
19 Correct 10 ms 972 KB Output is correct
20 Correct 8 ms 972 KB Output is correct