Submission #477228

# Submission time Handle Problem Language Result Execution time Memory
477228 2021-10-01T06:38:51 Z ogibogi2004 Experiments with Gorlum (IZhO13_expgorl) C++14
0 / 100
1000 ms 588 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>1000)
    {
        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)<<mindist1<<" "<<fixed<<setprecision(20)<<maxdist1<<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++)
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 260 ms 372 KB Output is correct
2 Correct 300 ms 392 KB Output is correct
3 Correct 355 ms 396 KB Output is correct
4 Correct 356 ms 332 KB Output is correct
5 Correct 213 ms 376 KB Output is correct
6 Correct 286 ms 380 KB Output is correct
7 Correct 363 ms 452 KB Output is correct
8 Correct 406 ms 396 KB Output is correct
9 Execution timed out 1082 ms 588 KB Time limit exceeded
10 Halted 0 ms 0 KB -