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;
void chuck(set<int>::iterator& mid, set<int>& s, int in, set<int>::iterator& out){
if (*mid == *out){
if (in > *mid){
s.insert(in);
++mid;
s.erase(out);
return;
}
s.insert(in);
--mid;
s.erase(out);
return;
}
if (in < *mid && *mid < *out){
s.insert(in);
--mid;
s.erase(out);
return;
}
if (*out < *mid && *mid < in){
s.insert(in);
++mid;
s.erase(out);
return;
}
s.insert(in);
s.erase(out);
return;
}
int rectangle(int R, int C, int H, int W, int Q[3001][3001]) {
set<int> s;
for (int i = 0; i < H; ++i){
for (int j = 0; j < W; ++j){
s.insert(Q[i][j]);
}
}
auto mid = s.begin();
for (int i = 0; i < (s.size() - 1) / 2; ++i){
mid++;
}
int best = *mid;
for (int i = 0; i < C - W + 1; ++i){
for (int j = 0; j < R - H + 1; ++j){
if (i % 2 == 0){
if (j == R - H){
for (int k = 0; k < H; ++k){
auto out = s.find(Q[j + k][i]);
chuck(mid, s, Q[j + k][i + W], out);
}
}
else{
for (int k = 0; k < W; ++k){
auto out = s.find(Q[j][i + k]);
chuck(mid, s, Q[j + H][i + k], out);
}
}
}
else{
int p = R - H - j;
if (p == 0){
for (int k = 0; k < H; ++k){
auto out = s.find(Q[p + k][i]);
chuck(mid, s, Q[p + k][i + W], out);
}
}
else{
for (int k = 0; k < W; ++k){
auto out = s.find(Q[p + H - 1][i + k]);
chuck(mid, s, Q[p - 1][i + k], out);
}
}
}
best = min(best, *mid);
}
}
return best;
}
Compilation message (stderr)
quality.cpp: In function 'int rectangle(int, int, int, int, int (*)[3001])':
quality.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int i = 0; i < (s.size() - 1) / 2; ++i){
| ~~^~~~~~~~~~~~~~~~~~~~
# | 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... |