Submission #1541653


Source Code Expand

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

template <class T>
class segment_tree {
    public:
    segment_tree(int n, function<T(const T&, const T&)> func, const T& init = T());
    ~segment_tree();
    void update(int x, const T& value);
    T get(int x, int y) const; // [x, y)
    
    private:
    int size;
    function<T(const T&, const T&)> func;
    T init;
    T* data;
};

template <class T> segment_tree<T>::segment_tree(int n, function<T(const T&, const T&)> func, const T& init) : size(1 << (32 - __builtin_clz(n - 1))), func(func), init(init) {
    data = (T *)malloc(sizeof(T) * size * 2);
    for (int i = 0; i < size * 2; i++) data[i] = init;
}

template <class T> segment_tree<T>::~segment_tree() {
    free(data);
}

template <class T> void segment_tree<T>::update(int x, const T& value) {
    data[x += size] = value;
    while (x >>= 1) data[x] = func(data[x * 2], data[x * 2 + 1]);
}

template <class T> T segment_tree<T>::get(int x, int y) const {
    T vl = init, vr = init;
    for (x += size, y += size; x < y; x >>= 1, y >>= 1) {
        if (x & 1) vl = func(vl, data[x++]);
        if (y & 1) vr = func(data[--y], vr);
    }
    return func(vl, vr);
}

double pi = acos(-1);
int x[200002];
int y[200002];

int main() {
    int n, mc, i;
    double ans;
    map <int, int> mpx, mpy;
    map <int, int>::iterator it;
    
    scanf("%d %d %d %d", &x[0], &y[0], &x[1], &y[1]);
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d %d", &x[i + 2], &y[i + 2]);
    
    ans = (long long)abs(x[0] - x[1]) * 100 + (long long)abs(y[0] - y[1]) * 100;
    mc = min(abs(x[0] - x[1]), abs(y[0] - y[1]));
    
    for (i = 0; i < n + 2; i++) {
        mpx[x[i]] = 0;
        mpy[y[i]] = 0;
    }
    
    for (it = mpx.begin(), i = 0; it != mpx.end(); it++, i++) it->second = i;
    for (it = mpy.begin(), i = 0; it != mpy.end(); it++, i++) it->second = i;
    
    for (i = 0; i < n + 2; i++) {
        x[i] = mpx[x[i]];
        y[i] = mpy[y[i]];
    }
    
    if (x[0] == x[1]) {
        if (y[0] > y[1]) swap(y[0], y[1]);
        
        for (i = 2; i < n + 2; i++) {
            if (x[i] == x[0] && y[i] > y[0] && y[i] < y[1]) {
                ans -= 20;
                ans += 10 * pi;
            }
        }
    } else if (y[0] == y[1]) {
        if (x[0] > x[1]) swap(x[0], x[1]);
        
        for (i = 2; i < n + 2; i++) {
            if (y[i] == y[0] && x[i] > x[0] && x[i] < x[1]) {
                ans -= 20;
                ans += 10 * pi;
            }
        }
    } else {
        int c;
        vector <pair<int, int> > v;
        
        if (x[0] > x[1]) {
            swap(x[0], x[1]);
            swap(y[0], y[1]);
        }
        
        if (y[0] > y[1]) {
            for (i = 1; i < n + 2; i++) y[i] = y[0] * 2 - y[i];
        }
        
        for (i = 2; i < n + 2; i++) v.push_back(make_pair(x[i], y[i]));
        
        sort(v.begin(), v.end());
        
        segment_tree<int> s(y[1] + 1, [](int a, int b) { return max(a, b);}, 0);
        
        for (i = 0; i < v.size(); i++) {
            int xx = v[i].first;
            int yy = v[i].second;
            
            if (xx < x[0] || xx > x[1] || yy < y[0] || yy > y[1]) continue;
            
            s.update(yy, s.get(y[0], yy) + 1);
        }
        
        c = s.get(y[0], y[1] + 1);
        
        if (c <= mc) {
            ans -= 20 * c;
            ans += 5 * pi * c;
        } else {
            ans -= 20 * mc;
            ans += 5 * pi * mc;
            ans -= 20;
            ans += 10 * pi;
        }
    }
    
    printf("%.12lf\n", ans);
    
    return 0;
}

Submission Info

Submission Time
Task C - Fountain Walk
User kawatea
Language C++14 (GCC 5.4.1)
Score 900
Code Size 3865 Byte
Status AC
Exec Time 432 ms
Memory 26356 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:59:53: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d", &x[0], &y[0], &x[1], &y[1]);
                                                     ^
./Main.cpp:60:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
./Main.cpp:62:65: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     for (i = 0; i < n; i++) scanf("%d %d", &x[i + 2], &y[i + 2]);
                                                                 ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 3
AC × 47
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All 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 AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
subtask_1_01.txt AC 1 ms 256 KB
subtask_1_02.txt AC 1 ms 256 KB
subtask_1_03.txt AC 1 ms 256 KB
subtask_1_04.txt AC 1 ms 256 KB
subtask_1_05.txt AC 1 ms 256 KB
subtask_1_06.txt AC 1 ms 256 KB
subtask_1_07.txt AC 1 ms 256 KB
subtask_1_08.txt AC 1 ms 256 KB
subtask_1_09.txt AC 95 ms 7296 KB
subtask_1_10.txt AC 257 ms 18292 KB
subtask_1_11.txt AC 49 ms 4988 KB
subtask_1_12.txt AC 369 ms 24308 KB
subtask_1_13.txt AC 260 ms 16000 KB
subtask_1_14.txt AC 104 ms 8568 KB
subtask_1_15.txt AC 43 ms 4352 KB
subtask_1_16.txt AC 369 ms 24308 KB
subtask_1_17.txt AC 218 ms 15348 KB
subtask_1_18.txt AC 158 ms 11640 KB
subtask_1_19.txt AC 152 ms 11384 KB
subtask_1_20.txt AC 363 ms 24308 KB
subtask_1_21.txt AC 373 ms 24308 KB
subtask_1_22.txt AC 384 ms 26356 KB
subtask_1_23.txt AC 379 ms 26356 KB
subtask_1_24.txt AC 1 ms 256 KB
subtask_1_25.txt AC 1 ms 256 KB
subtask_1_26.txt AC 1 ms 256 KB
subtask_1_27.txt AC 1 ms 256 KB
subtask_1_28.txt AC 400 ms 24308 KB
subtask_1_29.txt AC 401 ms 22776 KB
subtask_1_30.txt AC 432 ms 24308 KB
subtask_1_31.txt AC 280 ms 24308 KB
subtask_1_32.txt AC 291 ms 24308 KB
subtask_1_33.txt AC 292 ms 24308 KB
subtask_1_34.txt AC 245 ms 24308 KB
subtask_1_35.txt AC 251 ms 24308 KB
subtask_1_36.txt AC 383 ms 24308 KB
subtask_1_37.txt AC 289 ms 24308 KB
subtask_1_38.txt AC 287 ms 24308 KB
subtask_1_39.txt AC 276 ms 24308 KB
subtask_1_40.txt AC 284 ms 24308 KB
subtask_1_41.txt AC 290 ms 24308 KB