# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
551493 | PiejanVDC | Rectangles (IOI19_rect) | C++17 | 5081 ms | 74100 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "rect.h"
using namespace std;
long long count_rectangles(vector<vector<int>> v) {
long long ans = 0;
const int n = (int)v.size();
const int m = (int)v[0].size();
if(n < 3 || m < 3)
return 0LL;
bool ok = 1;
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < m ; j++)
if(v[i][j] > 1)
ok = 0;
if(ok) {
vector<vector<int>>sum(n+1, vector<int>(m+1,0));
for(int i = 1 ; i <= n ; i++) {
for(int j = 1 ; j <= m ; j++) {
sum[i][j] = sum[i][j-1] + sum[i-1][j] - sum[i-1][j-1] + v[i-1][j-1];
}
}
auto get = [&] (int x1, int y1, int x2, int y2) -> int {
return sum[x1][y1] - sum[x2-1][y1] - sum[x1][y2-1] + sum[x2-1][y2-1];
};
for(int i = 1 ; i < n-1 ; i++) {
for(int j = 1 ; j < m-1 ; j++) {
if(v[i][j] == 0 && v[i][j+1] == 1) {
int l = 1, r = i, f, s;
while(l <= r) {
int mid = (l+r)/2;
if(get(i+1, j+1, mid+1, j+1) == 0)
f = mid, r = mid-1;
else
l = mid+1;
}
l = 1, r = j;
while(l <= r) {
int mid = (l+r)/2;
if(get(i+1, j+1, i+1, mid+1) == 0)
s = mid, r = mid-1;
else
l = mid+1;
}
if(get(i+1, j+1, f+1, s+1) != 0)
continue;
if(get(i+1, j+2, f+1, j+2) == i - f + 1 && get(i+2, j+1, i+2, s+1) == j - s + 1 && get(i+1, s, f+1, s) == i - f + 1 && get(f, j+1, f, s+1) == j - s + 1) {
ans++;
}
}
}
}
return ans;
}
for(int i = 1 ; i < n-1 ; i++) {
for(int j = 1 ; j < m-1 ; j++) {
for(int ii = i ; ii < n-1 ; ii++) {
for(int jj = j ; jj < m-1 ; jj++) {
ok = 1;
for(int k = i ; k <= ii && ok ; k++) {
for(int l = j ; l <= jj ; l++) {
if(v[k][l] >= v[i-1][l] || v[k][l] >= v[ii+1][l] || v[k][l] >= v[k][j-1] || v[k][l] >= v[k][jj+1]) {
ok = 0;
break;
}
}
}
ans += ok;
}
}
}
}
return ans;
}
/*
6 5
4 8 7 5 6
7 4 10 3 5
9 7 20 14 2
9 14 7 3 6
5 7 5 2 7
4 5 13 5 6
#include <cstdio>
#include <unistd.h>
#include <cassert>
#include <string>
using namespace std;
class InputReader {
private:
static const int SIZE = 4096;
int inputFileDescriptor;
char buf[SIZE];
int curChar;
int numChars;
public:
inline InputReader(int _inputFileDescriptor):
inputFileDescriptor(_inputFileDescriptor),
curChar(0),
numChars(0) {
}
inline void close() {
::close(inputFileDescriptor);
}
inline char read() {
assert(numChars != -1);
if (curChar >= numChars) {
curChar = 0;
numChars = ::read(inputFileDescriptor, buf, SIZE);
if (numChars == -1)
return -1;
}
return buf[curChar++];
}
inline int readInt() {
int c = eatWhite();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
assert(c >= '0' && c <= '9');
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
inline string readString() {
char c = eatWhite();
string res;
do {
res += c;
c = read();
} while (!isSpaceChar(c));
return res;
}
inline string readLine() {
string res;
while (true) {
char c = read();
if (c == '\n' || c == '\r' || c == -1)
break;
res += c;
}
return res;
}
inline char eatWhite() {
char c = read();
while (isSpaceChar(c))
c = read();
return c;
}
static inline bool isSpaceChar(char c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
};
int main() {
InputReader inputReader(STDIN_FILENO);
int n, m;
cin>>n>>m;
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin>>a[i][j];
}
}
long long result = count_rectangles(a);
printf("%lld\n", result);
return 0;
}
*/
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |