답안 #1037997

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1037997 2024-07-29T11:58:16 Z fv3 축구 경기장 (IOI23_soccer) C++17
17.5 / 100
4500 ms 104272 KB
#include "soccer.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int nt = 1;
vector<vector<int>> st_h, st_v;

int getvrange(int l, int r, int k, int x, int y, int i)
{
    if (l > r) swap(l, r);
    if (r < x || l > y) return 0;
    if (x >= l && y <= r) return st_v[i][k];
    int c = (x + y) / 2;
    return getvrange(l, r, k*2, x, c, i) + getvrange(l, r, k*2|1, c+1, y, i);
}

int gethrange(int l, int r, int k, int x, int y, int i)
{
    if (l > r) swap(l, r);
    if (r < x || l > y) return 0;
    if (x >= l && y <= r) return st_h[i][k];
    int c = (x + y) / 2;
    return gethrange(l, r, k*2, x, c, i) + gethrange(l, r, k*2|1, c+1, y, i);
}

int biggest_stadium(int N, vector<vector<int>> F)
{
    int res = 0;

    while (nt < N)
        nt *= 2;

    st_v = st_h = vector<vector<int>>(N, vector<int>(2*nt));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            st_h[i][nt + j] = F[i][j];
            st_v[i][nt + j] = F[j][i];
        }

        for (int j = nt - 1; j >= 1; j--)
        {
            st_h[i][j] = st_h[i][j*2] + st_h[i][j*2|1];
            st_v[i][j] = st_v[i][j*2] + st_v[i][j*2|1];
        }
    }

    int top;
    int topl, topr;
    for (int i = 0; i < N; i++)
    {
        if (st_h[i][1] == N) continue;
        for (int j = 0; j < N; j++)
        {
            if (F[i][j]) continue;
            if (gethrange(j, j + (N - st_h[i][1] - 1), 1, 0, nt - 1, i))
                return -1;

            top = i;
            topl = j;
            topr = j + (N - st_h[i][1] - 1);

            break;
        }
        break;
    }

    int btm;
    int btml, btmr;
    for (int i = N-1; i >= 0; i--)
    {
        if (st_h[i][1] == N) continue;
        for (int j = 0; j < N; j++)
        {
            if (F[i][j]) continue;
            if (gethrange(j, j + (N - st_h[i][1] - 1), 1, 0, nt - 1, i))
                return -1;

            btm = i;
            btml = j;
            btmr = j + (N - st_h[i][1] - 1);
            break;
        }
        break;
    }

    int lft;
    int lft_up, lft_dwn;
    for (int i = 0; i < N; i++)
    {
        if (st_v[i][1] == N) continue;
        for (int j = 0; j < N; j++)
        {
            if (F[j][i]) continue;
            if (getvrange(j, j + (N - st_v[i][1] - 1), 1, 0, nt - 1, i))
                return -1;

            lft = i;
            lft_up = j;
            lft_dwn = j + (N - st_v[i][1] - 1);
            break;
        }
        break;
    }

    int right;
    int right_up, right_dwn;
    for (int i = N-1; i >= 0; i--)
    {
        if (st_v[i][1] == N) continue;
        for (int j = 0; j < N; j++)
        {
            if (F[j][i]) continue;
            if (getvrange(j, j + (N - st_v[i][1] - 1), 1, 0, nt - 1, i))
                return -1;

            right = i;
            right_up = j;
            right_dwn = j + (N - st_v[i][1] - 1);
            break;
        }
        break;
    }

    if (!(lft_up >= right_up && lft_dwn <= right_dwn) && !(lft_up <= right_up && lft_dwn >= right_dwn))
        return -1;

    int v = max(max(lft_up, right_up), min(lft_dwn, right_dwn));
    if (!(topl >= btml && topr <= btmr) && !(topl <= btml && topr >= btmr))
        return -1;
    int h = max(max(topl, btml), min(topr, btmr));

    int cnt = 0;
    for (int x = 0; x < N; x++)
    {
        for (int y = 0; y < N; y++)
        {
            if (F[y][x]) 
                continue;
            cnt++;

            if (gethrange(x, h, 1, 0, nt - 1, y))
                return -1;
            if (getvrange(y, v, 1, 0, nt - 1, x))
                return -1;
        }
    }

    for (int x = 0; x < N; x++)
    {
        for (int y = 0; y < N; y++)
        {
            if (F[y][x]) 
                continue;

            {
                bool b1 = getvrange(y, lft_up, 1, 0, nt - 1, x) || gethrange(x, lft, 1, 0, nt - 1, lft_up);
                bool b2 = getvrange(y, lft_up, 1, 0, nt - 1, lft) || gethrange(x, lft, 1, 0, nt - 1, y);
      
                if (b1 && b2)
                    return -1;    
            }

            {
                bool b1 = getvrange(y, right_up, 1, 0, nt - 1, x) || gethrange(x, right, 1, 0, nt - 1, right_up);
                bool b2 = getvrange(y, right_up, 1, 0, nt - 1, right) || gethrange(x, right, 1, 0, nt - 1, y);
      
                if (b1 && b2)
                    return -1;    
            }
            
            {
                bool b1 = getvrange(y, lft_dwn, 1, 0, nt - 1, x) || gethrange(x, lft, 1, 0, nt - 1, lft_dwn);
                bool b2 = getvrange(y, lft_dwn, 1, 0, nt - 1, lft) || gethrange(x, lft, 1, 0, nt - 1, y);
      
                if (b1 && b2)
                    return -1;    
            }

            {
                bool b1 = getvrange(y, right_dwn, 1, 0, nt - 1, x) || gethrange(x, right, 1, 0, nt - 1, right_dwn);
                bool b2 = getvrange(y, right_dwn, 1, 0, nt - 1, right) || gethrange(x, right, 1, 0, nt - 1, y);
      
                if (b1 && b2)
                    return -1;    
            }

            {
                bool b1 = getvrange(y, top, 1, 0, nt - 1, topl) || gethrange(x, topl, 1, 0, nt - 1, y);
                bool b2 = getvrange(y, top, 1, 0, nt - 1, x) || gethrange(x, topl, 1, 0, nt - 1, top);
      
                if (b1 && b2)
                    return -1;    
            }

            {
                bool b1 = getvrange(y, top, 1, 0, nt - 1, topr) || gethrange(x, topr, 1, 0, nt - 1, y);
                bool b2 = getvrange(y, top, 1, 0, nt - 1, x) || gethrange(x, topr, 1, 0, nt - 1, top);
      
                if (b1 && b2)
                    return -1;    
            }

            {
                bool b1 = getvrange(y, btm, 1, 0, nt - 1, btml) || gethrange(x, btml, 1, 0, nt - 1, y);
                bool b2 = getvrange(y, btm, 1, 0, nt - 1, x) || gethrange(x, btml, 1, 0, nt - 1, btm);
      
                if (b1 && b2)
                    return -1;    
            }

            {
                bool b1 = getvrange(y, btm, 1, 0, nt - 1, btmr) || gethrange(x, btmr, 1, 0, nt - 1, y);
                bool b2 = getvrange(y, btm, 1, 0, nt - 1, x) || gethrange(x, btmr, 1, 0, nt - 1, btm);
      
                if (b1 && b2)
                    return -1;    
            }
        }
    }


    return cnt;
}

