답안 #841756

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
841756 2023-09-02T03:16:35 Z olnyfcxwps 축구 경기장 (IOI23_soccer) C++17
52 / 100
612 ms 556320 KB
#include <iostream>
#include <vector>
using namespace std;

const int N = 30;
int n;
int tree[2000][2000];
bool seen[2000][2000];
int prefix[2000][2000];
int dp1[N][N][N];
int dp2[N][N][N];
int max_area;
vector<int> startP;
vector<int> endP;

bool are_empty(int row, int col1, int col2) {
    if (col1 == 0) {
        return prefix[row][col2] == 0;
    }
    return prefix[row][col2] == prefix[row][col1 - 1];
}

int solve_1() {
    int x = 0;
    int y = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (tree[i][j] == 1) {
                x = i;
                y = j;
            }
        }
    }
    x += 1;
    y += 1;
    int m = x * y;
    int t = x * (n - y + 1);
    if (t < m) {
        m = t;
    }
    t = (n - x + 1) * y;
    if (t < m) {
        m = t;
    }
    t = (n - x + 1) * (n - y + 1);
    if (t < m) {
        m = t;
    }
    return n * n - m;
}

void dfs(int r, int c) {
    seen[r][c] = true;
    if (r - 1 >= 0 && tree[r - 1][c] == 0 && !seen[r - 1][c]) {
        dfs(r - 1, c);
    }
    if (r + 1 < n && tree[r + 1][c] == 0 && !seen[r + 1][c]) {
        dfs(r + 1, c);
    }
    if (c - 1 >= 0 && tree[r][c - 1] == 0 && !seen[r][c - 1]) {
        dfs(r, c - 1);
    }
    if (c + 1 < n && tree[r][c + 1] == 0 && !seen[r][c + 1]) {
        dfs(r, c + 1);
    }
}

bool check() {
    int c = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            seen[i][j] = false;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (tree[i][j] == 0) {
                if (!seen[i][j]) {
                    dfs(i, j);
                    c += 1;
                }
            }
        }
    }
    if (c != 1) {
        return false;
    }

    vector<int> s;
    vector<int> t;
    int longest = 0;
    int where = 0;
    for (int i = 0; i < n; i++) {
        bool seen = false;
        for (int j = 0; j < n;) {
            if (tree[i][j] == 0) {
                if (seen) {
                    return false;
                }
                seen = true;
                int k = j + 1;
                while (k < n && tree[i][k] == 0) {
                    k++;
                }
                s.push_back(j);
                t.push_back(k - 1);
                if (longest < k - j) {
                    longest = k - j;
                    where = s.size() - 1;
                }
                j = k;
            } else {
                j++;
            }
        }
    }

    /*for (int i = 0; i < s.size(); i++) {
        cout << s[i] << " " << t[i] << "\n";
    }
    cout << where << "\n";*/

    for (int i = where - 1; i >= 0; i--) {
        if (s[i] < s[i + 1] || t[i] > t[i + 1]) {
            return false;
        }
    }

    for (int i = where; i + 1 < s.size(); i++) {
        // cout << i << "\n";
        if (s[i + 1] < s[i] || t[i + 1] > t[i]) {
            return false;
        }
    }
    // cout << "here\n";

    for (int i = 0; i < s.size(); i++) {
        for (int j = i + 1; j < s.size(); j++) {
            if (!(s[i] <= s[j] && t[j] <= t[i]
                || s[j] <= s[i] && t[i] <= t[j]
            )) {
                return false;
            }
        }
    }

    return true;
}

