Submission #736258


Source Code Expand

Copy
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

signed main()
{
    double L, X, Y, S, D;
    cin >> L >> X >> Y >> S >> D;

    if (S < D) { // D が S より先にある場合
        double a = abs(D - S); // 時計回りの距離
        double b = L - abs(D - S); // 反時計回りの距離

        double ans = inf;

        // 時計回りで歩く時の時間
        chmin(ans, a / (Y + X));

        if (Y < X) { // 反時計回りに歩いても戻ってしまう場合
            chmin(ans, a / (X - Y));
        } else { // そんなことはない場合
            chmin(ans, b / (Y - X));
        }
        
        printf("%.10f\n", ans);
    } else {
        double a = L - abs(D - S);
        double b = abs(D - S);

        double ans = inf;

        // 時計回りで歩く時の時間
        chmin(ans, a / (Y + X));

        if (Y < X) { // 反時計回りに歩いても戻ってしまう場合
            chmin(ans, a / (X - Y));
        } else { // そんなことはない場合
            chmin(ans, b / (Y - X));
        }

        printf("%.10f\n", ans);
    }
}

Submission Info

Submission Time
Task A - 動く歩道
User Izryt
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2509 Byte
Status
Exec Time 4 ms
Memory 256 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All 100 / 100 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt
Case Name Status Exec Time Memory
01.txt 4 ms 256 KB
02.txt 4 ms 256 KB
03.txt 4 ms 256 KB
04.txt 4 ms 256 KB
05.txt 4 ms 256 KB
06.txt 4 ms 256 KB
07.txt 4 ms 256 KB
08.txt 4 ms 256 KB
09.txt 4 ms 256 KB
10.txt 4 ms 256 KB
11.txt 4 ms 256 KB
12.txt 4 ms 256 KB
13.txt 4 ms 256 KB
14.txt 4 ms 256 KB
15.txt 4 ms 256 KB
16.txt 4 ms 256 KB
sample_01.txt 4 ms 256 KB
sample_02.txt 4 ms 256 KB
sample_03.txt 4 ms 256 KB
sample_04.txt 4 ms 256 KB