This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int rectangle(int R, int C, int H, int W, int Q[3001][3001]) {
int ans = 0;
set<int> st;
for(int i = 0; i < W; i++)
for(int j = 0; j < H; j++) st.insert(Q[j][i]);
auto it = st.begin();
advance(it, (W*H)/2);
ans = *it;
bool back = 0;
for(int k = 0; k <= R-H; k++){
if(!back){
for(int i = 1; i <= C-W; i++){
// elimino la parte precedente
for(int j = k; j < H+k; j++){
st.erase(Q[j][i-1]);
st.insert(Q[j][i+W-1]);
}
auto it = st.begin();
advance(it, (W*H)/2);
ans = min(ans, *it);
}
}else{
for(int i = C-W-1; i >= 0; i--){
// elimino la parte precedente
for(int j = k; j < H+k; j++){
st.erase(Q[j][i+W-1]);
st.insert(Q[j][i]);
}
auto it = st.begin();
advance(it, (W*H)/2);
ans = min(ans, *it);
}
}
if(!back){
if(k+H < R){
for(int i = C-W; i < C; i++){
st.erase(Q[k][i]);
st.insert(Q[k+H][i]);
}
}
}else{
if(k+H < R){
for(int i = 0; i < W; i++){
st.erase(Q[k][i]);
st.insert(Q[k+H][i]);
}
}
}
auto it = st.begin();
advance(it, (W*H)/2);
ans = min(ans, *it);
back^=1;
}
return ans;
}
# | 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... |