bool is_possible() {
    bool start_shrink = false;
    for (int i = 1; i < startP.size(); i++) {
        int l1 = startP[i - 1];
        int r1 = endP[i - 1];
        int l2 = startP[i];
        int r2 = endP[i];
        // check if include
        if (!(l1 <= l2 && r2 <= r1 || l2 <= l1 && r1 <= r2)) {
            return false;
        }
        // check if shrink
        if (r2 - l2 < r1 - l1) {
            start_shrink = true;
        } else if (r2 - l2 > r1 - l1) {
            if (start_shrink) {
                return false;
            }
        }
    }

    for (int i = 0; i < startP.size(); i++) {
        for (int j = i; j < startP.size(); j++) {
            int l1 = startP[i];
            int r1 = endP[i];
            int l2 = startP[j];
            int r2 = endP[j];
            // check if include
            if (!(l1 <= l2 && r2 <= r1 || l2 <= l1 && r1 <= r2)) {
                return false;
            }
        }
    }

    return true;
}

void brute_force(int row, int a) {
    if (row == n) {
        return;
    }
    // skip row if possible
    if (startP.empty()) {
        brute_force(row + 1, a);
    }
    // brute force
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            if (!are_empty(row, i, j)) {
                break;
            }
            startP.push_back(i);
            endP.push_back(j);
            if (is_possible()) {
                if (a + j - i + 1 > max_area) {
                    max_area = a + j - i + 1;
                }
                brute_force(row + 1, a + j - i + 1);
            }
            startP.pop_back();
            endP.pop_back();
        }
    }
}

// int biggest_stadium(int N, int[][] F)
int biggest_stadium(int X, vector<vector<int>> F) {
    n = X;
    int total = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            tree[i][j] = F[i][j];
            total += tree[i][j];
            prefix[i][j] = tree[i][j];
            if (j - 1 >= 0) {
                prefix[i][j] += prefix[i][j - 1];
            }
        }
    }
    if (total == 1) {
        return solve_1();
    }
    if (total == 0) {
        return n * n;
    }
    /*if (n > 30) {
        return 123;
    }*/

    if (check()) {
        return n * n - total;
    }

    if (n <= 7) {
        brute_force(0, 0);
        return max_area;
    }

    return 0;
}

Compilation message

