#4995
În laboratoarele Marii Ghilde, ucenicul Jean Carapace are pe masa de lucru N eprubete asezate in linie. Eprubetele sunt numerotate de la stanga la dreapta cu indici de la 1 la N. Fiecare eprubetă i conține inițial o cantitate de Esență Primordială, V[i] , număr natural nenul. Definim o „Pereche Pură” ca fiind două eprubete vecine ale căror cantități sunt reprezentate prin numere prime între ele, adică cmmdc(V[i] , V[i+1]) = 1. O proprietate esențială a configurației inițiale este că se garantează existent, a a cel puțin unei astfel de perechi.
Scopul lui este să obțină „Scara Perfectă”, adică o configurație în care cantitatea de esență din fiecare eprubetă este
egală cu indicele ei:
Eprubeta 1 = 1, Eprubeta 2 = 2, …, Eprubeta N = N.

Pentru a modifica nivelul substanței, el poate folosi doar fenomenul de Rezonanță între două eprubete vecine. Mai exact, operațiile se aplică pe două eprubete situate la indicii A și B, cu condiția ca |A − B| = 1. Operațiile permise sunt:
adun A B ⇒ V[A] ← V[A] + V[B] (Eprubeta A câștigă o cantitate de esență egală cu valoarea din eprubeta B)scad A B ⇒ V[A] ← V[A] − V[B] (Eprubeta A pierde o cantitate de esență egală cu valoarea din eprubeta B)La aplicarea operațiilor, trebuie respectate următoarele reguli:
1. La fiecare operație, doar eprubeta cu indicele A își modifică valoarea. Eprubeta cu indicele B rămâne neschimbată.
2. Cantitatea de esență din orice eprubetă trebuie să se mențină în intervalul de siguranță [1, 10sup>5] în orice moment (inclusiv intermediar).
3. Numărul total de operații nu poate depăși 106.
Se cunosc C (numărul cerinței, 1 sau 2), N numărul de eprubete, precum și valorile V[i]. Determinați:
C = 1. Dacă există mai multe astfel de secvențe, se va afișa cea cu indicele de început minim.C = 2.ONI 2026, clasa a 7-a
| Problema | Alchimie | Operații I/O |
alchimie.in/alchimie.out
|
|---|---|---|---|
| Limita timp | 0.2 secunde | Limita memorie |
Total: 16 MB
/
Stivă 8 MB
|
| Id soluție | #64123107 | Utilizator | |
| Fișier | alchimie.cpp | Dimensiune | 5.88 KB |
| Data încărcării | 18 Aprilie 2026, 17:08 | Scor/rezultat | 50 puncte |
alchimie.cpp: In function ‘int main()’: alchimie.cpp:84:35: warning: narrowing conversion of ‘st’ from ‘int’ to ‘short int’ [-Wnarrowing] 84 | ans.push_back({0, st, dr}); //0 inseamna operatie de scadere | ^~ alchimie.cpp:84:39: warning: narrowing conversion of ‘dr’ from ‘int’ to ‘short int’ [-Wnarrowing] 84 | ans.push_back({0, st, dr}); //0 inseamna operatie de scadere | ^~ alchimie.cpp:89:35: warning: narrowing conversion of ‘dr’ from ‘int’ to ‘short int’ [-Wnarrowing] 89 | ans.push_back({0, dr, st}); | ^~ alchimie.cpp:89:39: warning: narrowing conversion of ‘st’ from ‘int’ to ‘short int’ [-Wnarrowing] 89 | ans.push_back({0, dr, st}); | ^~ alchimie.cpp:108:39: warning: narrowing conversion of ‘p1’ from ‘int’ to ‘short int’ [-Wnarrowing] 108 | ans.push_back({1, p1, p2}); //1 inseamna operatie de adunare | ^~ alchimie.cpp:108:43: warning: narrowing conversion of ‘p2’ from ‘int’ to ‘short int’ [-Wnarrowing] 108 | ans.push_back({1, p1, p2}); //1 inseamna operatie de adunare | ^~ alchimie.cpp:118:39: warning: narrowing conversion of ‘p2’ from ‘int’ to ‘short int’ [-Wnarrowing] 118 | ans.push_back({1, p2, p1}); | ^~ alchimie.cpp:118:43: warning: narrowing conversion of ‘p1’ from ‘int’ to ‘short int’ [-Wnarrowing] 118 | ans.push_back({1, p2, p1}); | ^~ alchimie.cpp:129:43: warning: narrowing conversion of ‘p1’ from ‘int’ to ‘short int’ [-Wnarrowing] 129 | ans.push_back({0, p1, p2}); | ^~ alchimie.cpp:129:47: warning: narrowing conversion of ‘p2’ from ‘int’ to ‘short int’ [-Wnarrowing] 129 | ans.push_back({0, p1, p2}); | ^~ alchimie.cpp:134:43: warning: narrowing conversion of ‘p2’ from ‘int’ to ‘short int’ [-Wnarrowing] 134 | ans.push_back({0, p2, p1}); | ^~ alchimie.cpp:134:47: warning: narrowing conversion of ‘p1’ from ‘int’ to ‘short int’ [-Wnarrowing] 134 | ans.push_back({0, p2, p1}); | ^~ alchimie.cpp:141:39: warning: narrowing conversion of ‘i’ from ‘int’ to ‘short int’ [-Wnarrowing] 141 | ans.push_back({0, i, p2}); | ^ alchimie.cpp:141:42: warning: narrowing conversion of ‘p2’ from ‘int’ to ‘short int’ [-Wnarrowing] 141 | ans.push_back({0, i, p2}); | ^~ alchimie.cpp:151:39: warning: narrowing conversion of ‘p1’ from ‘int’ to ‘short int’ [-Wnarrowing] 151 | ans.push_back({0, p1, p2}); | ^~ alchimie.cpp:151:43: warning: narrowing conversion of ‘p2’ from ‘int’ to ‘short int’ [-Wnarrowing] 151 | ans.push_back({0, p1, p2}); | ^~ alchimie.cpp:156:39: warning: narrowing conversion of ‘p2’ from ‘int’ to ‘short int’ [-Wnarrowing] 156 | ans.push_back({0, p2, p1}); | ^~ alchimie.cpp:156:43: warning: narrowing conversion of ‘p1’ from ‘int’ to ‘short int’ [-Wnarrowing] 156 | ans.push_back({0, p2, p1}); | ^~ alchimie.cpp:177:39: warning: narrowing conversion of ‘p1’ from ‘int’ to ‘short int’ [-Wnarrowing] 177 | ans.push_back({1, p1, p2}); //1 inseamna operatie de adunare | ^~ alchimie.cpp:177:43: warning: narrowing conversion of ‘p2’ from ‘int’ to ‘short int’ [-Wnarrowing] 177 | ans.push_back({1, p1, p2}); //1 inseamna operatie de adunare | ^~ alchimie.cpp:187:39: warning: narrowing conversion of ‘p2’ from ‘int’ to ‘short int’ [-Wnarrowing] 187 | ans.push_back({1, p2, p1}); | ^~ alchimie.cpp:187:43: warning: narrowing conversion of ‘p1’ from ‘int’ to ‘short int’ [-Wnarrowing] 187 | ans.push_back({1, p2, p1}); | ^~ alchimie.cpp:198:43: warning: narrowing conversion of ‘p1’ from ‘int’ to ‘short int’ [-Wnarrowing] 198 | ans.push_back({0, p1, p2}); | ^~ alchimie.cpp:198:47: warning: narrowing conversion of ‘p2’ from ‘int’ to ‘short int’ [-Wnarrowing] 198 | ans.push_back({0, p1, p2}); | ^~ alchimie.cpp:203:43: warning: narrowing conversion of ‘p2’ from ‘int’ to ‘short int’ [-Wnarrowing] 203 | ans.push_back({0, p2, p1}); | ^~ alchimie.cpp:203:47: warning: narrowing conversion of ‘p1’ from ‘int’ to ‘short int’ [-Wnarrowing] 203 | ans.push_back({0, p2, p1}); | ^~ alchimie.cpp:210:39: warning: narrowing conversion of ‘i’ from ‘int’ to ‘short int’ [-Wnarrowing] 210 | ans.push_back({0, i, p2}); | ^ alchimie.cpp:210:42: warning: narrowing conversion of ‘p2’ from ‘int’ to ‘short int’ [-Wnarrowing] 210 | ans.push_back({0, i, p2}); | ^~ alchimie.cpp:220:39: warning: narrowing conversion of ‘p1’ from ‘int’ to ‘short int’ [-Wnarrowing] 220 | ans.push_back({0, p1, p2}); | ^~ alchimie.cpp:220:43: warning: narrowing conversion of ‘p2’ from ‘int’ to ‘short int’ [-Wnarrowing] 220 | ans.push_back({0, p1, p2}); | ^~ alchimie.cpp:225:39: warning: narrowing conversion of ‘p2’ from ‘int’ to ‘short int’ [-Wnarrowing] 225 | ans.push_back({0, p2, p1}); | ^~ alchimie.cpp:225:43: warning: narrowing conversion of ‘p1’ from ‘int’ to ‘short int’ [-Wnarrowing] 225 | ans.push_back({0, p2, p1}); | ^~ alchimie.cpp:233:31: warning: narrowing conversion of ‘i’ from ‘int’ to ‘short int’ [-Wnarrowing] 233 | ans.push_back({1, i, i - 1}); | ^ alchimie.cpp:233:36: warning: narrowing conversion of ‘(i - 1)’ from ‘int’ to ‘short int’ [-Wnarrowing] 233 | ans.push_back({1, i, i - 1}); | ~~^~~ alchimie.cpp:238:25: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<operatie>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare] 238 | for(int i = 0; i<ans.size(); i++) | ~^~~~~~~~~~~ alchimie.cpp:80:19: warning: ‘st’ may be used uninitialized [-Wmaybe-uninitialized] 80 | while(v[st] != v[dr]) | ~~~~^ alchimie.cpp:69:13: note: ‘st’ was declared here 69 | int st, dr; | ^~ alchimie.cpp:80:28: warning: ‘dr’ may be used uninitialized [-Wmaybe-uninitialized] 80 | while(v[st] != v[dr]) | ~~~~^ alchimie.cpp:69:17: note: ‘dr’ was declared here 69 | int st, dr; | ^~
| Test | Timp | Mesaj evaluare | Scor posibil | Scor obținut | ||
|---|---|---|---|---|---|---|
| 1 | 0.001 secunde | OK. | 2 | 2 | ||
| 2 | 0.001 secunde | OK. | 2 | 2 | ||
| 3 | 0.001 secunde | OK. | 2 | 2 | ||
| 4 | 0.001 secunde | OK. | 2 | 2 | ||
| 5 | 0.001 secunde | OK. | 2 | 2 | ||
| 6 | 0.001 secunde | OK. | 2 | 2 | ||
| 7 | 0.001 secunde | OK. | 2 | 2 | ||
| 8 | 0.001 secunde | OK. | 2 | 2 | ||
| 9 | 0.002 secunde | OK. | 2 | 2 | ||
| 10 | 0.003 secunde | OK. | 2 | 2 | ||
| 11 | 0.003 secunde | OK. | 2 | 2 | ||
| 12 | 0.001 secunde | OK. | 2 | 2 | ||
| 13 | 0.002 secunde | OK. | 2 | 2 | ||
| 14 | 0.001 secunde | OK. | 2 | 2 | ||
| 15 | 0.002 secunde | OK. | 2 | 2 | ||
| 16 | 0.002 secunde | OK. | 2 | 2 | ||
| 17 | 0.001 secunde | OK. | 2 | 2 | ||
| 18 | 0.001 secunde | OK. | 2 | 2 | ||
| 19 | 0.002 secunde | OK. | 2 | 2 | ||
| 20 | 0.001 secunde | OK. | 2 | 2 | ||
| 21 | 0.002 secunde | OK. | 2 | 2 | ||
| 22 | 0.001 secunde | Raspuns gresit. | 2 | 0 | ||
| 23 | 0.001 secunde | Raspuns gresit. | 2 | 0 | ||
| 24 | 0.001 secunde | Raspuns gresit. | 2 | 0 | ||
| 25 | 0.003 secunde | Raspuns gresit. | 2 | 0 | ||
| 26 | 0.001 secunde | Raspuns gresit. | 2 | 0 | ||
| 27 | 0.001 secunde | Raspuns gresit. | 2 | 0 | ||
| 28 | 0.002 secunde | Raspuns gresit. | 2 | 0 | ||
| 29 | 0.003 secunde | Raspuns gresit. | 2 | 0 | ||
| 30 | 0.001 secunde | Raspuns gresit. | 2 | 0 | ||
| 31 | 0.001 secunde | Raspuns gresit. | 2 | 0 | ||
| 32 | 0.001 secunde | Raspuns gresit. | 2 | 0 | ||
| 33 | 0.048 secunde | Raspuns gresit. | 2 | 0 | ||
| 34 | 0.029 secunde | Raspuns gresit. | 2 | 0 | ||
| 35 | 0.04 secunde | Raspuns gresit. | 2 | 0 | ||
| 36 | 0.024 secunde | Raspuns gresit. | 2 | 0 | ||
| 37 | 0.017 secunde | Raspuns gresit. | 2 | 0 | ||
| 38 | 0.045 secunde | Raspuns gresit. | 2 | 0 | ||
| 39 | 0.064 secunde | Raspuns gresit. | 2 | 0 | ||
| 40 | 0.06 secunde | Raspuns gresit. | 2 | 0 | ||
| 41 | 0.082 secunde | OK. | 4 | 4 | ||
| 42 | 0.076 secunde | Raspuns gresit. | 4 | 0 | ||
| 43 | 0.112 secunde | OK. | 4 | 4 | ||
| 44 | 0.06 secunde | Raspuns gresit. | 4 | 0 | ||
| 45 | 0.087 secunde | Raspuns gresit. | 4 | 0 | ||
| Punctaj total | 50 | |||||
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema Alchimie 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ă.