Submission #1544852


Source Code Expand

Copy
#include <iostream>
#include <sstream>
#include <fstream>

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>

#include <algorithm>
#include <numeric>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
// #include <unordered_map>
#include <set>
#include <utility>
#include <bitset>
#include <limits>
#include <climits>
using namespace std;

#ifdef DEBUG
#define NDEBUG
#include "cout11.h"
#endif
#undef NDEBUG
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

#define INTSPACE 11
char _buf[INTSPACE*1000000 + 3];  // ここ要確認

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}
int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    return i;
}


int lis(vector<int>& a) {
    int M = a.size();
    if (M == 0) return 0;

    // cout << a << endl;
    assert(0 < M && M <= 200000);

    vector<int> dp(M, 1e9);
    dp[0] = a[0];
    int maxlen = 1;
    for (int i=1; i<M; ++i) {
        int len = (int)(lower_bound(dp.begin(),dp.begin()+i, a[i]) - dp.begin())+1;
        maxlen = max(maxlen, len);
        dp[len-1] = min(dp[len-1], a[i]);
    }
    // cout << dp << endl;
    return maxlen;
}

int main() {
    vector<int> tmp(4);
    loadvec(tmp,4);
    int x1=tmp[0], y1=tmp[1], x2=tmp[2], y2=tmp[3];
    int xmin=min(x1,x2), xmax=max(x1,x2);
    int ymin=min(y1,y2), ymax=max(y1,y2);
    if (x2 < x1) {
        swap(x1,x2); swap(y1,y2);
    }
    long double ans = 100.0 * ((xmax - xmin) + (ymax - ymin));
    long double pi = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;

    int N = loadint();
    vector<ii> ft;
    ft.reserve(N);
    rep(i,N){
        loadvec(tmp,2);
        int Xi=tmp[0], Yi=tmp[1];
        if (IN(Xi,xmin,xmax) && IN(Yi,ymin,ymax)) {
            ft.pb(ii(Xi,Yi));
        }
    }
    sort(ALL(ft));
    int M = ft.size();
    vector<int> a(M);
    rep(i,M) a[i] = ft[i].second;
    if (xmax == xmin || ymax == ymin) {
        // cout << a << endl;
        assert(M == 0 || M == 1);
        ans += (pi*10 - 20)*M; // M = 0 or 1
    } else if (M > 0) {
        assert(x1 < x2);
        if (y1 > y2) {
            rep(i,M) a[i] = ymax - a[i];
        } else {
            rep(i,M) a[i] -= ymin;
        }
        // cout << a << endl;
        int L = lis(a); // 1..M

        if (L == ymax-ymin+1 || L == xmax-xmin+1) {
            ans -= (20.0 - pi*5) * (L-1);
            ans += (pi*10 - 20);
        } else {
            ans -= (20.0 - pi*5) * L;
        }
    }
    printf("%.15Lf\n", ans);
    return 0;
}

Submission Info

Submission Time
Task C - Fountain Walk
User naoya_t
Language C++14 (GCC 5.4.1)
Score 900
Code Size 4086 Byte
Status
Exec Time 49 ms
Memory 3456 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt
All 900 / 900 sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_19.txt, subtask_1_20.txt, subtask_1_21.txt, subtask_1_22.txt, subtask_1_23.txt, subtask_1_24.txt, subtask_1_25.txt, subtask_1_26.txt, subtask_1_27.txt, subtask_1_28.txt, subtask_1_29.txt, subtask_1_30.txt, subtask_1_31.txt, subtask_1_32.txt, subtask_1_33.txt, subtask_1_34.txt, subtask_1_35.txt, subtask_1_36.txt, subtask_1_37.txt, subtask_1_38.txt, subtask_1_39.txt, subtask_1_40.txt, subtask_1_41.txt
Case Name Status Exec Time Memory
sample_01.txt 1 ms 256 KB
sample_02.txt 1 ms 256 KB
sample_03.txt 1 ms 256 KB
subtask_1_01.txt 1 ms 256 KB
subtask_1_02.txt 1 ms 256 KB
subtask_1_03.txt 1 ms 256 KB
subtask_1_04.txt 1 ms 256 KB
subtask_1_05.txt 1 ms 256 KB
subtask_1_06.txt 1 ms 256 KB
subtask_1_07.txt 1 ms 256 KB
subtask_1_08.txt 1 ms 256 KB
subtask_1_09.txt 8 ms 256 KB
subtask_1_10.txt 16 ms 256 KB
subtask_1_11.txt 5 ms 256 KB
subtask_1_12.txt 45 ms 3328 KB
subtask_1_13.txt 17 ms 256 KB
subtask_1_14.txt 9 ms 256 KB
subtask_1_15.txt 5 ms 256 KB
subtask_1_16.txt 45 ms 3328 KB
subtask_1_17.txt 14 ms 256 KB
subtask_1_18.txt 12 ms 256 KB
subtask_1_19.txt 12 ms 256 KB
subtask_1_20.txt 44 ms 3328 KB
subtask_1_21.txt 45 ms 3328 KB
subtask_1_22.txt 45 ms 3328 KB
subtask_1_23.txt 44 ms 3328 KB
subtask_1_24.txt 1 ms 256 KB
subtask_1_25.txt 1 ms 256 KB
subtask_1_26.txt 1 ms 256 KB
subtask_1_27.txt 1 ms 256 KB
subtask_1_28.txt 20 ms 384 KB
subtask_1_29.txt 22 ms 384 KB
subtask_1_30.txt 49 ms 3328 KB
subtask_1_31.txt 27 ms 3328 KB
subtask_1_32.txt 31 ms 3328 KB
subtask_1_33.txt 31 ms 3456 KB
subtask_1_34.txt 27 ms 3328 KB
subtask_1_35.txt 36 ms 3328 KB
subtask_1_36.txt 38 ms 3328 KB
subtask_1_37.txt 34 ms 3328 KB
subtask_1_38.txt 35 ms 3328 KB
subtask_1_39.txt 35 ms 3328 KB
subtask_1_40.txt 32 ms 3328 KB
subtask_1_41.txt 33 ms 3328 KB