답안 #429316

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
429316 2021-06-15T20:34:59 Z JeanBombeur Aliens (IOI16_aliens) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>
#include "aliens.h"
using namespace std;
 
//    <|°_°|>
 
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 && pair<long long, int>((a.cst - Deque[fin - 1].cst) * (Deque[fin - 2].pente - Deque[fin - 1].pente), a.prix) < pair<long long, int>((Deque[fin - 1].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 && pair<long long, int>(absc * Deque[deb].pente + Deque[deb].cst, Deque[deb].prix) > pair<long long,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 ++)
    {
        long long d1 = 0, d2 = Points[i].first;
        if (i > 0)
            d1 = max(0LL, Points[i - 1].second - Points[i].first);
        Insert({-2 * d2, DP.first - d1 * d1 + d2 * d2, DP.second});
        DP = GetMin(Points[i].second);
        DP.first += Points[i].second * Points[i].second + lambda;
        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 && Aliens[i].second <= (int)Points[nbPoints - 1].second)
            nbPoints --;
        Points[nbPoints ++] = Aliens[i];
    }
    
    for (int i = 0; i < nbPoints; i ++)
    {
        swap(Points[i].first, Points[i].second);
    }
    
    long long lambda = -1;
    long long ans = 0;
    
    long long gauche = 0, droite = (long long)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;
            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 'std::pair<long long int, int> GetMin(long long int)':
aliens.cpp:35:171: error: the value of 'Deque' is not usable in a constant expression
   35 |     while (fin > deb + 1 && pair<long long, int>(absc * Deque[deb].pente + Deque[deb].cst, Deque[deb].prix) > pair<long long,absc * Deque[deb + 1].pente + Deque[deb + 1].cst, Deque[deb + 1].prix))
      |                                                                                                                                                                           ^~~
aliens.cpp:22:8: note: 'Deque' was not declared 'constexpr'
   22 | droite Deque[MAX_POINTS];
      |        ^~~~~
aliens.cpp:35:191: error: the value of 'deb' is not usable in a constant expression
   35 |     while (fin > deb + 1 && pair<long long, int>(absc * Deque[deb].pente + Deque[deb].cst, Deque[deb].prix) > pair<long long,absc * Deque[deb + 1].pente + Deque[deb + 1].cst, Deque[deb + 1].prix))
      |                                                                                                                                                                                               ^~~~
aliens.cpp:23:5: note: 'int deb' is not const
   23 | int deb = 0, fin = 0;
      |     ^~~
aliens.cpp:35:191: error: wrong number of template arguments (3, should be 2)
   35 |     while (fin > deb + 1 && pair<long long, int>(absc * Deque[deb].pente + Deque[deb].cst, Deque[deb].prix) > pair<long long,absc * Deque[deb + 1].pente + Deque[deb + 1].cst, Deque[deb + 1].prix))
      |                                                                                                                                                                                               ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from aliens.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: provided for 'template<class _T1, class _T2> struct std::pair'
  211 |     struct pair
      |            ^~~~
aliens.cpp:35:196: error: expected primary-expression before ')' token
   35 |     while (fin > deb + 1 && pair<long long, int>(absc * Deque[deb].pente + Deque[deb].cst, Deque[deb].prix) > pair<long long,absc * Deque[deb + 1].pente + Deque[deb + 1].cst, Deque[deb + 1].prix))
      |                                                                                                                                                                                                    ^
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:81:15: warning: unused variable 'lambda' [-Wunused-variable]
   81 |     long long lambda = -1;
      |               ^~~~~~