Compilation message

soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:30:9: warning: unused variable 'res' [-Wunused-variable]
   30 |     int res = 0;
      |         ^~~
soccer.cpp:128:18: warning: 'right_up' may be used uninitialized in this function [-Wmaybe-uninitialized]
  128 |     if (!(lft_up >= right_up && lft_dwn <= right_dwn) && !(lft_up <= right_up && lft_dwn >= right_dwn))
      |           ~~~~~~~^~~~~~~~~~~
soccer.cpp:128:41: warning: 'right_dwn' may be used uninitialized in this function [-Wmaybe-uninitialized]
  128 |     if (!(lft_up >= right_up && lft_dwn <= right_dwn) && !(lft_up <= right_up && lft_dwn >= right_dwn))
      |                                 ~~~~~~~~^~~~~~~~~~~~
soccer.cpp:128:18: warning: 'right_up' may be used uninitialized in this function [-Wmaybe-uninitialized]
  128 |     if (!(lft_up >= right_up && lft_dwn <= right_dwn) && !(lft_up <= right_up && lft_dwn >= right_dwn))
      |           ~~~~~~~^~~~~~~~~~~
soccer.cpp:128:41: warning: 'right_dwn' may be used uninitialized in this function [-Wmaybe-uninitialized]
  128 |     if (!(lft_up >= right_up && lft_dwn <= right_dwn) && !(lft_up <= right_up && lft_dwn >= right_dwn))
      |                                 ~~~~~~~~^~~~~~~~~~~~
