# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
204413 |
2020-02-25T17:03:03 Z |
ADJA |
Rectangles (IOI19_rect) |
C++14 |
|
5000 ms |
122956 KB |
#include "rect.h"
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
using namespace std;
const int MAXN = 2500;
int n, m;
int a[MAXN][MAXN];
int ok[MAXN][MAXN];
int mxc[MAXN];
int one[MAXN][MAXN], zero[MAXN][MAXN];
long long solveSix() {
for (int j = m - 1; j >= 0; j--) {
for (int i = 0; i < n; i++) {
if (a[i][j] == 0) {
one[i][j] = 0;
zero[i][j] = 1 + zero[i][j + 1];
} else {
zero[i][j] = 0;
one[i][j] = 1 + one[i][j + 1];
}
}
}
long long ans = 0;
for (int j = 0; j + 1 < m; j++) {
int prevOne = -1, mnZero = 123123, mxZero = -1;
for (int i = 0; i < n; i++) {
if (a[i][j] == 1 && one[i][j + 1] == 0) {
mxZero = max(mxZero, zero[i][j + 1]);
mnZero = min(mnZero, zero[i][j + 1]);
} else {
int curOne = one[i][j + 1];
if (prevOne != -1 && mxZero != -1 && mxZero == mnZero) {
int zeroLen = mnZero;
if (j + zeroLen + 1 < m && prevOne >= zeroLen && curOne >= zeroLen) {
ans++;
// cerr << i << " " << j << endl;
}
}
prevOne = curOne;
mnZero = 123123, mxZero = -1;
}
}
}
return ans;
}
long long count_rectangles(std::vector<std::vector<int> > A) {
n = sz(A); m = sz(A[0]);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = A[i][j];
}
}
bool isSix = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] > 1) {
isSix = false;
}
}
}
if (isSix) {
return solveSix();
}
long long ans = 0;
vector<int> cols;
for (int i = 0; i < m; i++) {
cols.push_back(i);
}
random_shuffle(all(cols));
for (int coli = 0; coli < min(200, m); coli++) {
int col = cols[coli];
if (col == m - 1) {
continue;
}
for (int i = 0; i < n; i++) {
for (int j = col; j < m; j++) {
ok[i][j] = 0;
}
}
for (int i = 0; i < n; i++) {
int mx = -1;
for (int j = col + 1; j < m; j++) {
if (a[i][col] > mx && a[i][j] > mx) {
ok[i][j] = 1;
}
if (a[i][j] > mx) {
mx = a[i][j];
}
}
}
for (int i = 0; i < n; i++) {
for (int j = col + 1; j < m; j++) {
if (ok[i][j]) {
ok[i][j] = 1 + ok[i - 1][j];
}
}
}
for (int row = 0; row + 1 < n; row++) {
for (int j = col + 1; j < m; j++) {
mxc[j] = -1;
}
for (int row2 = row + 1; row2 < n; row2++) {
bool good = true;
for (int col2 = col + 1; col2 + 1 < m; col2++) {
if (!(a[row][col2] > mxc[col2] && a[row2][col2] > mxc[col2])) {
good = false;
}
if (good && row2 - 1 > row && ok[row2 - 1][col2 + 1] >= row2 - row - 1) {
ans++;
}
if (a[row2][col2] > mxc[col2]) {
mxc[col2] = a[row2][col2];
}
}
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
508 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
632 KB |
Output is correct |
5 |
Correct |
6 ms |
632 KB |
Output is correct |
6 |
Correct |
6 ms |
664 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
508 KB |
Output is correct |
9 |
Correct |
6 ms |
632 KB |
Output is correct |
10 |
Correct |
6 ms |
504 KB |
Output is correct |
11 |
Correct |
6 ms |
508 KB |
Output is correct |
12 |
Correct |
6 ms |
508 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
760 KB |
Output is correct |
20 |
Correct |
5 ms |
760 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
508 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
632 KB |
Output is correct |
5 |
Correct |
6 ms |
632 KB |
Output is correct |
6 |
Correct |
6 ms |
664 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
508 KB |
Output is correct |
9 |
Correct |
6 ms |
632 KB |
Output is correct |
10 |
Correct |
6 ms |
504 KB |
Output is correct |
11 |
Correct |
6 ms |
508 KB |
Output is correct |
12 |
Correct |
6 ms |
508 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
28 ms |
1144 KB |
Output is correct |
18 |
Correct |
28 ms |
1144 KB |
Output is correct |
19 |
Correct |
28 ms |
1016 KB |
Output is correct |
20 |
Correct |
34 ms |
1120 KB |
Output is correct |
21 |
Correct |
42 ms |
1016 KB |
Output is correct |
22 |
Correct |
41 ms |
1016 KB |
Output is correct |
23 |
Correct |
38 ms |
1016 KB |
Output is correct |
24 |
Correct |
15 ms |
1016 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
760 KB |
Output is correct |
28 |
Correct |
5 ms |
760 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
508 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
632 KB |
Output is correct |
5 |
Correct |
6 ms |
632 KB |
Output is correct |
6 |
Correct |
6 ms |
664 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
508 KB |
Output is correct |
9 |
Correct |
6 ms |
632 KB |
Output is correct |
10 |
Correct |
6 ms |
504 KB |
Output is correct |
11 |
Correct |
6 ms |
508 KB |
Output is correct |
12 |
Correct |
6 ms |
508 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
28 ms |
1144 KB |
Output is correct |
18 |
Correct |
28 ms |
1144 KB |
Output is correct |
19 |
Correct |
28 ms |
1016 KB |
Output is correct |
20 |
Correct |
34 ms |
1120 KB |
Output is correct |
21 |
Correct |
42 ms |
1016 KB |
Output is correct |
22 |
Correct |
41 ms |
1016 KB |
Output is correct |
23 |
Correct |
38 ms |
1016 KB |
Output is correct |
24 |
Correct |
15 ms |
1016 KB |
Output is correct |
25 |
Correct |
847 ms |
2624 KB |
Output is correct |
26 |
Correct |
847 ms |
2552 KB |
Output is correct |
27 |
Correct |
821 ms |
2624 KB |
Output is correct |
28 |
Correct |
920 ms |
2680 KB |
Output is correct |
29 |
Correct |
1123 ms |
2680 KB |
Output is correct |
30 |
Correct |
1147 ms |
2680 KB |
Output is correct |
31 |
Correct |
1053 ms |
2680 KB |
Output is correct |
32 |
Correct |
984 ms |
2680 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
760 KB |
Output is correct |
36 |
Correct |
5 ms |
760 KB |
Output is correct |
37 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
508 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
632 KB |
Output is correct |
5 |
Correct |
6 ms |
632 KB |
Output is correct |
6 |
Correct |
6 ms |
664 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
508 KB |
Output is correct |
9 |
Correct |
6 ms |
632 KB |
Output is correct |
10 |
Correct |
6 ms |
504 KB |
Output is correct |
11 |
Correct |
6 ms |
508 KB |
Output is correct |
12 |
Correct |
6 ms |
508 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
28 ms |
1144 KB |
Output is correct |
18 |
Correct |
28 ms |
1144 KB |
Output is correct |
19 |
Correct |
28 ms |
1016 KB |
Output is correct |
20 |
Correct |
34 ms |
1120 KB |
Output is correct |
21 |
Correct |
42 ms |
1016 KB |
Output is correct |
22 |
Correct |
41 ms |
1016 KB |
Output is correct |
23 |
Correct |
38 ms |
1016 KB |
Output is correct |
24 |
Correct |
15 ms |
1016 KB |
Output is correct |
25 |
Correct |
847 ms |
2624 KB |
Output is correct |
26 |
Correct |
847 ms |
2552 KB |
Output is correct |
27 |
Correct |
821 ms |
2624 KB |
Output is correct |
28 |
Correct |
920 ms |
2680 KB |
Output is correct |
29 |
Correct |
1123 ms |
2680 KB |
Output is correct |
30 |
Correct |
1147 ms |
2680 KB |
Output is correct |
31 |
Correct |
1053 ms |
2680 KB |
Output is correct |
32 |
Correct |
984 ms |
2680 KB |
Output is correct |
33 |
Execution timed out |
5073 ms |
13708 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
291 ms |
59000 KB |
Output is correct |
3 |
Correct |
633 ms |
122360 KB |
Output is correct |
4 |
Correct |
638 ms |
122744 KB |
Output is correct |
5 |
Correct |
637 ms |
122800 KB |
Output is correct |
6 |
Correct |
269 ms |
60920 KB |
Output is correct |
7 |
Correct |
553 ms |
119800 KB |
Output is correct |
8 |
Correct |
583 ms |
122956 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
760 KB |
Output is correct |
12 |
Correct |
5 ms |
760 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
508 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
632 KB |
Output is correct |
5 |
Correct |
6 ms |
632 KB |
Output is correct |
6 |
Correct |
6 ms |
664 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
508 KB |
Output is correct |
9 |
Correct |
6 ms |
632 KB |
Output is correct |
10 |
Correct |
6 ms |
504 KB |
Output is correct |
11 |
Correct |
6 ms |
508 KB |
Output is correct |
12 |
Correct |
6 ms |
508 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
28 ms |
1144 KB |
Output is correct |
18 |
Correct |
28 ms |
1144 KB |
Output is correct |
19 |
Correct |
28 ms |
1016 KB |
Output is correct |
20 |
Correct |
34 ms |
1120 KB |
Output is correct |
21 |
Correct |
42 ms |
1016 KB |
Output is correct |
22 |
Correct |
41 ms |
1016 KB |
Output is correct |
23 |
Correct |
38 ms |
1016 KB |
Output is correct |
24 |
Correct |
15 ms |
1016 KB |
Output is correct |
25 |
Correct |
847 ms |
2624 KB |
Output is correct |
26 |
Correct |
847 ms |
2552 KB |
Output is correct |
27 |
Correct |
821 ms |
2624 KB |
Output is correct |
28 |
Correct |
920 ms |
2680 KB |
Output is correct |
29 |
Correct |
1123 ms |
2680 KB |
Output is correct |
30 |
Correct |
1147 ms |
2680 KB |
Output is correct |
31 |
Correct |
1053 ms |
2680 KB |
Output is correct |
32 |
Correct |
984 ms |
2680 KB |
Output is correct |
33 |
Execution timed out |
5073 ms |
13708 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |