답안 #1072578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072578 2024-08-23T22:37:17 Z HorizonWest 축구 경기장 (IOI23_soccer) C++17
77.5 / 100
3724 ms 922528 KB
#include <iostream>
#include <complex>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <bitset>
#include <queue>
#include <map>
#include <stack>
#include <cmath>
#include <cstdint>
#include <cassert>
using namespace std;

const int Max = 3001, Inf = 1e9, TLE = 3e6;

#define ll unsigned long long

int lg[Max], cnt; 

struct SPTMIN
{
    vector <vector <int>> spt; 

    int query(int i, int j){
        int x = lg[j-i+1];
        return min(spt[i][x], spt[j - (1LL << x) + 1][x]);
    }

    SPTMIN(vector <int> v)
    {
        int n = v.size();
        spt.assign(n + 1, vector <int> (lg[n] + 1, Inf));

        for(int j = 0; j < lg[n]+1; j++)
        {
            for(int i = 0; i < n; i++){
                if(j == 0){
                    spt[i][j] = v[i];
                    continue;
                }
                spt[i][j] = spt[i][j-1];
                if(i + (1LL << (j-1)) < n) spt[i][j] = min(spt[i][j-1], spt[i + (1LL << (j-1))][j-1]);
            }
        }
    }
};

struct SPTMAX
{
    vector <vector <int>> spt; 

    int query(int i, int j){
        int x = lg[j-i+1];
        return max(spt[i][x], spt[j - (1LL << x) + 1][x]);
    }

    SPTMAX(vector <int> v)
    {
        int n = v.size();
        spt.assign(n + 1, vector <int> (lg[n] + 1, 0));

        for(int j = 0; j < lg[n]+1; j++)
        {
            for(int i = 0; i < n; i++){
                if(j == 0){
                    spt[i][j] = v[i];
                    continue;
                }
                spt[i][j] = spt[i][j-1];
                if(i + (1LL << (j-1)) < n) spt[i][j] = max(spt[i][j-1], spt[i + (1LL << (j-1))][j-1]);
            }
        }
    }
};

