답안 #295399

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
295399 2020-09-09T16:22:36 Z SamAnd Rectangles (IOI19_rect) C++17
72 / 100
5000 ms 255048 KB
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
const int N = 2505;
const int xx[4] = {1, 0, -1, 0};
const int yy[4] = {0, 1, 0, -1};

int n, m;
int a[N][N];

bool c[N][N];
int q;
int minx, maxx, miny, maxy;

void dfs(int x, int y)
{
    c[x][y] = true;
    ++q;
    minx = min(minx, x);
    maxx = max(maxx, x);
    miny = min(miny, y);
    maxy = max(maxy, y);
    for (int i = 0; i < 4; ++i)
    {
        int hx = x + xx[i];
        int hy = y + yy[i];
        if (hx >= 1 && hx <= n && hy >= 1 && hy <= m && !c[hx][hy] && a[hx][hy] == 0)
        {
            dfs(hx, hy);
        }
    }
}

ll solv6()
{
    ll ans = 0;
    for (int x = 1; x <= n; ++x)
    {
        for (int y = 1; y <= m; ++y)
        {
            if (a[x][y] == 0)
            {
                if (!c[x][y])
                {
                    q = 0;
                    minx = maxx = x;
                    miny = maxy = y;
                    dfs(x, y);
                    if (minx == 1 || maxx == n)
                        continue;
                    if (miny == 1 || maxy == m)
                        continue;
                    if ((maxx - minx + 1) * (maxy - miny + 1) == q)
                    {
                        ++ans;
                    }
                }
            }
        }
    }
    return ans;
}

int l[N][N], r[N][N];

int maxu[N];
int ul[N], ur[N];

