제출 #837069

#제출 시각아이디문제언어결과실행 시간메모리
837069EllinorAliens (IOI16_aliens)C++14
컴파일 에러
0 ms0 KiB
#include <iostream> #include <vector> #include <queue> #include <string> #include <cmath> #include <cstdlib> #include <set> #include <iomanip> #include <limits> #include <map> #include <assert.h> #include <algorithm> #include <list> #include <iterator> #include <fstream> #include <random> #include <unordered_map> #include <array> //#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for (int i = (a); i < b; i++) #define rrep(i,a) for (int i = (a) - 1; i >= 0; i--) #define pb push_back #define all(x) x.begin(), x.end() typedef long long ll; typedef pair<int, int> pii; typedef pair<bool, bool> pbb; // fast #include "aliens.h" // !!! // int N, M; vector<int> diagonal; long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { N = n; M = m; diagonal.assign(M, 0); // -1 ? rep(i,0,N) { int d = min(r[i], c[i]); int da = max(r[i], c[i]) - min(r[i], c[i]) + 1; // +1 // 0-ind diagonal[d] = max(diagonal[d], da); } int d = 0; rep(i,0,M) { d--; // d = max(d, 0); d = max(d, diagonal[i]); diagonal[i] = d; } set<pii> square_start_inds; int last = 0; rep(i,0,M) { last = max(last, 0); if (diagonal[i] > last) { // start of square square_start_inds.insert({i, diagonal[i]}); last = diagonal[i]; } last--; } // squares > 0 if (square_start_inds.size() > k) { // diff // diff, start_ind_1, start_ind_2 set<array<ll, 3>> diff_set; map<pii, ll> diff_map; // ?? auto it = square_start_inds.begin(); pii x = *it; int last_ind = x.first; int last_len = x.second; int now_ind, now_len; for (auto it = square_start_inds.begin(); it != square_start_inds.end(); it++) { it++; x = *it; now_ind = x.first; now_len = x.second; ll diff = 0; ll side = now_ind + now_len - last_ind; // 1 1 ll add = side * side; diff += add; ll rem = last_len * last_len; diff -= rem; rem = now_len * now_len; diff -= rem; // diff_set.insert({diff, last_ind, now_ind}); diff_map[{last_ind, now_ind}] = diff; // last_ind = x.first; last_len = x.second; } while (square_start_inds.size() > k) { // assert(diff_set.size() > 0); // :) // assert(diff_set.size() == square_start_inds.size() - 1); // :) auto it = diff_set.begin(); array<ll, 3> arr = *it; ll diff = arr[0]; ll ind_1 = arr[1]; ll ind_2 = arr[2]; diff_set.erase(it); // ! ll ind_2_len; bool before = false, after = false; ll ind_before, len_before; auto itt = square_start_inds.lower_bound({ind_1, 0}); if (itt != square_start_inds.begin()) { before = true; itt--; pii x = *itt; ind_before = x.first; len_before = x.second; ll diff1 = diff_map[{ind_before, ind_1}]; auto it1 = diff_set.lower_bound({diff1, ind_before, ind_1}); // assert ! diff_set.erase(it1); // square_start_inds.erase(itt); // bort nej // ta bort diff } // else ? ll ind_after, len_after; // ta bort diff // ??? itt = square_start_inds.lower_bound({ind_2, 0}); // ! pii xx = *itt; ind_2_len = xx.second; if (itt != square_start_inds.end()) { itt++; if (itt != square_start_inds.end()) { after = true; pii x = *itt; ind_after = x.first; len_after = x.second; ll diff2 = diff_map[{ind_2, ind_after}]; auto it2 = diff_set.lower_bound({diff2, ind_2, ind_after}); // assert ! diff_set.erase(it2); // square_start_inds.erase(itt); // bort nej // ta bort diff } } ll my_len = ind_2 + ind_2_len - ind_1; // add new diff 1 if (before) { last_ind = ind_before; last_len = len_before; now_ind = ind_1; now_len = my_len; ll diff_ = 0; ll side = now_ind + now_len - last_ind; // 1 1 ll add = side * side; diff_ += add; ll rem = last_len * last_len; diff_ -= rem; rem = now_len * now_len; diff_ -= rem; diff_set.insert({diff_, last_ind, now_ind}); diff_map[{last_ind, now_ind}] = diff_; } // add new diff 2 if (after) { last_ind = ind_1; last_len = my_len; now_ind = ind_after; now_len = len_after; diff_ = 0; side = now_ind + now_len - last_ind; // 1 1 add = side * side; diff_ += add; rem = last_len * last_len; diff_ -= rem; rem = now_len * now_len; diff_ -= rem; diff_set.insert({diff_, last_ind, now_ind}); diff_map[{last_ind, now_ind}] = diff_; } // ta bort square_inds * 2, add * 1 // ta bort 1 auto it3 = square_start_inds.lower_bound({ind_1, 0}); // :) // ? square_start_inds.erase(it3); // ta bort 2 // ??? it3 = square_start_inds.lower_bound({ind_2, 0}); // :) // ? square_start_inds.erase(it3); // add 1 square_start_inds.insert({ind_1, my_len}); } } ll ans = 0; ll last_reach = -1; for (auto it = square_start_inds.begin(); it != square_start_inds.end(); it++) { pii x = *it; ll add = x.second * x.second; ans += add; if (last_reach >= x.first) { int overlap = last_reach - x.first + 1; ll rem = overlap * overlap; ans -= rem; } last_reach = x.first + x.second - 1; } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:80:34: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   80 |     if (square_start_inds.size() > k)
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~^~~
aliens.cpp:124:41: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  124 |         while (square_start_inds.size() > k)
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~^~~
aliens.cpp:227:17: error: 'diff_' was not declared in this scope; did you mean 'diff'?
  227 |                 diff_ = 0;
      |                 ^~~~~
      |                 diff
