#4968
În grădina palatului de vară, maestrul grădinar Andrei caută locul perfect pentru amplasarea unui bonsai prezidențial. Grădina palatului este formată din mai multe parcele, dispuse pe N linii și M coloane. Deoarece grădina palatului este frecventată de turiști, fiecărei parcele îi este asociat un număr natural, reprezentând importanța parcelei respective.
Bonsaiul prezidențial poate fi plantat doar sub forma unei cruci simetrice (un centru și 4 brațe egale pe direcțiile Nord, Sud, Est, Vest), care nu conține valori nule (parcele cu importanța 0) și are număr maxim de parcele pe care se poate amplasa un bonsai. Un bonsai este definit de centrul său (i, j) și de raza maximă posibilă R, cu care se poate extinde pe toate cele 4 direcții (numărul de parcele al unui braț, fără a număra centrul). Un bonsai cu R=0 ocupă o singură parcelă (centrul), iar un bonsai cu R=1 ocupă centrul și cei 4 vecini: (i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1). Andrei are trei criterii diferite de alegere, în funcție de cerința președintelui:
R = 0, astfel Andrei trebuie să caute toate locurile posibile în care se poate amplasa un bonsai de rază R = 0.Rmax pe care o poate avea un bonsai în grădină.Cerința
Se dau C, reprezentând cerința care trebuie rezolvată (C = 1, C = 2 sau C = 3), N, M, dimensiunile grădinii și N x M valori naturale, reprezentând importanța fiecărei parcele.
C = 1, ajutați-l pe Andrei să determine în câte locuri posibile din grădină ar putea planta un bonsai de rază R = 0.C = 2, ajutați-l pe Andrei să determine raza maximă Rmax a unui bonsai care poate fi plantat în grădină.C = 3, ajutați-l pe Andrei să determine locul cu importanța maximă în care poate planta bonsaiul, precum și coordonatele (i, j) ale centrului acestuia. Dacă există mai multe locuri cu aceeași importanță maximă, se va alege cel cu raza R cea mai mare. Dacă există mai multe astfel de locuri cu importanța egală și cu aceeași rază R, se va alege locul cu i minim, iar în caz de egalitate, cel cu j minim.OJI 2026, clasa a 7-a
| Problema | bonsai | Operații I/O |
bonsai.in/bonsai.out
|
|---|---|---|---|
| Limita timp | 0.2 secunde | Limita memorie |
Total: 32 MB
/
Stivă 8 MB
|
| Id soluție | #64422119 | Utilizator | |
| Fișier | bonsai.cpp | Dimensiune | 1.33 KB |
| Data încărcării | 06 Mai 2026, 09:48 | Scor/rezultat | Eroare de compilare |
bonsai.cpp: In function ‘int main()’: bonsai.cpp:40:65: error: no match for ‘operator+’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type’ {aka ‘int’} and ‘std::vector<std::vector<int> >’) 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^ ~~~~ | | | std::vector<std::vector<int> > In file included from /usr/include/c++/13/string:48, from /usr/include/c++/13/bits/locale_classes.h:40, from /usr/include/c++/13/bits/ios_base.h:41, from /usr/include/c++/13/ios:44, from /usr/include/c++/13/ostream:40, from /usr/include/c++/13/iostream:41, from bonsai.cpp:1: /usr/include/c++/13/bits/stl_iterator.h:634:5: note: candidate: ‘template<class _Iterator> std::reverse_iterator<_Iterator> std::operator+(typename reverse_iterator<_Iterator>::difference_type, const reverse_iterator<_Iterator>&)’ 634 | operator+(typename reverse_iterator<_Iterator>::difference_type __n, | ^~~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:634:5: note: template argument deduction/substitution failed: bonsai.cpp:40:67: note: ‘std::vector<std::vector<int> >’ is not derived from ‘const std::reverse_iterator<_Iterator>’ 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^~~~ /usr/include/c++/13/bits/stl_iterator.h:1808:5: note: candidate: ‘template<class _Iterator> std::move_iterator<_IteratorL> std::operator+(typename move_iterator<_IteratorL>::difference_type, const move_iterator<_IteratorL>&)’ 1808 | operator+(typename move_iterator<_Iterator>::difference_type __n, | ^~~~~~~~ /usr/include/c++/13/bits/stl_iterator.h:1808:5: note: template argument deduction/substitution failed: bonsai.cpp:40:67: note: ‘std::vector<std::vector<int> >’ is not derived from ‘const std::move_iterator<_IteratorL>’ 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^~~~ In file included from /usr/include/c++/13/string:54: /usr/include/c++/13/bits/basic_string.h:3553:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Alloc>&, const __cxx11::basic_string<_CharT, _Traits, _Alloc>&)’ 3553 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/basic_string.h:3553:5: note: template argument deduction/substitution failed: bonsai.cpp:40:67: note: mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type’ {aka ‘int’} 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^~~~ /usr/include/c++/13/bits/basic_string.h:3571:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Alloc>&)’ 3571 | operator+(const _CharT* __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/basic_string.h:3571:5: note: template argument deduction/substitution failed: bonsai.cpp:40:67: note: mismatched types ‘const _CharT*’ and ‘int’ 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^~~~ /usr/include/c++/13/bits/basic_string.h:3590:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Alloc>&)’ 3590 | operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs) | ^~~~~~~~ /usr/include/c++/13/bits/basic_string.h:3590:5: note: template argument deduction/substitution failed: bonsai.cpp:40:67: note: ‘std::vector<std::vector<int> >’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^~~~ /usr/include/c++/13/bits/basic_string.h:3607:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)’ 3607 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/basic_string.h:3607:5: note: template argument deduction/substitution failed: bonsai.cpp:40:67: note: mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type’ {aka ‘int’} 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^~~~ /usr/include/c++/13/bits/basic_string.h:3625:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Alloc>&, _CharT)’ 3625 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs) | ^~~~~~~~ /usr/include/c++/13/bits/basic_string.h:3625:5: note: template argument deduction/substitution failed: bonsai.cpp:40:67: note: mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type’ {aka ‘int’} 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^~~~ /usr/include/c++/13/bits/basic_string.h:3637:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, const __cxx11::basic_string<_CharT, _Traits, _Alloc>&)’ 3637 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/basic_string.h:3637:5: note: template argument deduction/substitution failed: bonsai.cpp:40:67: note: mismatched types ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type’ {aka ‘int’} 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^~~~ /usr/include/c++/13/bits/basic_string.h:3644:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Alloc>&, __cxx11::basic_string<_CharT, _Traits, _Alloc>&&)’ 3644 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/basic_string.h:3644:5: note: template argument deduction/substitution failed: bonsai.cpp:40:67: note: mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type’ {aka ‘int’} 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^~~~ /usr/include/c++/13/bits/basic_string.h:3651:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, __cxx11::basic_string<_CharT, _Traits, _Alloc>&&)’ 3651 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/basic_string.h:3651:5: note: template argument deduction/substitution failed: bonsai.cpp:40:67: note: mismatched types ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type’ {aka ‘int’} 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^~~~ /usr/include/c++/13/bits/basic_string.h:3674:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Alloc>&&)’ 3674 | operator+(const _CharT* __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/basic_string.h:3674:5: note: template argument deduction/substitution failed: bonsai.cpp:40:67: note: mismatched types ‘const _CharT*’ and ‘int’ 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^~~~ /usr/include/c++/13/bits/basic_string.h:3681:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(_CharT, __cxx11::basic_string<_CharT, _Traits, _Alloc>&&)’ 3681 | operator+(_CharT __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/basic_string.h:3681:5: note: template argument deduction/substitution failed: bonsai.cpp:40:67: note: ‘std::vector<std::vector<int> >’ is not derived from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^~~~ /usr/include/c++/13/bits/basic_string.h:3688:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, const _CharT*)’ 3688 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/basic_string.h:3688:5: note: template argument deduction/substitution failed: bonsai.cpp:40:67: note: mismatched types ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type’ {aka ‘int’} 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^~~~ /usr/include/c++/13/bits/basic_string.h:3695:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, _CharT)’ 3695 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/basic_string.h:3695:5: note: template argument deduction/substitution failed: bonsai.cpp:40:67: note: mismatched types ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type’ {aka ‘int’} 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^~~~ bonsai.cpp:39:21: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation] 39 | for(int k = 1; k <= r; ++k) | ^~~ bonsai.cpp:40:71: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’ 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^ bonsai.cpp:40:71: error: expected ‘}’ at end of input bonsai.cpp:37:24: note: to match this ‘{’ 37 | } else { | ^ bonsai.cpp:40:71: error: expected ‘}’ at end of input 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^ bonsai.cpp:25:42: note: to match this ‘{’ 25 | for (int j = 1; j <= M; ++j) { | ^ bonsai.cpp:40:71: error: expected ‘}’ at end of input 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^ bonsai.cpp:24:38: note: to match this ‘{’ 24 | for (int i = 1; i <= N; ++i) { | ^ bonsai.cpp:40:71: error: expected ‘}’ at end of input 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^ bonsai.cpp:21:34: note: to match this ‘{’ 21 | } else if (C == 2 || C == 3) { | ^ bonsai.cpp:22:23: warning: unused variable ‘bestS’ [-Wunused-variable] 22 | int maxR = 0, bestS = -1, bestI = -1, bestJ = -1; | ^~~~~ bonsai.cpp:22:35: warning: unused variable ‘bestI’ [-Wunused-variable] 22 | int maxR = 0, bestS = -1, bestI = -1, bestJ = -1; | ^~~~~ bonsai.cpp:22:47: warning: unused variable ‘bestJ’ [-Wunused-variable] 22 | int maxR = 0, bestS = -1, bestI = -1, bestJ = -1; | ^~~~~ bonsai.cpp:40:71: error: expected ‘}’ at end of input 40 | currentS += grid[i-k][j] + grid[i+k][j] + grid | ^ bonsai.cpp:7:12: note: to match this ‘{’ 7 | int main() { | ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema bonsai 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ă.