This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
using namespace std;
#include <bits/stdc++.h>
#include "quality.h"
#pragma GCC optimize ("Ofast")
#pragma GCC target("avx2")
#define FR(i, N) for (int i = 0; i < int(N); i++)
#define all(x) begin(x), end(x)
int pref[3001][3001];
pair<int, int> coords[3001*3001];
int rectangle(int R, int C, int H, int W, int Q[3001][3001]) {
int low = 0;
int high = R*C-1;
FR(i, R){
FR(j, C){
coords[Q[i][j]-1] = {i, j};
}
}
int base = H*W/2;
while (low < high) {
int mid = (low + high)/2;
memset(pref, 0, sizeof(pref));
FR(i, mid+1) {
pref[coords[i].first][coords[i].second]++;
}
FR(i, R) {
FR(j, C) {
pref[i][j] += (i > 0 ? pref[i-1][j] : 0) + (j > 0 ? pref[i][j-1] : 0) - (i > 0 && j > 0 ? pref[i-1][j-1] : 0);
if (pref[i][j] - (i >= H ? pref[i-H][j] : 0) - (j >= W ? pref[i][j-W] : 0) + (j >= W && i >= H ? pref[i-H][j-W] : 0) > base) {
high = mid;
}
}
}
if (high != mid) {
low = mid+1;
}
}
return high+1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |