#4841
În urma petrecerii de ziua lui RAU-Gigel, copiii au primit atâtea bomboane încât au câștigat o energie debordantă – așa că l-au provocat pe RAU-Gigel la un concurs de … numărat!
Acestora li se dă o matrice cu N linii și M coloane, în care fiecare element este un număr natural nenul. Obiectivul lor este să determine câte submatrice (sub-dreptunghiuri formate din linii și coloane contigue) conțin exact K valori distincte.
RAU-Coder 2025
| Problema | MatriceInteresanta | Operații I/O |
matriceinteresanta.in/matriceinteresanta.out
|
|---|---|---|---|
| Limita timp | 2 secunde | Limita memorie |
Total: 128 MB
/
Stivă 32 MB
|
| Id soluție | #62921422 | Utilizator | |
| Fișier | matriceinteresanta.cpp | Dimensiune | 6.64 KB |
| Data încărcării | 06 Februarie 2026, 12:54 | Scor/rezultat | Eroare de compilare |
matriceinteresanta.cpp:11:5: error: stray '\304' in program long long res = 0;Desigur! Această problemă este una clasică de submatrice cu exact K valori distincte, și e destul de dificilă dacă încercăm să enumerăm toate submatricele direct (complexitate � sau mai mare). ^ matriceinteresanta.cpp:11:5: error: stray '\203' in program matriceinteresanta.cpp:11:5: error: stray '\304' in program matriceinteresanta.cpp:11:5: error: stray '\203' in program matriceinteresanta.cpp:11:5: error: stray '\304' in program matriceinteresanta.cpp:11:5: error: stray '\203' in program matriceinteresanta.cpp:11:5: error: stray '\310' in program matriceinteresanta.cpp:11:5: error: stray '\231' in program matriceinteresanta.cpp:11:5: error: stray '\304' in program matriceinteresanta.cpp:11:5: error: stray '\203' in program matriceinteresanta.cpp:11:5: error: stray '\304' in program matriceinteresanta.cpp:11:5: error: stray '\203' in program matriceinteresanta.cpp:11:5: error: stray '\303' in program matriceinteresanta.cpp:11:5: error: stray '\256' in program matriceinteresanta.cpp:11:5: error: stray '\304' in program matriceinteresanta.cpp:11:5: error: stray '\203' in program matriceinteresanta.cpp:11:5: error: stray '\304' in program matriceinteresanta.cpp:11:5: error: stray '\203' in program matriceinteresanta.cpp:11:5: error: stray '\304' in program matriceinteresanta.cpp:11:5: error: stray '\203' in program matriceinteresanta.cpp:11:5: error: stray '\357' in program matriceinteresanta.cpp:11:5: error: stray '\277' in program matriceinteresanta.cpp:11:5: error: stray '\275' in program matriceinteresanta.cpp:12:1: error: stray '\304' in program O strategie eficientă e să folosim tehnica de „two pointers” / sliding window pe coloane pentru fiecare pereche de rânduri combinată cu un hash map pentru numărarea valorilor distincte. ^ matriceinteresanta.cpp:12:1: error: stray '\203' in program matriceinteresanta.cpp:12:1: error: stray '\304' in program matriceinteresanta.cpp:12:1: error: stray '\203' in program matriceinteresanta.cpp:12:1: error: stray '\342' in program matriceinteresanta.cpp:12:1: error: stray '\200' in program matriceinteresanta.cpp:12:1: error: stray '\236' in program matriceinteresanta.cpp:12:1: error: stray '\342' in program matriceinteresanta.cpp:12:1: error: stray '\200' in program matriceinteresanta.cpp:12:1: error: stray '\235' in program matriceinteresanta.cpp:12:1: error: stray '\303' in program matriceinteresanta.cpp:12:1: error: stray '\242' in program matriceinteresanta.cpp:12:1: error: stray '\304' in program matriceinteresanta.cpp:12:1: error: stray '\203' in program matriceinteresanta.cpp:12:1: error: stray '\304' in program matriceinteresanta.cpp:12:1: error: stray '\203' in program matriceinteresanta.cpp:13:1: error: stray '\303' in program Voi scrie un exemplu de implementare în C++ pas cu pas: ^ matriceinteresanta.cpp:13:1: error: stray '\256' in program matriceinteresanta.cpp:106:1: error: stray '\360' in program 🔹 Observații importante: ^ matriceinteresanta.cpp:106:1: error: stray '\237' in program matriceinteresanta.cpp:106:1: error: stray '\224' in program matriceinteresanta.cpp:106:1: error: stray '\271' in program matriceinteresanta.cpp:106:1: error: stray '\310' in program matriceinteresanta.cpp:106:1: error: stray '\233' in program matriceinteresanta.cpp:107:1: error: stray '\304' in program Problema e foarte dificilă la N, M mari dacă vrem să numărăm exact fără optimizare. ^ matriceinteresanta.cpp:107:1: error: stray '\203' in program matriceinteresanta.cpp:107:1: error: stray '\304' in program matriceinteresanta.cpp:107:1: error: stray '\203' in program matriceinteresanta.cpp:107:1: error: stray '\304' in program matriceinteresanta.cpp:107:1: error: stray '\203' in program matriceinteresanta.cpp:107:1: error: stray '\304' in program matriceinteresanta.cpp:107:1: error: stray '\203' in program matriceinteresanta.cpp:107:1: error: stray '\304' in program matriceinteresanta.cpp:107:1: error: stray '\203' in program matriceinteresanta.cpp:107:1: error: stray '\304' in program matriceinteresanta.cpp:107:1: error: stray '\203' in program matriceinteresanta.cpp:107:1: error: stray '\304' in program matriceinteresanta.cpp:107:1: error: stray '\203' in program matriceinteresanta.cpp:109:1: error: stray '\304' in program Fixarea a două rânduri top și bottom. ^ matriceinteresanta.cpp:109:1: error: stray '\203' in program matriceinteresanta.cpp:109:1: error: stray '\303' in program matriceinteresanta.cpp:109:1: error: stray '\242' in program matriceinteresanta.cpp:109:1: error: stray '\310' in program matriceinteresanta.cpp:109:1: error: stray '\231' in program matriceinteresanta.cpp:110:1: error: stray '\303' in program Transformarea problemei într-un vector 1D de coloane care conține valorile din rândurile selectate. ^ matriceinteresanta.cpp:110:1: error: stray '\256' in program matriceinteresanta.cpp:110:1: error: stray '\310' in program matriceinteresanta.cpp:110:1: error: stray '\233' in program matriceinteresanta.cpp:110:1: error: stray '\303' in program matriceinteresanta.cpp:110:1: error: stray '\242' in program matriceinteresanta.cpp:111:1: error: stray '\304' in program Folosirea sliding window cu map pentru distincte pentru a număra submatricele care încep de la orice coloană și se termină la orice coloană între top-bottom. ^ matriceinteresanta.cpp:111:1: error: stray '\203' in program matriceinteresanta.cpp:111:1: error: stray '\303' in program matriceinteresanta.cpp:111:1: error: stray '\256' in program matriceinteresanta.cpp:111:1: error: stray '\304' in program matriceinteresanta.cpp:111:1: error: stray '\203' in program matriceinteresanta.cpp:111:1: error: stray '\310' in program matriceinteresanta.cpp:111:1: error: stray '\231' in program matriceinteresanta.cpp:111:1: error: stray '\304' in program matriceinteresanta.cpp:111:1: error: stray '\203' in program matriceinteresanta.cpp:111:1: error: stray '\304' in program matriceinteresanta.cpp:111:1: error: stray '\203' in program matriceinteresanta.cpp:111:1: error: stray '\303' in program matriceinteresanta.cpp:111:1: error: stray '\256' in program matriceinteresanta.cpp:113:1: error: stray '\304' in program Complexitatea finală poate ajunge la O(N^2 * M), ceea ce e rezonabil pentru N, M ≤ 500. ^ matriceinteresanta.cpp:113:1: error: stray '\203' in program matriceinteresanta.cpp:113:1: error: stray '\342' in program matriceinteresanta.cpp:113:1: error: stray '\211' in program matriceinteresanta.cpp:113:1: error: stray '\244' in program matriceinteresanta.cpp:114:1: error: stray '\304' in program Dacă vrei, pot să-ți scriu varianta completă funcțională în C++ care chiar calculează exact K distinct și scrie rezultatul în fișier. ^ matriceinteresanta.cpp:114:1: error: stray '\203' in program matriceinteresanta.cpp:114:1: error: stray '\304' in program matriceinteresanta.cpp:114:1: error: stray '\203' in program matriceinteresanta.cpp:114:1: error: stray '\310' in program matriceinteresanta.cpp:114:1: error: stray '\233' in program matriceinteresanta.cpp:114:1: error: stray '\304' in program matriceinteresanta.cpp:114:1: error: stray '\203' in program matriceinteresanta.cpp:114:1: error: stray '\310' in program matriceinteresanta.cpp:114:1: error: stray '\233' in program matriceinteresanta.cpp:114:1: error: stray '\304' in program matriceinteresanta.cpp:114:1: error: stray '\203' in program matriceinteresanta.cpp:114:1: error: stray '\303' in program matriceinteresanta.cpp:114:1: error: stray '\256' in program matriceinteresanta.cpp:114:1: error: stray '\304' in program matriceinteresanta.cpp:114:1: error: stray '\203' in program matriceinteresanta.cpp:114:1: error: stray '\310' in program matriceinteresanta.cpp:114:1: error: stray '\231' in program matriceinteresanta.cpp:114:1: error: stray '\303' in program matriceinteresanta.cpp:114:1: error: stray '\256' in program matriceinteresanta.cpp:114:1: error: stray '\310' in program matriceinteresanta.cpp:114:1: error: stray '\231' in program matriceinteresanta.cpp:115:1: error: stray '\304' in program Vrei să fac asta? ^ matriceinteresanta.cpp:115:1: error: stray '\203' in program matriceinteresanta.cpp: In function 'long long int countSubarraysWithKDistinct(std::vector<int>&, int)': matriceinteresanta.cpp:11:23: error: 'Desigur' was not declared in this scope long long res = 0;Desigur! Această problemă este una clasică de submatrice cu exact K valori distincte, și e destul de dificilă dacă încercăm să enumerăm toate submatricele direct (complexitate � sau mai mare). ^ matriceinteresanta.cpp:11:30: error: expected ';' before '!' token long long res = 0;Desigur! Această problemă este una clasică de submatrice cu exact K valori distincte, și e destul de dificilă dacă încercăm să enumerăm toate submatricele direct (complexitate � sau mai mare). ^ matriceinteresanta.cpp:19:11: error: declaration of 'int K' shadows a parameter int N, M, K; ^ matriceinteresanta.cpp:23:64: error: a function-definition is not allowed here before '{' token long long countSubarraysWithKDistinct(vector<int>& arr, int K) { ^ matriceinteresanta.cpp:11:15: warning: unused variable 'res' [-Wunused-variable] long long res = 0;Desigur! Această problemă este una clasică de submatrice cu exact K valori distincte, și e destul de dificilă dacă încercăm să enumerăm toate submatricele direct (complexitate � sau mai mare). ^ matriceinteresanta.cpp:19:5: warning: unused variable 'N' [-Wunused-variable] int N, M, K; ^ matriceinteresanta.cpp:19:8: warning: unused variable 'M' [-Wunused-variable] int N, M, K; ^ matriceinteresanta.cpp:19:11: warning: unused variable 'K' [-Wunused-variable] int N, M, K; ^ matriceinteresanta.cpp:194:13: error: expected '}' at end of input return 0; ^ matriceinteresanta.cpp:194:13: warning: no return statement in function returning non-void [-Wreturn-type]
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema MatriceInteresanta 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ă.