Submission #1243027


Source Code Expand

#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>
using namespace std;
#define MOD 1000000007
#define PI 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r) for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define each(i, v) for (auto i : v)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
#define fi first
#define se second
#define setp(x) setprecision(x)
#define mset(m, v) memset(m, v, sizeof(m))
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }

//static const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//#define int ll

int main() { 
        int n;
        cin >> n;
        int start, goal;
        cin >> start >> goal;
        vi l(n + 1), r(n + 1);
        rep(i, n + 1) cin >> l[i] >> r[i];
        l[0] = r[0] = start;
        l[n] = r[n] = goal;
        double ans = 0;
        int y = 0, x = start;
        auto cmp = [&](int ay, int ax, int by, int bx) {
                return (ax - x) * (ll)(by - y) - (ay - y) * (ll)(bx - x) < 0;
        };
        while (y < n) {
                int ly = y, ry = y;
                int lx = x - 1, rx = x + 1;
                reu(ny, y + 1, n + 1) {
                        if (cmp(ny, r[ny], ly, lx) && ly != y) {
                                ans += hypot(ly - y, l[ly] - x);
                                y = ly;
                                x = l[ly];
                                goto next;
                        }
                        if (cmp(ry, rx, ny, l[ny]) && ry != y) {
                                ans += hypot(ry - y, r[ry] - x);
                                y = ry;
                                x = r[ry];
                                goto next;
                        }
                        if (cmp(ny, r[ny], ry, rx)) {
                                ry = ny;
                                rx = r[ny];
                        }
                        if (cmp(ly, lx, ny, l[ny])) {
                                ly = ny;
                                lx = l[ny];
                        }
                }
                ans += hypot(n - y, goal - x);
                y = n;
                x = goal;
next:;
        }
        cout << setp(15) << ans << endl;
        return 0;
}

Submission Info

Submission Time
Task D - レースゲーム
User KokiYmgch
Language C++14 (GCC 5.4.1)
Score 100
Code Size 3386 Byte
Status AC
Exec Time 489 ms
Memory 1920 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 26
Set Name Test Cases
All 00_sample1.txt, 00_sample2.txt, 01_rnd_large_00.txt, 01_rnd_large_01.txt, 01_rnd_large_02.txt, 01_rnd_small_00.txt, 01_rnd_small_01.txt, 01_rnd_small_02.txt, 02_narrowrnd_large_00.txt, 02_narrowrnd_large_01.txt, 02_narrowrnd_small_00.txt, 02_narrowrnd_small_01.txt, 03_zigzag_large_00.txt, 03_zigzag_small_00.txt, 04_middle_large_00.txt, 04_middle_large_01.txt, 04_middle_large_02.txt, 04_middle_small_00.txt, 04_middle_small_01.txt, 04_middle_small_02.txt, 05_turnleft_large_00.txt, 05_turnleft_small_00.txt, 06_turnright_large_00.txt, 06_turnright_small_00.txt, 07_free_large_00.txt, 07_free_small_00.txt
Case Name Status Exec Time Memory
00_sample1.txt AC 2 ms 512 KB
00_sample2.txt AC 1 ms 256 KB
01_rnd_large_00.txt AC 127 ms 1792 KB
01_rnd_large_01.txt AC 131 ms 1792 KB
01_rnd_large_02.txt AC 127 ms 1792 KB
01_rnd_small_00.txt AC 2 ms 256 KB
01_rnd_small_01.txt AC 2 ms 256 KB
01_rnd_small_02.txt AC 2 ms 256 KB
02_narrowrnd_large_00.txt AC 128 ms 1792 KB
02_narrowrnd_large_01.txt AC 128 ms 1792 KB
02_narrowrnd_small_00.txt AC 2 ms 256 KB
02_narrowrnd_small_01.txt AC 2 ms 256 KB
03_zigzag_large_00.txt AC 109 ms 1792 KB
03_zigzag_small_00.txt AC 2 ms 256 KB
04_middle_large_00.txt AC 129 ms 1792 KB
04_middle_large_01.txt AC 128 ms 1792 KB
04_middle_large_02.txt AC 131 ms 1792 KB
04_middle_small_00.txt AC 2 ms 256 KB
04_middle_small_01.txt AC 2 ms 256 KB
04_middle_small_02.txt AC 2 ms 256 KB
05_turnleft_large_00.txt AC 135 ms 1792 KB
05_turnleft_small_00.txt AC 2 ms 256 KB
06_turnright_large_00.txt AC 489 ms 1792 KB
06_turnright_small_00.txt AC 2 ms 256 KB
07_free_large_00.txt AC 104 ms 1920 KB
07_free_small_00.txt AC 2 ms 256 KB