Submission #745438

# Submission time Handle Problem Language Result Execution time Memory
745438 2023-05-20T06:43:33 Z boris_mihov Shortcut (IOI16_shortcut) C++17
0 / 100
1 ms 312 KB
#include "shortcut.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

typedef long long llong;
const int MAXN = 1000000 + 10;
const llong INF = 1e15;

struct Point
{
    llong x, y;
};

struct Rectangle
{
    Point low, up;
    Rectangle()
    {
        low.x = low.y = 0;
        up.x = up.y = INF;
    }

    bool isInside(Point p)
    {
        return low.x <= p.x && low.y <= p.y && low.x <= up.x && low.y <= up.y;
    }
};

bool haveIntersection(Rectangle a, Rectangle b)
{
    return !(a.up.x < b.low.x || b.up.x < a.low.x || a.up.y < b.low.y || b.up.y < a.low.y); 
}

Rectangle intersect(Rectangle a, Rectangle b)
{
    Rectangle res;
    res.low.x = std::max(a.low.x, b.low.x);
    res.low.y = std::max(a.low.y, b.low.y);
    res.up.x = std::min(a.up.x, b.up.x);
    res.up.y = std::min(a.up.y, b.up.y);
    return res;
}

int n, c;
int l[MAXN];
int d[MAXN];
llong p[MAXN];

llong abs(const llong &num)
{
    if (num < 0) return -num;
    return num;
}

bool check(llong allowed)
{
    Rectangle area;
    for (int i = 1 ; i <= n ; ++i)
    {
        for (int j = i + 1 ; j <= n ; ++j)
        {
            if (p[j] - p[i] + d[i] + d[j] <= allowed)
            {
                continue;
            }

            if (allowed < c + d[i] + d[j])
            {
                return false;
            }

            Point centre = {p[j] + p[i], p[j] - p[i]};
            Rectangle curr;
            curr.low.x = centre.x - (allowed - c - d[i] - d[j]);
            curr.low.y = centre.y - (allowed - c - d[i] - d[j]);
            curr.up.x = centre.x + (allowed - c - d[i] - d[j]);
            curr.up.y = centre.y + (allowed - c - d[i] - d[j]);
            if (!haveIntersection(area, curr))
            {
                return false;
            }

            area = intersect(area, curr);
        }
    }
    
    for (int i = 1 ; i <= n ; ++i)
    {
        for (int j = i + 1 ; j <= n ; ++j)
        {
            Point curr = {p[j] + p[i], p[j] - p[i]};
            if (area.isInside(curr))
            {
                return true;
            }
        }
    }

    return false;
}

llong find_shortcut(int N, std::vector <int> L, std::vector <int> D, int C)
{
    n = N; c = C;
    for (int i = 0 ; i < n - 1 ; ++i)
    {
        l[i + 1] = L[i]; 
    }

    for (int i = 0 ; i < n ; ++i)
    {
        d[i + 1] = D[i];
    }

    p[1] = 0;
    for (int i = 2 ; i <= n ; ++i)
    {
        p[i] = p[i - 1] + l[i - 1];
    }

    llong l = -1, r = INF, mid;
    while (l < r - 1)
    {
        mid = (l + r) / 2;
        if (!check(mid)) l = mid;
        else r = mid;
    }

    return r;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 232 KB n = 2, 62 is a correct answer
6 Correct 0 ms 212 KB n = 2, 3 is a correct answer
7 Correct 1 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 308 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 304 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 308 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 312 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 3189 vs contestant 3115
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 232 KB n = 2, 62 is a correct answer
6 Correct 0 ms 212 KB n = 2, 3 is a correct answer
7 Correct 1 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 308 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 304 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 308 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 312 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 3189 vs contestant 3115
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 232 KB n = 2, 62 is a correct answer
6 Correct 0 ms 212 KB n = 2, 3 is a correct answer
7 Correct 1 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 308 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 304 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 308 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 312 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 3189 vs contestant 3115
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 232 KB n = 2, 62 is a correct answer
6 Correct 0 ms 212 KB n = 2, 3 is a correct answer
7 Correct 1 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 308 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 304 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 308 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 312 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 3189 vs contestant 3115
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 232 KB n = 2, 62 is a correct answer
6 Correct 0 ms 212 KB n = 2, 3 is a correct answer
7 Correct 1 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 308 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 304 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 308 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 312 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 3189 vs contestant 3115
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 232 KB n = 2, 62 is a correct answer
6 Correct 0 ms 212 KB n = 2, 3 is a correct answer
7 Correct 1 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 308 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 304 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 308 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 312 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 3189 vs contestant 3115
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 232 KB n = 2, 62 is a correct answer
6 Correct 0 ms 212 KB n = 2, 3 is a correct answer
7 Correct 1 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 308 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 304 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 308 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 312 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 3189 vs contestant 3115
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 232 KB n = 2, 62 is a correct answer
6 Correct 0 ms 212 KB n = 2, 3 is a correct answer
7 Correct 1 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 308 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 304 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 308 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 312 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 3189 vs contestant 3115
19 Halted 0 ms 0 KB -