Submission #723904

#TimeUsernameProblemLanguageResultExecution timeMemory
723904PetyAliens (IOI16_aliens)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
const long long INF = 1e18;
long long dp[4002][4002], cost[4002][4002];
 
void divide (int k, int st, int dr, int opl, int opr) {
  int mid = (st + dr) / 2;
  int opt = opl;
  for (int i = 1; i <= mid; i++) {
    if (dp[k][mid] > dp[k - 1][i - 1] + cost[i][mid]) {
        dp[k][mid] = dp[k - 1][i - 1] + cost[i][mid];
        opt = i;
    }
  }
 
  if (st == dr)
    return;
  divide(k, st, mid, opl, opt);
  divide(k, mid + 1, dr, opt, opr);
}
 
long long take_photos(int n, int m, int k, vector<int>r, vector<int> c) {
  vector<pair<long long, long long>>p, p2;
  for (int i = 0; i < n; i++) {
    if (r[i] > c[i])
      swap(r[i], c[i]);
    p.push_back({r[i], -c[i]});
  }
  sort(p.begin(), p.end());
  p2.push_back({-1, -1});
  int mx = -1;
  for (int i = 0; i < n; i++) {
    if (-p[i].second > mx)
      p2.push_back({p[i].first, -p[i].second});
    mx = max(mx, -p[i].second);
  }
  n = p2.size() - 1;
  k = min(k, n);
  for (int i = 0; i <= k; i++)
    for (int j = 0; j <= n; j++)
      dp[i][j] = INF;
  for (int j = 0; j <= k; j++)
    dp[j][0] = 0;
  for (int i = 1; i <= n; i++)
    for (long long j = i, mx = 0; j <= n; j++) {
      mx = max(mx, p2[j].second);
      cost[i][j] = ( mx - p2[i].first + 1) * (mx - p2[i].first + 1) - (i > 1 ? max(0, p2[i - 1].second - p2[i].first + 1) * max(0, p2[i - 1].second - p2[i].first + 1) : 0);
    }
  for (int j = 1; j <= n; j++)
    dp[1][j] = cost[1][j];
  for (int i = 2; i <= k; i++) {
    divide(i, 1, n, 1, n);
  }
  return dp[k][n];
}
 
// int main() {
//     int n, m, k;
//     assert(3 == scanf("%d %d %d", &n, &m, &k));
 
 
//     std::vector<int> r(n), c(n);
//     for (int i = 0; i < n; i++) {
//         assert(2 == scanf("%d %d", &r[i], &c[i]));
//     }
//     long long ans = take_photos(n, m, k, r, c);
    
    
//     printf("%lld\n", ans);
//     return 0;
// }
 
/**
 5 7 2
 0 3
 4 4
 4 6
 4 5
 4 6
  
*/

Compilation message (stderr)

aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:37:30: error: no matching function for call to 'max(int&, long long int)'
   37 |     mx = max(mx, -p[i].second);
      |                              ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from aliens.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
aliens.cpp:37:30: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   37 |     mx = max(mx, -p[i].second);
      |                              ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from aliens.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
aliens.cpp:37:30: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   37 |     mx = max(mx, -p[i].second);
      |                              ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from aliens.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
aliens.cpp:37:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   37 |     mx = max(mx, -p[i].second);
      |                              ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from aliens.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
aliens.cpp:37:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   37 |     mx = max(mx, -p[i].second);
      |                              ^
aliens.cpp:49:121: error: no matching function for call to 'max(int, long long int)'
   49 |       cost[i][j] = ( mx - p2[i].first + 1) * (mx - p2[i].first + 1) - (i > 1 ? max(0, p2[i - 1].second - p2[i].first + 1) * max(0, p2[i - 1].second - p2[i].first + 1) : 0);
      |                                                                                                                         ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from aliens.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
aliens.cpp:49:121: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   49 |       cost[i][j] = ( mx - p2[i].first + 1) * (mx - p2[i].first + 1) - (i > 1 ? max(0, p2[i - 1].second - p2[i].first + 1) * max(0, p2[i - 1].second - p2[i].first + 1) : 0);
      |                                                                                                                         ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from aliens.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
aliens.cpp:49:121: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   49 |       cost[i][j] = ( mx - p2[i].first + 1) * (mx - p2[i].first + 1) - (i > 1 ? max(0, p2[i - 1].second - p2[i].first + 1) * max(0, p2[i - 1].second - p2[i].first + 1) : 0);
      |                                                                                                                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from aliens.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
aliens.cpp:49:121: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   49 |       cost[i][j] = ( mx - p2[i].first + 1) * (mx - p2[i].first + 1) - (i > 1 ? max(0, p2[i - 1].second - p2[i].first + 1) * max(0, p2[i - 1].second - p2[i].first + 1) : 0);
      |                                                                                                                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from aliens.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
aliens.cpp:49:121: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   49 |       cost[i][j] = ( mx - p2[i].first + 1) * (mx - p2[i].first + 1) - (i > 1 ? max(0, p2[i - 1].second - p2[i].first + 1) * max(0, p2[i - 1].second - p2[i].first + 1) : 0);
      |                                                                                                                         ^
aliens.cpp:49:166: error: no matching function for call to 'max(int, long long int)'
   49 |       cost[i][j] = ( mx - p2[i].first + 1) * (mx - p2[i].first + 1) - (i > 1 ? max(0, p2[i - 1].second - p2[i].first + 1) * max(0, p2[i - 1].second - p2[i].first + 1) : 0);
      |                                                                                                                                                                      ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from aliens.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
aliens.cpp:49:166: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   49 |       cost[i][j] = ( mx - p2[i].first + 1) * (mx - p2[i].first + 1) - (i > 1 ? max(0, p2[i - 1].second - p2[i].first + 1) * max(0, p2[i - 1].second - p2[i].first + 1) : 0);
      |                                                                                                                                                                      ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from aliens.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
aliens.cpp:49:166: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   49 |       cost[i][j] = ( mx - p2[i].first + 1) * (mx - p2[i].first + 1) - (i > 1 ? max(0, p2[i - 1].second - p2[i].first + 1) * max(0, p2[i - 1].second - p2[i].first + 1) : 0);
      |                                                                                                                                                                      ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from aliens.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
aliens.cpp:49:166: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   49 |       cost[i][j] = ( mx - p2[i].first + 1) * (mx - p2[i].first + 1) - (i > 1 ? max(0, p2[i - 1].second - p2[i].first + 1) * max(0, p2[i - 1].second - p2[i].first + 1) : 0);
      |                                                                                                                                                                      ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from aliens.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
aliens.cpp:49:166: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   49 |       cost[i][j] = ( mx - p2[i].first + 1) * (mx - p2[i].first + 1) - (i > 1 ? max(0, p2[i - 1].second - p2[i].first + 1) * max(0, p2[i - 1].second - p2[i].first + 1) : 0);
      |                                                                                                                                                                      ^