int biggest_stadium(int n, std::vector<std::vector<int>> f)
{
    vector <vector<int>> A(n, vector <int> (n, 0)),
        B(n, vector <int> (n, 0)),
        C(n, vector <int> (n, 0)),
        D(n, vector <int> (n, 0)); 

    vector <SPTMIN> sp1;
    vector <SPTMAX> sp2;

    cnt = 0;

    for(int i = 1; i <= n; i++){
        lg[i] = log2(i);
    }

    for(int i = 0; i < n; i++)
    {
        int last = -1; 
        for(int j = 0; j < n; j++){
            if(f[i][j] == 1) last = j; 
            A[i][j] = last;
        }   

        last = n;
        for(int j = n-1; j >= 0; j--){
            if(f[i][j] == 1) last = j; 
            B[i][j] = last;
        }     
    }

    for(int i = 0; i < n; i++)
    {
        int last = -1; 
        for(int j = 0; j < n; j++){
            if(f[j][i] == 1) last = j; 
            C[j][i] = last+1;
        }   

        last = n;
        for(int j = n-1; j >= 0; j--){
            if(f[j][i] == 1) last = j; 
            D[j][i] = last-1;
        }     
    }

    for(int i = 0; i < n; i++)
    {
        sp1.push_back(SPTMIN(D[i]));
        sp2.push_back(SPTMAX(C[i]));
    }
    
    //return 0;

    //vector <vector<vector<int>>> dp1(n + 1, vector <vector<int>> 
    //    (n + 1, vector <int> (n + 1, -1)));

    //vector <vector<vector<int>>> dp2(n + 1, vector <vector<int>> 
    //    (n + 1, vector <int> (n + 1, -1)));

    map <ll, int> dp; 

    auto F = [&](auto F, int i, int j, int a, int b, int c, int d) -> int 
    {   cnt++;

        long long x = ((ll) b) + (((ll) c) << 11LL) + (((ll) d) << 22LL) + (((ll) j) << 33LL) 
                               + (((ll) i) << 44LL) + (((ll) a) << 55LL);
        
        if(dp[x] != 0) return dp[x];
        dp[x] = (b - a + 1); 
        if(i != j) dp[x] += (d - c + 1);

        int mx = 0;

        if(i != 0)
        {
            for(int k = a; k <= b; k++) if(f[i-1][k] == 0)
            {
                int l1 = max(A[i-1][k]+1, a), r1 = min(B[i-1][k]-1, b);
                int l2 = max(c, l1), r2 =  min(d, r1);

                int ni = sp2[i].query(l1, r1), d = abs(ni - i) - 1, t = (r1 - l1 + 1);

                mx = max(mx, F(F, ni, j, l1, r1, l2, r2) - (r2 - l2 + 1) + d * t);

                k = r1;
            }
        }

        if(j != n-1)
        {
            for(int k = c; k <= d; k++) if(f[j+1][k] == 0)
            {
                int l2 = max(A[j+1][k]+1, c), r2 = min(B[j+1][k]-1, d);
                int l1 = max(a, l2), r1 =  min(b, r2);

                int nj = sp1[j].query(l2, r2), d = abs(nj - j) - 1, t = (r2 - l2 + 1);

                mx = max(mx, F(F, i, nj, l1, r1, l2, r2) - (r1 - l1 + 1) + d * t);

                k = r2;
            }
        }

        return dp[x] = (dp[x] + mx);
    };      
    
    int ans = 0; 
  	
  	srand(time(NULL));
  	vector <pair<int, int>> fx; 
  
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            fx.push_back({ i, j });
        }
    }
  	
  	int mod = (int) fx.size(); 
 	for(int i = 0; i < (int) fx.size(); i++){
      int x = rand() % mod;
      swap(fx[i], fx[x]);
    }
  
  	for(auto& u : fx)
    {
      int i = u.first, j = u.second; 
      
      if(f[i][j] == 1) continue; 
      
      int l = A[i][j]+1, r = B[i][j]-1;

      ans = max(ans, F(F, i, i, l, r, l, r));

      if(n > 500 && cnt > TLE) {
        return ans;
      }
    }

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB ok
# 결과 실행 시간 메모리 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 344 KB ok
6 Correct 1 ms 348 KB ok
7 Correct 4 ms 2268 KB ok
8 Correct 89 ms 43840 KB ok
9 Correct 1903 ms 818300 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 1 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 Correct 0 ms 348 KB ok
8 Correct 0 ms 420 KB ok
9 Correct 0 ms 348 KB ok
10 Correct 0 ms 348 KB ok
11 Correct 0 ms 348 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 0 ms 348 KB ok
# 결과 실행 시간 메모리 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 1 ms 348 KB ok
5 Correct 0 ms 348 KB ok
6 Correct 0 ms 348 KB ok
7 Correct 0 ms 348 KB ok
8 Correct 0 ms 348 KB ok
9 Correct 0 ms 420 KB ok
10 Correct 0 ms 348 KB ok
11 Correct 0 ms 348 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 0 ms 348 KB ok
14 Correct 0 ms 348 KB ok
15 Correct 0 ms 348 KB ok
16 Correct 0 ms 348 KB ok
17 Correct 0 ms 348 KB ok
18 Correct 0 ms 348 KB ok
19 Correct 0 ms 348 KB ok
20 Correct 1 ms 348 KB ok
21 Correct 0 ms 348 KB ok
22 Correct 0 ms 348 KB ok
23 Correct 0 ms 348 KB ok
24 Correct 0 ms 348 KB ok
25 Correct 0 ms 348 KB ok
26 Correct 0 ms 348 KB ok
# 결과 실행 시간 메모리 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 Correct 1 ms 348 KB ok
7 Correct 0 ms 348 KB ok
8 Correct 0 ms 348 KB ok
9 Correct 0 ms 348 KB ok
10 Correct 0 ms 348 KB ok
11 Correct 0 ms 420 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 0 ms 348 KB ok
14 Correct 0 ms 348 KB ok
15 Correct 0 ms 348 KB ok
16 Correct 0 ms 348 KB ok
17 Correct 0 ms 348 KB ok
18 Correct 0 ms 348 KB ok
19 Correct 0 ms 348 KB ok
20 Correct 0 ms 348 KB ok
21 Correct 0 ms 348 KB ok
22 Correct 1 ms 348 KB ok
23 Correct 0 ms 348 KB ok
24 Correct 0 ms 348 KB ok
25 Correct 0 ms 348 KB ok
26 Correct 0 ms 348 KB ok
27 Correct 0 ms 348 KB ok
28 Correct 0 ms 348 KB ok
29 Correct 0 ms 348 KB ok
30 Correct 1 ms 612 KB ok
31 Correct 1 ms 604 KB ok
32 Correct 1 ms 344 KB ok
33 Correct 0 ms 348 KB ok
34 Correct 1 ms 348 KB ok
35 Correct 0 ms 348 KB ok
36 Correct 1 ms 344 KB ok
37 Correct 0 ms 348 KB ok
38 Correct 1 ms 348 KB ok
39 Correct 1 ms 600 KB ok
40 Correct 1 ms 348 KB ok
41 Correct 1 ms 604 KB ok
# 결과 실행 시간 메모리 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 Correct 1 ms 348 KB ok
7 Correct 0 ms 348 KB ok
8 Correct 0 ms 348 KB ok
9 Correct 0 ms 348 KB ok
10 Correct 0 ms 348 KB ok
11 Correct 0 ms 420 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 0 ms 348 KB ok
14 Correct 0 ms 348 KB ok
15 Correct 0 ms 348 KB ok
16 Correct 0 ms 348 KB ok
17 Correct 0 ms 348 KB ok
18 Correct 0 ms 348 KB ok
19 Correct 0 ms 348 KB ok
20 Correct 0 ms 348 KB ok
21 Correct 0 ms 348 KB ok
22 Correct 1 ms 348 KB ok
23 Correct 0 ms 348 KB ok
24 Correct 0 ms 348 KB ok
25 Correct 0 ms 348 KB ok
26 Correct 0 ms 348 KB ok
27 Correct 0 ms 348 KB ok
28 Correct 0 ms 348 KB ok
29 Correct 0 ms 348 KB ok
30 Correct 1 ms 612 KB ok
31 Correct 1 ms 604 KB ok
32 Correct 1 ms 344 KB ok
33 Correct 0 ms 348 KB ok
34 Correct 1 ms 348 KB ok
35 Correct 0 ms 348 KB ok
36 Correct 1 ms 344 KB ok
37 Correct 0 ms 348 KB ok
38 Correct 1 ms 348 KB ok
39 Correct 1 ms 600 KB ok
40 Correct 1 ms 348 KB ok
41 Correct 1 ms 604 KB ok
42 Correct 513 ms 64964 KB ok
43 Correct 446 ms 60612 KB ok
44 Correct 614 ms 69824 KB ok
45 Correct 544 ms 67268 KB ok
46 Correct 586 ms 68288 KB ok
47 Correct 108 ms 44488 KB ok
48 Correct 163 ms 49092 KB ok
49 Correct 172 ms 48580 KB ok
50 Correct 354 ms 63008 KB ok
51 Correct 285 ms 56516 KB ok
52 Correct 91 ms 46020 KB ok
53 Correct 67 ms 44228 KB ok
54 Correct 90 ms 45764 KB ok
55 Correct 115 ms 47300 KB ok
56 Correct 89 ms 44772 KB ok
57 Correct 238 ms 55392 KB ok
58 Correct 246 ms 56000 KB ok
59 Correct 278 ms 56768 KB ok
# 결과 실행 시간 메모리 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 Correct 0 ms 344 KB ok
7 Correct 1 ms 348 KB ok
8 Correct 4 ms 2268 KB ok
9 Correct 89 ms 43840 KB ok
10 Correct 1903 ms 818300 KB ok
11 Correct 1 ms 348 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 0 ms 348 KB ok
14 Correct 0 ms 348 KB ok
15 Correct 0 ms 348 KB ok
16 Correct 0 ms 420 KB ok
17 Correct 0 ms 348 KB ok
18 Correct 0 ms 348 KB ok
19 Correct 0 ms 348 KB ok
20 Correct 0 ms 348 KB ok
21 Correct 0 ms 348 KB ok
22 Correct 0 ms 348 KB ok
23 Correct 0 ms 348 KB ok
24 Correct 0 ms 348 KB ok
25 Correct 0 ms 348 KB ok
26 Correct 0 ms 348 KB ok
27 Correct 1 ms 348 KB ok
28 Correct 0 ms 348 KB ok
29 Correct 0 ms 348 KB ok
30 Correct 0 ms 348 KB ok
31 Correct 0 ms 348 KB ok
32 Correct 0 ms 348 KB ok
33 Correct 0 ms 348 KB ok
34 Correct 0 ms 348 KB ok
35 Correct 1 ms 612 KB ok
36 Correct 1 ms 604 KB ok
37 Correct 1 ms 344 KB ok
38 Correct 0 ms 348 KB ok
39 Correct 1 ms 348 KB ok
40 Correct 0 ms 348 KB ok
41 Correct 1 ms 344 KB ok
42 Correct 0 ms 348 KB ok
43 Correct 1 ms 348 KB ok
44 Correct 1 ms 600 KB ok
45 Correct 1 ms 348 KB ok
46 Correct 1 ms 604 KB ok
47 Correct 513 ms 64964 KB ok
48 Correct 446 ms 60612 KB ok
49 Correct 614 ms 69824 KB ok
50 Correct 544 ms 67268 KB ok
51 Correct 586 ms 68288 KB ok
52 Correct 108 ms 44488 KB ok
53 Correct 163 ms 49092 KB ok
54 Correct 172 ms 48580 KB ok
55 Correct 354 ms 63008 KB ok
56 Correct 285 ms 56516 KB ok
57 Correct 91 ms 46020 KB ok
58 Correct 67 ms 44228 KB ok
59 Correct 90 ms 45764 KB ok
60 Correct 115 ms 47300 KB ok
61 Correct 89 ms 44772 KB ok
62 Correct 238 ms 55392 KB ok
63 Correct 246 ms 56000 KB ok
64 Correct 278 ms 56768 KB ok
65 Correct 2886 ms 920428 KB ok
66 Correct 3637 ms 896368 KB ok
67 Correct 1611 ms 840928 KB ok
68 Correct 3239 ms 909792 KB ok
69 Partially correct 2664 ms 911008 KB partial
70 Partially correct 2605 ms 914084 KB partial
71 Correct 3101 ms 909496 KB ok
72 Correct 2288 ms 828024 KB ok
73 Correct 3486 ms 905760 KB ok
74 Correct 3724 ms 914416 KB ok
75 Correct 3488 ms 912820 KB ok
76 Correct 2093 ms 917480 KB ok
77 Correct 2032 ms 917208 KB ok
78 Correct 2483 ms 918320 KB ok
79 Correct 1556 ms 839212 KB ok
80 Correct 1602 ms 838044 KB ok
81 Correct 2120 ms 854864 KB ok
82 Correct 3578 ms 894340 KB ok
83 Correct 3254 ms 878824 KB ok
84 Correct 1625 ms 838488 KB ok
85 Correct 1371 ms 830292 KB ok
86 Correct 1752 ms 846384 KB ok
87 Correct 2035 ms 852088 KB ok
88 Correct 2283 ms 843744 KB ok
89 Correct 2247 ms 825252 KB ok
90 Correct 2291 ms 829668 KB ok
91 Correct 2373 ms 832320 KB ok
92 Correct 1745 ms 842572 KB ok
93 Correct 1937 ms 851496 KB ok
94 Correct 1318 ms 829400 KB ok
95 Correct 1351 ms 826524 KB ok
96 Correct 1256 ms 825432 KB ok
97 Correct 1151 ms 825264 KB ok
98 Correct 1054 ms 825328 KB ok
99 Correct 2399 ms 922528 KB ok
100 Correct 2122 ms 917748 KB ok
101 Correct 2084 ms 917988 KB ok
102 Correct 2186 ms 917676 KB ok
103 Correct 2355 ms 918948 KB ok
104 Correct 1921 ms 918432 KB ok
105 Correct 1860 ms 918172 KB ok
106 Correct 2837 ms 917600 KB ok
107 Partially correct 2830 ms 919160 KB partial
108 Correct 3417 ms 920304 KB ok
109 Correct 3232 ms 920216 KB ok