#1027
Cool
Se consideră un șir A
format din N
elemente naturale nenule. Numim secvență de lungime K
a șirului A
orice succesiune de elemente consecutive din șir de forma A
i
, A
i+1
,…, A
i+K-1
.
O secvență o numim secvență cool dacă elementele care o compun sunt distincte și pot fi rearanjate astfel încât să alcătuiască o secvență continuă de numere consecutive.
De exemplu, considerând șirul A=(3,1,6,8,4,5,6,7,4,3,4)
, atunci secvența (8,4,5,6,7)
este o secvență cool deoarece conține elemente distincte ce pot fi rearanjate astfel încât să alcătuiască șirul de numere consecutive 4,5,6,7,8,
pe când secvențele (4,3,4), (6,7,4,3)
nu sunt considerate secvențe cool.
Fiind dat un şir de N
numere naturale nenule se cer următoarele:
1. Pentru o valoare dată K
să se verifice dacă secvența A
1
, A
2
,…, A
K
este secvență cool. Dacă secvența este cool, atunci se va afișa cea mai mare valoare ce aparține secvenței. Dacă secvența nu este cool, atunci se va afișa numărul elementelor distincte din secvența A
1
, A
2
,…, A
K
, adică numărul elementelor care apar o singură dată.
2. Lungimea maximă a unei secvențe cool și numărul secvențelor cool de lungime maximă.
OJI 2014, Clasa a IX-a
Problema | Cool | Operații I/O |
cool.in /cool.out
|
---|---|---|---|
Limita timp | 0.5 secunde | Limita memorie |
Total: 2 MB
/
Stivă 1 MB
|
Id soluție | #49779394 | Utilizator | |
Fișier | cool.cpp | Dimensiune | 2.90 KB |
Data încărcării | 14 Martie 2024, 17:00 | Scor / rezultat | Eroare de compilare |
In file included from /usr/include/c++/4.8/algorithm:62:0, from cool.cpp:4: /usr/include/c++/4.8/bits/stl_algo.h: In instantiation of 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]': /usr/include/c++/4.8/bits/stl_algo.h:2211:62: required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' /usr/include/c++/4.8/bits/stl_algo.h:5462:47: required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' cool.cpp:25:42: required from here /usr/include/c++/4.8/bits/stl_algo.h:2142:17: error: assignment of read-only location '__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator*<const int*, std::vector<int> >()' *__first = _GLIBCXX_MOVE(__val); ^ In file included from /usr/include/c++/4.8/bits/stl_algo.h:61:0, from /usr/include/c++/4.8/algorithm:62, from cool.cpp:4: /usr/include/c++/4.8/bits/stl_heap.h: In instantiation of 'void std::__pop_heap(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]': /usr/include/c++/4.8/bits/stl_algo.h:1936:42: required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' /usr/include/c++/4.8/bits/stl_algo.h:5308:51: required from 'void std::partial_sort(_RAIter, _RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' /usr/include/c++/4.8/bits/stl_algo.h:2310:60: required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; _Size = int]' /usr/include/c++/4.8/bits/stl_algo.h:5461:36: required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' cool.cpp:25:42: required from here /usr/include/c++/4.8/bits/stl_heap.h:262:17: error: assignment of read-only location '__result.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator*<const int*, std::vector<int> >()' *__result = _GLIBCXX_MOVE(*__first); ^ /usr/include/c++/4.8/bits/stl_heap.h: In instantiation of 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; _Distance = int; _Tp = int]': /usr/include/c++/4.8/bits/stl_heap.h:407:71: required from 'void std::make_heap(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' /usr/include/c++/4.8/bits/stl_algo.h:1933:39: required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' /usr/include/c++/4.8/bits/stl_algo.h:5308:51: required from 'void std::partial_sort(_RAIter, _RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' /usr/include/c++/4.8/bits/stl_algo.h:2310:60: required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; _Size = int]' /usr/include/c++/4.8/bits/stl_algo.h:5461:36: required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' cool.cpp:25:42: required from here /usr/include/c++/4.8/bits/stl_heap.h:237:29: error: assignment of read-only location '__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator+<const int*, std::vector<int> >((*(const difference_type*)(& __holeIndex))).__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator*<const int*, std::vector<int> >()' *(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first + __secondChild)); ^ /usr/include/c++/4.8/bits/stl_heap.h:243:29: error: assignment of read-only location '__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator+<const int*, std::vector<int> >((*(const difference_type*)(& __holeIndex))).__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator*<const int*, std::vector<int> >()' *(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first ^ In file included from /usr/include/c++/4.8/bits/stl_pair.h:59:0, from /usr/include/c++/4.8/bits/stl_algobase.h:64, from /usr/include/c++/4.8/bits/char_traits.h:39, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from cool.cpp:1: /usr/include/c++/4.8/bits/move.h: In instantiation of 'void std::swap(_Tp&, _Tp&) [with _Tp = const int]': /usr/include/c++/4.8/bits/stl_algobase.h:147:22: required from 'void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; _ForwardIterator2 = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' /usr/include/c++/4.8/bits/stl_algo.h:88:34: required from 'void std::__move_median_to_first(_Iterator, _Iterator, _Iterator, _Iterator) [with _Iterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' /usr/include/c++/4.8/bits/stl_algo.h:2282:74: required from '_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' /usr/include/c++/4.8/bits/stl_algo.h:2315:54: required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; _Size = int]' /usr/include/c++/4.8/bits/stl_algo.h:5461:36: required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' cool.cpp:25:42: required from here /usr/include/c++/4.8/bits/move.h:176:11: error: assignment of read-only reference '__a' __a = _GLIBCXX_MOVE(__b); ^ /usr/include/c++/4.8/bits/move.h:177:11: error: assignment of read-only reference '__b' __b = _GLIBCXX_MOVE(__tmp); ^ In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from cool.cpp:1: /usr/include/c++/4.8/bits/stl_algobase.h: In instantiation of '_BI2 std::__copy_move_backward_a(_BI1, _BI1, _BI2) [with bool _IsMove = true; _BI1 = const int*; _BI2 = const int*]': /usr/include/c++/4.8/bits/stl_algobase.h:596:33: required from '_BI2 std::__copy_move_backward_a2(_BI1, _BI1, _BI2) [with bool _IsMove = true; _BI1 = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; _BI2 = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' /usr/include/c++/4.8/bits/stl_algobase.h:667:15: required from '_BI2 std::move_backward(_BI1, _BI1, _BI2) [with _BI1 = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; _BI2 = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' /usr/include/c++/4.8/bits/stl_algo.h:2141:8: required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' /usr/include/c++/4.8/bits/stl_algo.h:2211:62: required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' /usr/include/c++/4.8/bits/stl_algo.h:5462:47: required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >]' cool.cpp:25:42: required from here /usr/include/c++/4.8/bits/stl_algobase.h:587:18: error: no matching function for call to 'std::__copy_move_backward<true, true, std::random_access_iterator_tag>::__copy_move_b(const int*&, const int*&, const int*&)' __result); ^ /usr/include/c++/4.8/bits/stl_algobase.h:587:18: note: candidate is: /usr/include/c++/4.8/bits/stl_algobase.h:563:9: note: template<class _Tp> static _Tp* std::__copy_move_backward<_IsMove, true, std::random_access_iterator_tag>::__copy_move_b(const _Tp*, const _Tp*, _Tp*) [with _Tp = _Tp; bool _IsMove = true] __copy_move_b(const _Tp* __first, const _Tp* __last, _Tp* __result) ^ /usr/include/c++/4.8/bits/stl_algobase.h:563:9: note: template argument deduction/substitution failed: /usr/include/c++/4.8/bits/stl_algobase.h:587:18: note: deduced conflicting types for parameter '_Tp' ('int' and 'const int') __result); ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema Cool face parte din prima categorie. Soluția propusă de tine va fi evaluată astfel:
Suma punctajelor acordate pe testele utilizate pentru verificare este 100. Astfel, soluția ta poate obține cel mult 100 de puncte, caz în care se poate considera corectă.