aliens.cpp:228:17: error: 'side' was not declared in this scope
  228 |                 side = now_ind + now_len - last_ind; // 1 1
      |                 ^~~~
aliens.cpp:229:17: error: 'add' was not declared in this scope; did you mean 'fadd'?
  229 |                 add = side * side;
      |                 ^~~
      |                 fadd
aliens.cpp:232:17: error: 'rem' was not declared in this scope; did you mean 'drem'?
  232 |                 rem = last_len * last_len;
      |                 ^~~
      |                 drem
aliens.cpp:238:59: error: no matching function for call to 'std::set<std::array<long long int, 3> >::insert(<brace-enclosed initializer list>)'
  238 |                 diff_set.insert({diff_, last_ind, now_ind});
      |                                                           ^
In file included from /usr/include/c++/10/set:61,
                 from aliens.cpp:7:
/usr/include/c++/10/bits/stl_set.h:509:7: note: candidate: 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = std::array<long long int, 3>; _Compare = std::less<std::array<long long int, 3> >; _Alloc = std::allocator<std::array<long long int, 3> >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<std::array<long long int, 3>, std::array<long long int, 3>, std::_Identity<std::array<long long int, 3> >, std::less<std::array<long long int, 3> >, std::allocator<std::array<long long int, 3> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = std::array<long long int, 3>]'
  509 |       insert(const value_type& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_set.h:509:32: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::array<long long int, 3>&'}
  509 |       insert(const value_type& __x)
      |              ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:518:7: note: candidate: 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::array<long long int, 3>; _Compare = std::less<std::array<long long int, 3> >; _Alloc = std::allocator<std::array<long long int, 3> >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<std::array<long long int, 3>, std::array<long long int, 3>, std::_Identity<std::array<long long int, 3> >, std::less<std::array<long long int, 3> >, std::allocator<std::array<long long int, 3> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = std::array<long long int, 3>]'
  518 |       insert(value_type&& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_set.h:518:27: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::set<std::array<long long int, 3> >::value_type&&' {aka 'std::array<long long int, 3>&&'}
  518 |       insert(value_type&& __x)
      |              ~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:546:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, const value_type&) [with _Key = std::array<long long int, 3>; _Compare = std::less<std::array<long long int, 3> >; _Alloc = std::allocator<std::array<long long int, 3> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<std::array<long long int, 3>, std::array<long long int, 3>, std::_Identity<std::array<long long int, 3> >, std::less<std::array<long long int, 3> >, std::allocator<std::array<long long int, 3> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<std::array<long long int, 3>, std::array<long long int, 3>, std::_Identity<std::array<long long int, 3> >, std::less<std::array<long long int, 3> >, std::allocator<std::array<long long int, 3> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = std::array<long long int, 3>]'
  546 |       insert(const_iterator __position, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_set.h:546:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/10/bits/stl_set.h:551:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::array<long long int, 3>; _Compare = std::less<std::array<long long int, 3> >; _Alloc = std::allocator<std::array<long long int, 3> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<std::array<long long int, 3>, std::array<long long int, 3>, std::_Identity<std::array<long long int, 3> >, std::less<std::array<long long int, 3> >, std::allocator<std::array<long long int, 3> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<std::array<long long int, 3>, std::array<long long int, 3>, std::_Identity<std::array<long long int, 3> >, std::less<std::array<long long int, 3> >, std::allocator<std::array<long long int, 3> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = std::array<long long int, 3>]'
  551 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_set.h:551:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/10/bits/stl_set.h:566:2: note: candidate: 'template<class _InputIterator> void std::set<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = std::array<long long int, 3>; _Compare = std::less<std::array<long long int, 3> >; _Alloc = std::allocator<std::array<long long int, 3> >]'
  566 |  insert(_InputIterator __first, _InputIterator __last)
      |  ^~~~~~
/usr/include/c++/10/bits/stl_set.h:566:2: note:   template argument deduction/substitution failed:
aliens.cpp:238:59: note:   candidate expects 2 arguments, 1 provided
  238 |                 diff_set.insert({diff_, last_ind, now_ind});
      |                                                           ^
In file included from /usr/include/c++/10/set:61,
                 from aliens.cpp:7:
/usr/include/c++/10/bits/stl_set.h:578:7: note: candidate: 'void std::set<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = std::array<long long int, 3>; _Compare = std::less<std::array<long long int, 3> >; _Alloc = std::allocator<std::array<long long int, 3> >]'
  578 |       insert(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_set.h:578:43: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::initializer_list<std::array<long long int, 3> >'
  578 |       insert(initializer_list<value_type> __l)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
aliens.cpp:131:16: warning: unused variable 'diff' [-Wunused-variable]
  131 |             ll diff = arr[0];
      |                ^~~~