soccer.cpp: In function 'bool check()':
soccer.cpp:129:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  129 |     for (int i = where; i + 1 < s.size(); i++) {
      |                         ~~~~~~^~~~~~~~~~
soccer.cpp:137:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  137 |     for (int i = 0; i < s.size(); i++) {
      |                     ~~^~~~~~~~~~
soccer.cpp:138:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  138 |         for (int j = i + 1; j < s.size(); j++) {
      |                             ~~^~~~~~~~~~
soccer.cpp:139:32: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  139 |             if (!(s[i] <= s[j] && t[j] <= t[i]
soccer.cpp: In function 'bool is_possible()':
soccer.cpp:152:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  152 |     for (int i = 1; i < startP.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~
soccer.cpp:158:24: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  158 |         if (!(l1 <= l2 && r2 <= r1 || l2 <= l1 && r1 <= r2)) {
      |               ~~~~~~~~~^~~~~~~~~~~
soccer.cpp:171:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  171 |     for (int i = 0; i < startP.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~
soccer.cpp:172:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  172 |         for (int j = i; j < startP.size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~
soccer.cpp:178:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  178 |             if (!(l1 <= l2 && r2 <= r1 || l2 <= l1 && r1 <= r2)) {
      |                   ~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB ok
2 Correct 1 ms 4440 KB ok
3 Correct 1 ms 4440 KB ok
4 Correct 1 ms 4444 KB ok
5 Correct 1 ms 4440 KB ok
6 Correct 1 ms 4440 KB ok
7 Correct 2 ms 4440 KB ok
8 Correct 17 ms 12632 KB ok
9 Correct 244 ms 65104 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB ok
2 Correct 1 ms 4440 KB ok
3 Correct 1 ms 6488 KB ok
4 Correct 1 ms 6488 KB ok
5 Correct 1 ms 6488 KB ok
6 Correct 1 ms 6488 KB ok
7 Correct 1 ms 6488 KB ok
8 Correct 1 ms 6488 KB ok
9 Correct 1 ms 4440 KB ok
10 Correct 1 ms 6492 KB ok
11 Correct 1 ms 6488 KB ok
12 Correct 1 ms 6488 KB ok
13 Correct 1 ms 6492 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB ok
2 Correct 1 ms 4440 KB ok
3 Correct 1 ms 4440 KB ok
4 Correct 1 ms 6488 KB ok
5 Correct 1 ms 6488 KB ok
6 Correct 1 ms 6488 KB ok
7 Correct 1 ms 6488 KB ok
8 Correct 1 ms 6488 KB ok
9 Correct 1 ms 6488 KB ok
10 Correct 1 ms 4440 KB ok
11 Correct 1 ms 6492 KB ok
12 Correct 1 ms 6488 KB ok
13 Correct 1 ms 6488 KB ok
14 Correct 1 ms 6492 KB ok
15 Correct 189 ms 6488 KB ok
16 Correct 26 ms 6488 KB ok
17 Correct 1 ms 6488 KB ok
18 Correct 1 ms 6488 KB ok
19 Correct 1 ms 6488 KB ok
20 Correct 1 ms 6488 KB ok
21 Correct 1 ms 6488 KB ok
22 Correct 1 ms 6492 KB ok
23 Correct 1 ms 6488 KB ok
24 Correct 1 ms 6488 KB ok
25 Correct 1 ms 6488 KB ok
26 Correct 6 ms 6492 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB ok
2 Correct 1 ms 4440 KB ok
3 Correct 1 ms 4440 KB ok
4 Correct 1 ms 4440 KB ok
5 Correct 1 ms 4444 KB ok
6 Correct 1 ms 6488 KB ok
7 Correct 1 ms 6488 KB ok
8 Correct 1 ms 6488 KB ok
9 Correct 1 ms 6488 KB ok
10 Correct 1 ms 6488 KB ok
11 Correct 1 ms 6488 KB ok
12 Correct 1 ms 4440 KB ok
13 Correct 1 ms 6492 KB ok
14 Correct 1 ms 6488 KB ok
15 Correct 1 ms 6488 KB ok
16 Correct 1 ms 6492 KB ok
17 Correct 189 ms 6488 KB ok
18 Correct 26 ms 6488 KB ok
19 Correct 1 ms 6488 KB ok
20 Correct 1 ms 6488 KB ok
21 Correct 1 ms 6488 KB ok
22 Correct 1 ms 6488 KB ok
23 Correct 1 ms 6488 KB ok
24 Correct 1 ms 6492 KB ok
25 Correct 1 ms 6488 KB ok
26 Correct 1 ms 6488 KB ok
27 Correct 1 ms 6488 KB ok
28 Correct 6 ms 6492 KB ok
29 Correct 2 ms 6488 KB ok
30 Partially correct 1 ms 6488 KB partial
31 Partially correct 1 ms 6492 KB partial
32 Partially correct 1 ms 6488 KB partial
33 Partially correct 1 ms 6488 KB partial
34 Correct 1 ms 6488 KB ok
35 Correct 1 ms 6492 KB ok
36 Partially correct 1 ms 6488 KB partial
37 Partially correct 1 ms 6488 KB partial
38 Partially correct 1 ms 6492 KB partial
39 Partially correct 1 ms 6488 KB partial
40 Partially correct 1 ms 6488 KB partial
41 Partially correct 1 ms 6488 KB partial
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB ok
2 Correct 1 ms 4440 KB ok
3 Correct 1 ms 4440 KB ok
4 Correct 1 ms 4440 KB ok
5 Correct 1 ms 4444 KB ok
6 Correct 1 ms 6488 KB ok
7 Correct 1 ms 6488 KB ok
8 Correct 1 ms 6488 KB ok
9 Correct 1 ms 6488 KB ok
10 Correct 1 ms 6488 KB ok
11 Correct 1 ms 6488 KB ok
12 Correct 1 ms 4440 KB ok
13 Correct 1 ms 6492 KB ok
14 Correct 1 ms 6488 KB ok
15 Correct 1 ms 6488 KB ok
16 Correct 1 ms 6492 KB ok
17 Correct 189 ms 6488 KB ok
18 Correct 26 ms 6488 KB ok
19 Correct 1 ms 6488 KB ok
20 Correct 1 ms 6488 KB ok
21 Correct 1 ms 6488 KB ok
22 Correct 1 ms 6488 KB ok
23 Correct 1 ms 6488 KB ok
24 Correct 1 ms 6492 KB ok
25 Correct 1 ms 6488 KB ok
26 Correct 1 ms 6488 KB ok
27 Correct 1 ms 6488 KB ok
28 Correct 6 ms 6492 KB ok
29 Correct 2 ms 6488 KB ok
30 Partially correct 1 ms 6488 KB partial
31 Partially correct 1 ms 6492 KB partial
32 Partially correct 1 ms 6488 KB partial
33 Partially correct 1 ms 6488 KB partial
34 Correct 1 ms 6488 KB ok
35 Correct 1 ms 6492 KB ok
36 Partially correct 1 ms 6488 KB partial
37 Partially correct 1 ms 6488 KB partial
38 Partially correct 1 ms 6492 KB partial
39 Partially correct 1 ms 6488 KB partial
40 Partially correct 1 ms 6488 KB partial
41 Partially correct 1 ms 6488 KB partial
42 Partially correct 30 ms 32600 KB partial
43 Partially correct 28 ms 27736 KB partial
44 Partially correct 31 ms 36332 KB partial
45 Partially correct 31 ms 36944 KB partial
46 Partially correct 32 ms 35152 KB partial
47 Partially correct 38 ms 46928 KB partial
48 Correct 23 ms 24664 KB ok
49 Partially correct 25 ms 27224 KB partial
50 Partially correct 27 ms 32080 KB partial
51 Partially correct 22 ms 20568 KB partial
52 Partially correct 19 ms 18768 KB partial
53 Partially correct 18 ms 17496 KB partial
54 Partially correct 18 ms 19032 KB partial
55 Partially correct 23 ms 20312 KB partial
56 Partially correct 27 ms 29336 KB partial
57 Partially correct 35 ms 40016 KB partial
58 Partially correct 32 ms 38736 KB partial
59 Partially correct 33 ms 36440 KB partial
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB ok
2 Correct 1 ms 4440 KB ok
3 Correct 1 ms 4440 KB ok
4 Correct 1 ms 4440 KB ok
5 Correct 1 ms 4444 KB ok
6 Correct 1 ms 4440 KB ok
7 Correct 1 ms 4440 KB ok
8 Correct 2 ms 4440 KB ok
9 Correct 17 ms 12632 KB ok
10 Correct 244 ms 65104 KB ok
11 Correct 1 ms 6488 KB ok
12 Correct 1 ms 6488 KB ok
13 Correct 1 ms 6488 KB ok
14 Correct 1 ms 6488 KB ok
15 Correct 1 ms 6488 KB ok
16 Correct 1 ms 6488 KB ok
17 Correct 1 ms 4440 KB ok
18 Correct 1 ms 6492 KB ok
19 Correct 1 ms 6488 KB ok
20 Correct 1 ms 6488 KB ok
21 Correct 1 ms 6492 KB ok
22 Correct 189 ms 6488 KB ok
23 Correct 26 ms 6488 KB ok
24 Correct 1 ms 6488 KB ok
25 Correct 1 ms 6488 KB ok
26 Correct 1 ms 6488 KB ok
27 Correct 1 ms 6488 KB ok
28 Correct 1 ms 6488 KB ok
29 Correct 1 ms 6492 KB ok
30 Correct 1 ms 6488 KB ok
31 Correct 1 ms 6488 KB ok
32 Correct 1 ms 6488 KB ok
33 Correct 6 ms 6492 KB ok
34 Correct 2 ms 6488 KB ok
35 Partially correct 1 ms 6488 KB partial
36 Partially correct 1 ms 6492 KB partial
37 Partially correct 1 ms 6488 KB partial
38 Partially correct 1 ms 6488 KB partial
39 Correct 1 ms 6488 KB ok
40 Correct 1 ms 6492 KB ok
41 Partially correct 1 ms 6488 KB partial
42 Partially correct 1 ms 6488 KB partial
43 Partially correct 1 ms 6492 KB partial
44 Partially correct 1 ms 6488 KB partial
45 Partially correct 1 ms 6488 KB partial
46 Partially correct 1 ms 6488 KB partial
47 Partially correct 30 ms 32600 KB partial
48 Partially correct 28 ms 27736 KB partial
49 Partially correct 31 ms 36332 KB partial
50 Partially correct 31 ms 36944 KB partial
51 Partially correct 32 ms 35152 KB partial
52 Partially correct 38 ms 46928 KB partial
53 Correct 23 ms 24664 KB ok
54 Partially correct 25 ms 27224 KB partial
55 Partially correct 27 ms 32080 KB partial
56 Partially correct 22 ms 20568 KB partial
57 Partially correct 19 ms 18768 KB partial
58 Partially correct 18 ms 17496 KB partial
59 Partially correct 18 ms 19032 KB partial
60 Partially correct 23 ms 20312 KB partial
61 Partially correct 27 ms 29336 KB partial
62 Partially correct 35 ms 40016 KB partial
63 Partially correct 32 ms 38736 KB partial
64 Partially correct 33 ms 36440 KB partial
65 Partially correct 472 ms 324020 KB partial
66 Partially correct 284 ms 66896 KB partial
67 Partially correct 255 ms 66896 KB partial
68 Partially correct 464 ms 377628 KB partial
69 Partially correct 490 ms 385360 KB partial
70 Partially correct 475 ms 379016 KB partial
71 Partially correct 492 ms 403016 KB partial
72 Partially correct 612 ms 556320 KB partial
73 Correct 387 ms 195064 KB ok
74 Correct 433 ms 199480 KB ok
75 Partially correct 389 ms 199172 KB partial
76 Partially correct 430 ms 317320 KB partial
77 Partially correct 432 ms 316240 KB partial
78 Partially correct 369 ms 131920 KB partial
79 Partially correct 252 ms 67104 KB partial
80 Partially correct 259 ms 66996 KB partial
81 Partially correct 262 ms 67316 KB partial
82 Partially correct 272 ms 67664 KB partial
83 Partially correct 271 ms 67156 KB partial
84 Partially correct 271 ms 90448 KB partial
85 Partially correct 261 ms 81232 KB partial
86 Partially correct 277 ms 102480 KB partial
87 Partially correct 298 ms 119328 KB partial
88 Partially correct 393 ms 268368 KB partial
89 Partially correct 586 ms 518224 KB partial
90 Partially correct 476 ms 383148 KB partial
91 Partially correct 477 ms 287568 KB partial
92 Partially correct 260 ms 66896 KB partial
93 Partially correct 269 ms 67104 KB partial
94 Partially correct 254 ms 66896 KB partial
95 Partially correct 256 ms 66896 KB partial
96 Partially correct 253 ms 67152 KB partial
97 Partially correct 255 ms 67096 KB partial
98 Partially correct 255 ms 67152 KB partial
99 Partially correct 312 ms 83236 KB partial
100 Partially correct 559 ms 442192 KB partial
101 Partially correct 499 ms 273452 KB partial
102 Partially correct 507 ms 255056 KB partial
103 Partially correct 549 ms 415824 KB partial
104 Partially correct 502 ms 266524 KB partial
105 Partially correct 510 ms 267540 KB partial
106 Partially correct 529 ms 355652 KB partial
107 Partially correct 504 ms 322044 KB partial
108 Partially correct 314 ms 83992 KB partial
109 Partially correct 321 ms 97616 KB partial