Submission #429247

# Submission time Handle Problem Language Result Execution time Memory
429247 2021-06-15T19:29:45 Z JeanBombeur Aliens (IOI16_aliens) C++17
4 / 100
1 ms 272 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];
 
droite Deque[MAX_POINTS];
int deb = 0, fin = 0;
 
int nbPoints = 0;
 
void Insert(droite a) {
    while (fin > deb + 1 && make_pair((a.cst - Deque[fin - 2].cst) * (Deque[fin - 2].pente - Deque[fin - 1].pente), a.prix) < make_pair((Deque[fin - 2].pente - a.pente) * (Deque[fin - 1].cst - Deque[fin - 2].cst), Deque[fin - 1].prix))
        fin --;
    Deque[fin ++] = a;
    return;
}
 
pair <long long, int> GetMin(long long absc) {
    while (fin > deb + 1 && make_pair(absc * Deque[deb].pente + Deque[deb].cst, Deque[deb].prix) > make_pair(absc * Deque[deb + 1].pente + Deque[deb + 1].cst, Deque[deb + 1].prix))
        deb ++;
    return {Deque[deb].pente * absc + Deque[deb].cst, Deque[deb].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)
        {
            long long d = max(0LL, Points[i].second - Points[i + 1].first);
            Insert({- 2 * Points[i + 1].first,
            Points[i + 1].first * Points[i + 1].first - d * d + 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] = {Colonnes[i] + 1, Lignes[i]};
    }
    sort(Aliens, Aliens + nbAliens);
    
    for (int i = 0; i < nbAliens; i ++)
    {
        while (nbPoints > 0 && (int)Points[nbPoints - 1].first >= Aliens[i].second)
            nbPoints --;
        if (nbPoints == 0 || (int)Points[nbPoints - 1].second < Aliens[i].first)
            Points[nbPoints ++] = {Aliens[i].second, Aliens[i].first};
    }
    
    long long lambda = -1;
    long long ans = 0;
    
    long long gauche = 0, droite = tailleMax * tailleMax;
    
    while (gauche <= droite)
    {
        long long milieu = (gauche + droite) / 2;
        pair <long long, int> dp = FindDP(milieu);
        if (dp.second <= nbPhotos)
        {
            ans = dp.first - dp.second * milieu;
            droite = milieu - 1;
        }
        else
            gauche = milieu + 1;
    }
    
    return ans - gauche * nbPhotos;
    /*
    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) * DP.second;
        else
            lambda += i;
    }
    return ans;*/
}

Compilation message

aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:79:15: warning: unused variable 'lambda' [-Wunused-variable]
   79 |     long long lambda = -1;
      |               ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 272 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 4
4 Correct 0 ms 204 KB Correct answer: answer = 12
5 Correct 1 ms 204 KB Correct answer: answer = 52
6 Correct 1 ms 204 KB Correct answer: answer = 210
7 Correct 1 ms 204 KB Correct answer: answer = 88
8 Correct 1 ms 204 KB Correct answer: answer = 7696
9 Correct 1 ms 204 KB Correct answer: answer = 1
10 Correct 1 ms 204 KB Correct answer: answer = 2374
11 Correct 1 ms 204 KB Correct answer: answer = 9502
12 Correct 1 ms 204 KB Correct answer: answer = 49
13 Correct 0 ms 204 KB Correct answer: answer = 151
14 Correct 1 ms 204 KB Correct answer: answer = 7550
15 Correct 1 ms 204 KB Correct answer: answer = 7220
16 Correct 1 ms 204 KB Correct answer: answer = 7550
17 Correct 1 ms 204 KB Correct answer: answer = 10000
18 Correct 1 ms 204 KB Correct answer: answer = 10000
19 Correct 1 ms 204 KB Correct answer: answer = 624
20 Correct 1 ms 204 KB Correct answer: answer = 10000
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 1
2 Incorrect 1 ms 204 KB Wrong answer: output = 2, expected = 4
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 272 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 4
4 Correct 0 ms 204 KB Correct answer: answer = 12
5 Correct 1 ms 204 KB Correct answer: answer = 52
6 Correct 1 ms 204 KB Correct answer: answer = 210
7 Correct 1 ms 204 KB Correct answer: answer = 88
8 Correct 1 ms 204 KB Correct answer: answer = 7696
9 Correct 1 ms 204 KB Correct answer: answer = 1
10 Correct 1 ms 204 KB Correct answer: answer = 2374
11 Correct 1 ms 204 KB Correct answer: answer = 9502
12 Correct 1 ms 204 KB Correct answer: answer = 49
13 Correct 0 ms 204 KB Correct answer: answer = 151
14 Correct 1 ms 204 KB Correct answer: answer = 7550
15 Correct 1 ms 204 KB Correct answer: answer = 7220
16 Correct 1 ms 204 KB Correct answer: answer = 7550
17 Correct 1 ms 204 KB Correct answer: answer = 10000
18 Correct 1 ms 204 KB Correct answer: answer = 10000
19 Correct 1 ms 204 KB Correct answer: answer = 624
20 Correct 1 ms 204 KB Correct answer: answer = 10000
21 Correct 1 ms 204 KB Correct answer: answer = 1
22 Incorrect 1 ms 204 KB Wrong answer: output = 2, expected = 4
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 272 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 4
4 Correct 0 ms 204 KB Correct answer: answer = 12
5 Correct 1 ms 204 KB Correct answer: answer = 52
6 Correct 1 ms 204 KB Correct answer: answer = 210
7 Correct 1 ms 204 KB Correct answer: answer = 88
8 Correct 1 ms 204 KB Correct answer: answer = 7696
9 Correct 1 ms 204 KB Correct answer: answer = 1
10 Correct 1 ms 204 KB Correct answer: answer = 2374
11 Correct 1 ms 204 KB Correct answer: answer = 9502
12 Correct 1 ms 204 KB Correct answer: answer = 49
13 Correct 0 ms 204 KB Correct answer: answer = 151
14 Correct 1 ms 204 KB Correct answer: answer = 7550
15 Correct 1 ms 204 KB Correct answer: answer = 7220
16 Correct 1 ms 204 KB Correct answer: answer = 7550
17 Correct 1 ms 204 KB Correct answer: answer = 10000
18 Correct 1 ms 204 KB Correct answer: answer = 10000
19 Correct 1 ms 204 KB Correct answer: answer = 624
20 Correct 1 ms 204 KB Correct answer: answer = 10000
21 Correct 1 ms 204 KB Correct answer: answer = 1
22 Incorrect 1 ms 204 KB Wrong answer: output = 2, expected = 4
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 272 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 4
4 Correct 0 ms 204 KB Correct answer: answer = 12
5 Correct 1 ms 204 KB Correct answer: answer = 52
6 Correct 1 ms 204 KB Correct answer: answer = 210
7 Correct 1 ms 204 KB Correct answer: answer = 88
8 Correct 1 ms 204 KB Correct answer: answer = 7696
9 Correct 1 ms 204 KB Correct answer: answer = 1
10 Correct 1 ms 204 KB Correct answer: answer = 2374
11 Correct 1 ms 204 KB Correct answer: answer = 9502
12 Correct 1 ms 204 KB Correct answer: answer = 49
13 Correct 0 ms 204 KB Correct answer: answer = 151
14 Correct 1 ms 204 KB Correct answer: answer = 7550
15 Correct 1 ms 204 KB Correct answer: answer = 7220
16 Correct 1 ms 204 KB Correct answer: answer = 7550
17 Correct 1 ms 204 KB Correct answer: answer = 10000
18 Correct 1 ms 204 KB Correct answer: answer = 10000
19 Correct 1 ms 204 KB Correct answer: answer = 624
20 Correct 1 ms 204 KB Correct answer: answer = 10000
21 Correct 1 ms 204 KB Correct answer: answer = 1
22 Incorrect 1 ms 204 KB Wrong answer: output = 2, expected = 4
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 272 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 4
4 Correct 0 ms 204 KB Correct answer: answer = 12
5 Correct 1 ms 204 KB Correct answer: answer = 52
6 Correct 1 ms 204 KB Correct answer: answer = 210
7 Correct 1 ms 204 KB Correct answer: answer = 88
8 Correct 1 ms 204 KB Correct answer: answer = 7696
9 Correct 1 ms 204 KB Correct answer: answer = 1
10 Correct 1 ms 204 KB Correct answer: answer = 2374
11 Correct 1 ms 204 KB Correct answer: answer = 9502
12 Correct 1 ms 204 KB Correct answer: answer = 49
13 Correct 0 ms 204 KB Correct answer: answer = 151
14 Correct 1 ms 204 KB Correct answer: answer = 7550
15 Correct 1 ms 204 KB Correct answer: answer = 7220
16 Correct 1 ms 204 KB Correct answer: answer = 7550
17 Correct 1 ms 204 KB Correct answer: answer = 10000
18 Correct 1 ms 204 KB Correct answer: answer = 10000
19 Correct 1 ms 204 KB Correct answer: answer = 624
20 Correct 1 ms 204 KB Correct answer: answer = 10000
21 Correct 1 ms 204 KB Correct answer: answer = 1
22 Incorrect 1 ms 204 KB Wrong answer: output = 2, expected = 4
23 Halted 0 ms 0 KB -