#3442
Parcurgând elementele unei matrice pătratice de dimensiune n în spirală, pornind din colțul din
stânga-sus, în sens orar, de la margini către interior, se obține șirul strict crescător format din toate
valorile de la 1 la n2, ca în figura de mai jos. Din șirul dat se obțin două subșiruri disjuncte, de lungime egală, cu număr maxim de termeni. Primul subșir este format din numere consecutive din prima jumătate a șirului, și trebuie să conțină în mod obligatoriu valoarea 1, iar al doilea este format din numere consecutive din a doua jumătate a șirului și trebuie să conțină în mod obligatoriu valoarea n2.
| 1 | 2 | 3 | 4 | 5 |
| 16 | 17 | 18 | 19 | 6 |
| 15 | 24 | 25 | 20 | 7 |
| 14 | 23 | 22 | 21 | 8 |
| 13 | 12 | 11 | 10 | 9 |
Să se afle poziția în matrice a celui mai mare termen din primul subșir și a celui mai mic termen din al
doilea subșir.
OJI 2020, clasa a IX-a
| Problema | SpiralMatrix | Operații I/O |
spiralmatrix.in/spiralmatrix.out
|
|---|---|---|---|
| Limita timp | 0.2 secunde | Limita memorie |
Total: 64 MB
/
Stivă 32 MB
|
| Id soluție | #64390870 | Utilizator | |
| Fișier | spiralmatrix.cpp | Dimensiune | 1.88 KB |
| Data încărcării | 04 Mai 2026, 21:27 | Scor/rezultat | 55 puncte |
spiralmatrix.cpp: In function ‘int main()’: spiralmatrix.cpp:30:13: warning: ‘maxim’ may be used uninitialized [-Wmaybe-uninitialized] 30 | if (x == maxim) | ^~ spiralmatrix.cpp:10:18: note: ‘maxim’ was declared here 10 | int n, i, j, maxim, minim, imin, jmin, imax, jmax, lung, is = 1, x = 1; | ^~~~~ spiralmatrix.cpp:35:18: warning: ‘minim’ may be used uninitialized [-Wmaybe-uninitialized] 35 | else if (x == minim) | ^~ spiralmatrix.cpp:10:25: note: ‘minim’ was declared here 10 | int n, i, j, maxim, minim, imin, jmin, imax, jmax, lung, is = 1, x = 1; | ^~~~~ spiralmatrix.cpp:92:21: warning: ‘imin’ may be used uninitialized [-Wmaybe-uninitialized] 92 | cout << imin << " " << jmin; | ^~~ spiralmatrix.cpp:10:32: note: ‘imin’ was declared here 10 | int n, i, j, maxim, minim, imin, jmin, imax, jmax, lung, is = 1, x = 1; | ^~~~ spiralmatrix.cpp:92:28: warning: ‘jmin’ may be used uninitialized [-Wmaybe-uninitialized] 92 | cout << imin << " " << jmin; | ^~~~ spiralmatrix.cpp:10:38: note: ‘jmin’ was declared here 10 | int n, i, j, maxim, minim, imin, jmin, imax, jmax, lung, is = 1, x = 1; | ^~~~ spiralmatrix.cpp:91:21: warning: ‘imax’ may be used uninitialized [-Wmaybe-uninitialized] 91 | cout << imax << " " << jmax << endl; | ^~~ spiralmatrix.cpp:10:44: note: ‘imax’ was declared here 10 | int n, i, j, maxim, minim, imin, jmin, imax, jmax, lung, is = 1, x = 1; | ^~~~ spiralmatrix.cpp:91:28: warning: ‘jmax’ may be used uninitialized [-Wmaybe-uninitialized] 91 | cout << imax << " " << jmax << endl; | ^~~~ spiralmatrix.cpp:10:50: note: ‘jmax’ was declared here 10 | int n, i, j, maxim, minim, imin, jmin, imax, jmax, lung, is = 1, x = 1; | ^~~~
| Test | Timp | Mesaj evaluare | Scor posibil | Scor obținut | ||
|---|---|---|---|---|---|---|
| 0 | 0.002 secunde | OK. | 6 | 6 | ||
| 1 | 0.001 secunde | OK. | 3 | 3 | ||
| 2 | 0.002 secunde | OK. | 5 | 5 | ||
| 3 | 0.001 secunde | OK. | 8 | 8 | ||
| 4 | 0.001 secunde | OK. | 9 | 9 | ||
| 5 | 0.001 secunde | OK. | 4 | 4 | ||
| 6 | 0.001 secunde | OK. | 10 | 10 | ||
| 7 | Depășit | Limita de timp depășită | 7 | 0 | ||
| 8 | 0.003 secunde | Raspuns gresit. | 11 | 0 | ||
| 9 | 0.002 secunde | Raspuns gresit. | 12 | 0 | ||
| 10 | Depășit | Limita de timp depășită | 4 | 0 | ||
| 11 | Depășit | Limita de timp depășită | 6 | 0 | ||
| 12 | Depășit | Limita de timp depășită | 5 | 0 | ||
| 13 | 0.002 secunde | OK. | 5 | 5 | Exemplu | |
| 14 | 0.002 secunde | OK. | 5 | 5 | Exemplu | |
| Punctaj total | 55 | |||||
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema SpiralMatrix 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ă.