long long count_rectangles(std::vector<std::vector<int> > A)
{
    n = sz(A);
    m = sz(A[0]);
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            a[i][j] = A[i - 1][j - 1];
        }
    }

    bool z = true;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            if (a[i][j] > 1)
            {
                z = false;
            }
        }
    }

    if (z)
    {
        return solv6();
    }

    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            l[i][j] = j;
            while (l[i][j] > 1 && a[i][j] > a[i][l[i][j] - 1])
                --l[i][j];
            r[i][j] = j;
            while (r[i][j] < m && a[i][j] > a[i][r[i][j] + 1])
                ++r[i][j];
        }
    }

    ll ans = 0;
    for (int x1 = 2; x1 < n; ++x1)
    {
        for (int x2 = x1; x2 < n; ++x2)
        {
            for (int y = 1; y <= m; ++y)
            {
                if (x2 == x1)
                {
                    maxu[y] = a[x2][y];
                    ul[y] = l[x2][y];
                    ur[y] = r[x2][y];
                }
                else
                {
                    maxu[y] = max(maxu[y], a[x2][y]);
                    ul[y] = max(ul[y], l[x2][y]);
                    ur[y] = min(ur[y], r[x2][y]);
                }
            }
            for (int y1_ = 2; y1_ < m; ++y1_)
            {
                for (int y2 = y1_; y2 < m; ++y2)
                {
                    if (maxu[y2] >= a[x1 - 1][y2])
                        break;
                    if (maxu[y2] >= a[x2 + 1][y2])
                        break;
                    if (ur[y1_ - 1] >= y2 && ul[y2 + 1] <= y1_)
                        ++ans;
                }
            }
        }
    }
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 768 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 0 ms 512 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 768 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 0 ms 360 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 0 ms 512 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 768 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 0 ms 512 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 768 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 0 ms 360 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 3 ms 1536 KB Output is correct
18 Correct 3 ms 1408 KB Output is correct
19 Correct 3 ms 1408 KB Output is correct
20 Correct 2 ms 1408 KB Output is correct
21 Correct 3 ms 1408 KB Output is correct
22 Correct 3 ms 1440 KB Output is correct
23 Correct 3 ms 1408 KB Output is correct
24 Correct 2 ms 1408 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 0 ms 512 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 768 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 0 ms 512 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 768 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 0 ms 360 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 3 ms 1536 KB Output is correct
18 Correct 3 ms 1408 KB Output is correct
19 Correct 3 ms 1408 KB Output is correct
20 Correct 2 ms 1408 KB Output is correct
21 Correct 3 ms 1408 KB Output is correct
22 Correct 3 ms 1440 KB Output is correct
23 Correct 3 ms 1408 KB Output is correct
24 Correct 2 ms 1408 KB Output is correct
25 Correct 35 ms 3584 KB Output is correct
26 Correct 32 ms 3584 KB Output is correct
27 Correct 33 ms 3712 KB Output is correct
28 Correct 19 ms 3584 KB Output is correct
29 Correct 22 ms 3584 KB Output is correct
30 Correct 24 ms 3584 KB Output is correct
31 Correct 24 ms 3584 KB Output is correct
32 Correct 21 ms 3456 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 1 ms 512 KB Output is correct
36 Correct 0 ms 512 KB Output is correct
37 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 768 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 0 ms 512 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 768 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 0 ms 360 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 3 ms 1536 KB Output is correct
18 Correct 3 ms 1408 KB Output is correct
19 Correct 3 ms 1408 KB Output is correct
20 Correct 2 ms 1408 KB Output is correct
21 Correct 3 ms 1408 KB Output is correct
22 Correct 3 ms 1440 KB Output is correct
23 Correct 3 ms 1408 KB Output is correct
24 Correct 2 ms 1408 KB Output is correct
25 Correct 35 ms 3584 KB Output is correct
26 Correct 32 ms 3584 KB Output is correct
27 Correct 33 ms 3712 KB Output is correct
28 Correct 19 ms 3584 KB Output is correct
29 Correct 22 ms 3584 KB Output is correct
30 Correct 24 ms 3584 KB Output is correct
31 Correct 24 ms 3584 KB Output is correct
32 Correct 21 ms 3456 KB Output is correct
33 Correct 1040 ms 18552 KB Output is correct
34 Correct 1037 ms 18556 KB Output is correct
35 Correct 1111 ms 18436 KB Output is correct
36 Correct 1118 ms 18548 KB Output is correct
37 Correct 1309 ms 18404 KB Output is correct
38 Correct 1330 ms 21760 KB Output is correct
39 Correct 1412 ms 22008 KB Output is correct
40 Correct 1183 ms 20764 KB Output is correct
41 Correct 24 ms 11648 KB Output is correct
42 Correct 761 ms 19448 KB Output is correct
43 Correct 826 ms 20348 KB Output is correct
44 Correct 872 ms 22160 KB Output is correct
45 Correct 405 ms 15488 KB Output is correct
46 Correct 212 ms 11264 KB Output is correct
47 Correct 815 ms 21112 KB Output is correct
48 Correct 806 ms 22180 KB Output is correct
49 Correct 0 ms 384 KB Output is correct
50 Correct 0 ms 384 KB Output is correct
51 Correct 1 ms 512 KB Output is correct
52 Correct 0 ms 512 KB Output is correct
53 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 512 KB Output is correct
2 Correct 11 ms 512 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 119 ms 38008 KB Output is correct
3 Correct 259 ms 79736 KB Output is correct
4 Correct 259 ms 80120 KB Output is correct
5 Correct 255 ms 80120 KB Output is correct
6 Correct 195 ms 95992 KB Output is correct
7 Correct 445 ms 220792 KB Output is correct
8 Correct 481 ms 255048 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 0 ms 512 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 768 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 0 ms 512 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 768 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 0 ms 360 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 3 ms 1536 KB Output is correct
18 Correct 3 ms 1408 KB Output is correct
19 Correct 3 ms 1408 KB Output is correct
20 Correct 2 ms 1408 KB Output is correct
21 Correct 3 ms 1408 KB Output is correct
22 Correct 3 ms 1440 KB Output is correct
23 Correct 3 ms 1408 KB Output is correct
24 Correct 2 ms 1408 KB Output is correct
25 Correct 35 ms 3584 KB Output is correct
26 Correct 32 ms 3584 KB Output is correct
27 Correct 33 ms 3712 KB Output is correct
28 Correct 19 ms 3584 KB Output is correct
29 Correct 22 ms 3584 KB Output is correct
30 Correct 24 ms 3584 KB Output is correct
31 Correct 24 ms 3584 KB Output is correct
32 Correct 21 ms 3456 KB Output is correct
33 Correct 1040 ms 18552 KB Output is correct
34 Correct 1037 ms 18556 KB Output is correct
35 Correct 1111 ms 18436 KB Output is correct
36 Correct 1118 ms 18548 KB Output is correct
37 Correct 1309 ms 18404 KB Output is correct
38 Correct 1330 ms 21760 KB Output is correct
39 Correct 1412 ms 22008 KB Output is correct
40 Correct 1183 ms 20764 KB Output is correct
41 Correct 24 ms 11648 KB Output is correct
42 Correct 761 ms 19448 KB Output is correct
43 Correct 826 ms 20348 KB Output is correct
44 Correct 872 ms 22160 KB Output is correct
45 Correct 405 ms 15488 KB Output is correct
46 Correct 212 ms 11264 KB Output is correct
47 Correct 815 ms 21112 KB Output is correct
48 Correct 806 ms 22180 KB Output is correct
49 Correct 17 ms 512 KB Output is correct
50 Correct 11 ms 512 KB Output is correct
51 Correct 1 ms 640 KB Output is correct
52 Correct 0 ms 384 KB Output is correct
53 Correct 1 ms 512 KB Output is correct
54 Correct 1 ms 512 KB Output is correct
55 Correct 1 ms 512 KB Output is correct
56 Correct 1 ms 512 KB Output is correct
57 Correct 1 ms 512 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 0 ms 384 KB Output is correct
61 Correct 119 ms 38008 KB Output is correct
62 Correct 259 ms 79736 KB Output is correct
63 Correct 259 ms 80120 KB Output is correct
64 Correct 255 ms 80120 KB Output is correct
65 Correct 195 ms 95992 KB Output is correct
66 Correct 445 ms 220792 KB Output is correct
67 Correct 481 ms 255048 KB Output is correct
68 Execution timed out 5050 ms 107516 KB Time limit exceeded
69 Halted 0 ms 0 KB -