Submission #428992

# Submission time Handle Problem Language Result Execution time Memory
428992 2021-06-15T16:16:19 Z JeanBombeur Aliens (IOI16_aliens) C++17
0 / 100
1 ms 304 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include "aliens.h"
using namespace std;

//    <|°_°|>

const long long INFINI = (1LL << 60);
const int MAX_POINTS = (100 * 1000);
const int LOG = (40);

struct droite {
    long long pente, cst;
    int prix;
};

pair <long long, long long> Points[MAX_POINTS];
pair <int, int> Aliens[MAX_POINTS];

pair <droite, long long> Deque[MAX_POINTS];
int deb = 0, fin = 0;

int nbPoints = 0;

bool Compare(pair <int, int> a, pair <int, int> b) {
    if (a.first != b.first)
        return a.first < b.first;
    return a.second > b.second;
}

long long Inter(droite a, droite b) {
    if (a.pente == b.pente)
        return INFINI;
    return (b.cst - a.cst) / (a.pente - b.pente);
}

long long Eval(droite a, long long absc) {
    return a.pente * absc + a.cst;
}

void Insert(droite a) {
    while (fin > deb && Eval(Deque[fin - 1].first, Deque[fin - 1].second) >= Eval(a, Deque[fin - 1].second))
        fin --;
    if (fin == deb)
        Deque[fin ++] = {a, 0};
    else
    {
        Deque[fin] = {a, Inter(Deque[fin - 1].first, a)};
        fin ++;
    }
    return;
}

pair <long long, int> GetMin(int abcs) {
    while (fin > deb + 1 && abcs >= Deque[deb + 1].second)
        deb ++;
    return {Eval(Deque[deb].first, abcs), Deque[deb].first.prix};
}

pair <long long, int> FindDP(long long lambda) {
    deb = 0, fin = 0;
    pair <long long, int> DP = {0LL, 0};
    Insert({- 2 * Points[0].first, Points[0].first * Points[0].first, 0});
    for (int i = 0; i < nbPoints; i ++)
    {
        DP = GetMin(Points[i].second);
        DP.first += Points[i].second * Points[i].second + lambda;
        DP.second ++;
        if (i + 1 < nbPoints)
        {
            Insert({- 2 * Points[i + 1].first,
            Points[i + 1].first * Points[i + 1].first - max(0LL, Points[i].second - Points[i + 1].first) * max(0LL, Points[i].second * Points[i + 1].first) + DP.first, DP.second});
        }
    }
    return DP;
}

long long take_photos(int nbAliens, int tailleMax, int nbPhotos, vector<int> Lignes, vector<int> Colonnes) {
    
    tailleMax ++;
    
    for (int i = 0; i < nbAliens; i ++)
    {
        if (Lignes[i] > Colonnes[i])
            swap(Lignes[i], Colonnes[i]);
        Aliens[i] = {Lignes[i], Colonnes[i] + 1};
    }
    sort(Aliens, Aliens + nbAliens, Compare);
    
    for (int i = 0; i < nbAliens; i ++)
    {
        if (nbPoints == 0 || Aliens[i].second > (int)Points[nbPoints - 1].second)
            Points[nbPoints ++] = Aliens[i];
    }
    
    long long lambda = -1;
    long long ans = 0;
    for (long long i = (1LL << LOG); i > 0; i /= 2)
    {
        pair <long long, int> DP = FindDP(lambda + i);
        if (DP.second <= nbPhotos)
            ans = DP.first - (lambda + i) * nbPhotos;
        else
            lambda += i;
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 300 KB Correct answer: answer = 4
3 Correct 1 ms 304 KB Correct answer: answer = 4
4 Incorrect 1 ms 204 KB Wrong answer: output = 11, expected = 12
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 1
2 Correct 1 ms 204 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 1
4 Correct 1 ms 204 KB Correct answer: answer = 5
5 Correct 1 ms 300 KB Correct answer: answer = 41
6 Correct 1 ms 204 KB Correct answer: answer = 71923
7 Correct 1 ms 204 KB Correct answer: answer = 77137
8 Incorrect 1 ms 292 KB Wrong answer: output = 670, expected = 764
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 300 KB Correct answer: answer = 4
3 Correct 1 ms 304 KB Correct answer: answer = 4
4 Incorrect 1 ms 204 KB Wrong answer: output = 11, expected = 12
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 300 KB Correct answer: answer = 4
3 Correct 1 ms 304 KB Correct answer: answer = 4
4 Incorrect 1 ms 204 KB Wrong answer: output = 11, expected = 12
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 300 KB Correct answer: answer = 4
3 Correct 1 ms 304 KB Correct answer: answer = 4
4 Incorrect 1 ms 204 KB Wrong answer: output = 11, expected = 12
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 300 KB Correct answer: answer = 4
3 Correct 1 ms 304 KB Correct answer: answer = 4
4 Incorrect 1 ms 204 KB Wrong answer: output = 11, expected = 12
5 Halted 0 ms 0 KB -