soccer.cpp:128:18: warning: 'right_up' may be used uninitialized in this function [-Wmaybe-uninitialized]
  128 |     if (!(lft_up >= right_up && lft_dwn <= right_dwn) && !(lft_up <= right_up && lft_dwn >= right_dwn))
      |           ~~~~~~~^~~~~~~~~~~
soccer.cpp:128:41: warning: 'right_dwn' may be used uninitialized in this function [-Wmaybe-uninitialized]
  128 |     if (!(lft_up >= right_up && lft_dwn <= right_dwn) && !(lft_up <= right_up && lft_dwn >= right_dwn))
      |                                 ~~~~~~~~^~~~~~~~~~~~
soccer.cpp:161:79: warning: 'lft' may be used uninitialized in this function [-Wmaybe-uninitialized]
  161 |                 bool b2 = getvrange(y, lft_up, 1, 0, nt - 1, lft) || gethrange(x, lft, 1, 0, nt - 1, y);
      |                                                                      ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:217:74: warning: 'btm' may be used uninitialized in this function [-Wmaybe-uninitialized]
  217 |                 bool b2 = getvrange(y, btm, 1, 0, nt - 1, x) || gethrange(x, btmr, 1, 0, nt - 1, btm);
      |                                                                 ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:201:74: warning: 'top' may be used uninitialized in this function [-Wmaybe-uninitialized]
  201 |                 bool b2 = getvrange(y, top, 1, 0, nt - 1, x) || gethrange(x, topr, 1, 0, nt - 1, top);
      |                                                                 ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:169:83: warning: 'right' may be used uninitialized in this function [-Wmaybe-uninitialized]
  169 |                 bool b2 = getvrange(y, right_up, 1, 0, nt - 1, right) || gethrange(x, right, 1, 0, nt - 1, y);
      |                                                                          ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 344 KB partial
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 348 KB ok
6 Partially correct 1 ms 348 KB partial
7 Partially correct 1 ms 604 KB partial
8 Partially correct 19 ms 6296 KB partial
9 Partially correct 230 ms 96036 KB partial
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB ok
2 Correct 0 ms 348 KB ok
3 Partially correct 0 ms 344 KB partial
4 Partially correct 0 ms 344 KB partial
5 Partially correct 0 ms 348 KB partial
6 Partially correct 0 ms 348 KB partial
7 Partially correct 0 ms 348 KB partial
8 Correct 0 ms 348 KB ok
9 Correct 0 ms 348 KB ok
10 Partially correct 0 ms 344 KB partial
11 Partially correct 0 ms 344 KB partial
12 Partially correct 0 ms 348 KB partial
13 Correct 0 ms 348 KB ok
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 344 KB partial
2 Correct 0 ms 348 KB ok
3 Correct 0 ms 348 KB ok
4 Partially correct 0 ms 344 KB partial
5 Partially correct 0 ms 344 KB partial
6 Partially correct 0 ms 348 KB partial
7 Partially correct 0 ms 348 KB partial
8 Partially correct 0 ms 348 KB partial
9 Correct 0 ms 348 KB ok
10 Correct 0 ms 348 KB ok
11 Partially correct 0 ms 344 KB partial
12 Partially correct 0 ms 344 KB partial
13 Partially correct 0 ms 348 KB partial
14 Correct 0 ms 348 KB ok
15 Partially correct 0 ms 344 KB partial
16 Partially correct 0 ms 348 KB partial
17 Partially correct 0 ms 348 KB partial
18 Partially correct 0 ms 348 KB partial
19 Partially correct 1 ms 344 KB partial
20 Correct 0 ms 348 KB ok
21 Correct 0 ms 348 KB ok
22 Partially correct 0 ms 348 KB partial
23 Partially correct 0 ms 348 KB partial
24 Partially correct 0 ms 348 KB partial
25 Partially correct 0 ms 348 KB partial
26 Partially correct 0 ms 348 KB partial
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 344 KB partial
2 Correct 0 ms 348 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 348 KB ok
6 Partially correct 0 ms 344 KB partial
7 Partially correct 0 ms 344 KB partial
8 Partially correct 0 ms 348 KB partial
9 Partially correct 0 ms 348 KB partial
10 Partially correct 0 ms 348 KB partial
11 Correct 0 ms 348 KB ok
12 Correct 0 ms 348 KB ok
13 Partially correct 0 ms 344 KB partial
14 Partially correct 0 ms 344 KB partial
15 Partially correct 0 ms 348 KB partial
16 Correct 0 ms 348 KB ok
17 Partially correct 0 ms 344 KB partial
18 Partially correct 0 ms 348 KB partial
19 Partially correct 0 ms 348 KB partial
20 Partially correct 0 ms 348 KB partial
21 Partially correct 1 ms 344 KB partial
22 Correct 0 ms 348 KB ok
23 Correct 0 ms 348 KB ok
24 Partially correct 0 ms 348 KB partial
25 Partially correct 0 ms 348 KB partial
26 Partially correct 0 ms 348 KB partial
27 Partially correct 0 ms 348 KB partial
28 Partially correct 0 ms 348 KB partial
29 Partially correct 0 ms 344 KB partial
30 Partially correct 0 ms 348 KB partial
31 Partially correct 0 ms 348 KB partial
32 Partially correct 0 ms 348 KB partial
33 Partially correct 1 ms 348 KB partial
34 Correct 1 ms 348 KB ok
35 Correct 1 ms 348 KB ok
36 Partially correct 0 ms 348 KB partial
37 Partially correct 0 ms 344 KB partial
38 Partially correct 0 ms 348 KB partial
39 Partially correct 1 ms 348 KB partial
40 Partially correct 0 ms 348 KB partial
41 Partially correct 0 ms 348 KB partial
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 344 KB partial
2 Correct 0 ms 348 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 348 KB ok
6 Partially correct 0 ms 344 KB partial
7 Partially correct 0 ms 344 KB partial
8 Partially correct 0 ms 348 KB partial
9 Partially correct 0 ms 348 KB partial
10 Partially correct 0 ms 348 KB partial
11 Correct 0 ms 348 KB ok
12 Correct 0 ms 348 KB ok
13 Partially correct 0 ms 344 KB partial
14 Partially correct 0 ms 344 KB partial
15 Partially correct 0 ms 348 KB partial
16 Correct 0 ms 348 KB ok
17 Partially correct 0 ms 344 KB partial
18 Partially correct 0 ms 348 KB partial
19 Partially correct 0 ms 348 KB partial
20 Partially correct 0 ms 348 KB partial
21 Partially correct 1 ms 344 KB partial
22 Correct 0 ms 348 KB ok
23 Correct 0 ms 348 KB ok
24 Partially correct 0 ms 348 KB partial
25 Partially correct 0 ms 348 KB partial
26 Partially correct 0 ms 348 KB partial
27 Partially correct 0 ms 348 KB partial
28 Partially correct 0 ms 348 KB partial
29 Partially correct 0 ms 344 KB partial
30 Partially correct 0 ms 348 KB partial
31 Partially correct 0 ms 348 KB partial
32 Partially correct 0 ms 348 KB partial
33 Partially correct 1 ms 348 KB partial
34 Correct 1 ms 348 KB ok
35 Correct 1 ms 348 KB ok
36 Partially correct 0 ms 348 KB partial
37 Partially correct 0 ms 344 KB partial
38 Partially correct 0 ms 348 KB partial
39 Partially correct 1 ms 348 KB partial
40 Partially correct 0 ms 348 KB partial
41 Partially correct 0 ms 348 KB partial
42 Partially correct 14 ms 6236 KB partial
43 Partially correct 16 ms 6236 KB partial
44 Partially correct 14 ms 6236 KB partial
45 Partially correct 15 ms 6236 KB partial
46 Partially correct 14 ms 6236 KB partial
47 Partially correct 14 ms 6236 KB partial
48 Correct 244 ms 6456 KB ok
49 Partially correct 15 ms 6748 KB partial
50 Partially correct 14 ms 6748 KB partial
51 Partially correct 15 ms 6772 KB partial
52 Partially correct 14 ms 6748 KB partial
53 Partially correct 14 ms 6748 KB partial
54 Partially correct 38 ms 6744 KB partial
55 Partially correct 69 ms 6748 KB partial
56 Partially correct 19 ms 6748 KB partial
57 Partially correct 14 ms 6748 KB partial
58 Partially correct 15 ms 6744 KB partial
59 Partially correct 14 ms 6748 KB partial
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 344 KB partial
2 Correct 0 ms 348 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 0 ms 348 KB ok
5 Correct 0 ms 348 KB ok
6 Correct 0 ms 348 KB ok
7 Partially correct 1 ms 348 KB partial
8 Partially correct 1 ms 604 KB partial
9 Partially correct 19 ms 6296 KB partial
10 Partially correct 230 ms 96036 KB partial
11 Partially correct 0 ms 344 KB partial
12 Partially correct 0 ms 344 KB partial
13 Partially correct 0 ms 348 KB partial
14 Partially correct 0 ms 348 KB partial
15 Partially correct 0 ms 348 KB partial
16 Correct 0 ms 348 KB ok
17 Correct 0 ms 348 KB ok
18 Partially correct 0 ms 344 KB partial
19 Partially correct 0 ms 344 KB partial
20 Partially correct 0 ms 348 KB partial
21 Correct 0 ms 348 KB ok
22 Partially correct 0 ms 344 KB partial
23 Partially correct 0 ms 348 KB partial
24 Partially correct 0 ms 348 KB partial
25 Partially correct 0 ms 348 KB partial
26 Partially correct 1 ms 344 KB partial
27 Correct 0 ms 348 KB ok
28 Correct 0 ms 348 KB ok
29 Partially correct 0 ms 348 KB partial
30 Partially correct 0 ms 348 KB partial
31 Partially correct 0 ms 348 KB partial
32 Partially correct 0 ms 348 KB partial
33 Partially correct 0 ms 348 KB partial
34 Partially correct 0 ms 344 KB partial
35 Partially correct 0 ms 348 KB partial
36 Partially correct 0 ms 348 KB partial
37 Partially correct 0 ms 348 KB partial
38 Partially correct 1 ms 348 KB partial
39 Correct 1 ms 348 KB ok
40 Correct 1 ms 348 KB ok
41 Partially correct 0 ms 348 KB partial
42 Partially correct 0 ms 344 KB partial
43 Partially correct 0 ms 348 KB partial
44 Partially correct 1 ms 348 KB partial
45 Partially correct 0 ms 348 KB partial
46 Partially correct 0 ms 348 KB partial
47 Partially correct 14 ms 6236 KB partial
48 Partially correct 16 ms 6236 KB partial
49 Partially correct 14 ms 6236 KB partial
50 Partially correct 15 ms 6236 KB partial
51 Partially correct 14 ms 6236 KB partial
52 Partially correct 14 ms 6236 KB partial
53 Correct 244 ms 6456 KB ok
54 Partially correct 15 ms 6748 KB partial
55 Partially correct 14 ms 6748 KB partial
56 Partially correct 15 ms 6772 KB partial
57 Partially correct 14 ms 6748 KB partial
58 Partially correct 14 ms 6748 KB partial
59 Partially correct 38 ms 6744 KB partial
60 Partially correct 69 ms 6748 KB partial
61 Partially correct 19 ms 6748 KB partial
62 Partially correct 14 ms 6748 KB partial
63 Partially correct 15 ms 6744 KB partial
64 Partially correct 14 ms 6748 KB partial
65 Partially correct 243 ms 103764 KB partial
66 Partially correct 261 ms 103828 KB partial
67 Partially correct 241 ms 103832 KB partial
68 Partially correct 258 ms 103764 KB partial
69 Partially correct 256 ms 103828 KB partial
70 Partially correct 282 ms 104272 KB partial
71 Partially correct 233 ms 103960 KB partial
72 Partially correct 240 ms 103828 KB partial
73 Execution timed out 4554 ms 103832 KB Time limit exceeded
74 Halted 0 ms 0 KB -