Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #define MAX_NM 30000
- using namespace std;
- ifstream fin("matrice.in");
- ofstream fout("matrice.out");
- int n, m, a, L[MAX_NM + 1], C[MAX_NM + 1];
- int zmax = 0, nsol = 0;
- void Solve(int, int);
- void Update(int, int);
- int main()
- {
- fin >> n >> m >> a;
- // L si C reprezinta sumele partiale pentru linia de sus si coloana din stanga.
- for (int i = 1; i <= n; ++i)
- {
- fin >> C[i];
- C[i] += C[i - 1];
- }
- for (int j = 1; j <= m; ++j)
- {
- fin >> L[j];
- L[j] += L[j - 1];
- }
- for (int d = 1; d * d <= a; ++d)
- {
- if (a % d == 0)
- {
- Solve(d, a / d);
- if (d * d != a)
- Solve(a / d, d);
- }
- }
- fout << zmax << ' ' << nsol;
- return 0;
- }
- void Solve(int w, int h) // Rezolva dreptunghiurile de latime w si inaltime h.
- {
- if (w > m || h > n)
- return;
- int ma1 = 0, cnt_ma1 = 0, ma0 = 0, cnt_ma0 = 0;
- for (int st = 1, dr = w; dr <= m; ++st, ++dr)
- {
- int cnt1 = L[dr] - L[st - 1], cnt0 = w - cnt1;
- if (cnt1 > ma1)
- {
- ma1 = cnt1;
- cnt_ma1 = 1;
- }
- else if (cnt1 == ma1)
- ++cnt_ma1;
- if (cnt0 > ma0)
- {
- ma0 = cnt0;
- cnt_ma0 = 1;
- }
- else if (cnt0 == ma0)
- ++cnt_ma0;
- }
- for (int sus = 1, jos = h; jos <= n; ++sus, ++jos)
- {
- int cnt1 = C[jos] - C[sus - 1], cnt0 = h - cnt1;
- if (cnt1 > cnt0)
- {
- int z = cnt1 * ma1 + cnt0 * (w - ma1);
- Update(z, cnt_ma1);
- }
- else if (cnt0 > cnt1)
- {
- int z = cnt0 * ma0 + cnt1 * (w - ma0);
- Update(z, cnt_ma0);
- }
- else // cnt1 == cnt0
- {
- int z = cnt1 * w;
- Update(z, m - w + 1);
- }
- }
- }
- void Update(int z, int cnt) // Am gasit cnt dreptunghiuri noi cu z 0-uri. Updatez raspunsul.
- {
- if (z > zmax)
- {
- zmax = z;
- nsol = cnt;
- }
- else if (z == zmax)
- nsol += cnt;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement