Submission #1072553

# Submission time Handle Problem Language Result Execution time Memory
1072553 2024-08-23T21:52:57 Z HorizonWest Soccer Stadium (IOI23_soccer) C++17
70 / 100
4500 ms 1064272 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;

int lg[Max]; 

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;

    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 <vector<int>, int> dp; 

    auto F = [&](auto F, int i, int j, int a, int b, int c, int d) -> int 
    {
        vector <int> x = { i, j, a, b, c, d };
        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; 

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            int l = A[i][j]+1, r = B[i][j]-1;

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

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB ok
# Verdict Execution time Memory 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 604 KB ok
5 Correct 0 ms 348 KB ok
6 Correct 0 ms 348 KB ok
7 Correct 4 ms 2140 KB ok
8 Correct 88 ms 42364 KB ok
9 Correct 1474 ms 792972 KB ok
# Verdict Execution time Memory 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 1 ms 348 KB ok
8 Correct 1 ms 348 KB ok
9 Correct 1 ms 348 KB ok
10 Correct 1 ms 348 KB ok
11 Correct 0 ms 348 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 0 ms 344 KB ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 1 ms 348 KB ok
9 Correct 1 ms 348 KB ok
10 Correct 1 ms 348 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 344 KB ok
15 Correct 0 ms 344 KB ok
16 Correct 1 ms 604 KB ok
17 Correct 0 ms 688 KB ok
18 Correct 1 ms 348 KB ok
19 Correct 0 ms 348 KB ok
20 Correct 1 ms 344 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 1 ms 348 KB ok
25 Correct 1 ms 344 KB ok
26 Correct 0 ms 344 KB ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 604 KB ok
6 Correct 0 ms 348 KB ok
7 Correct 0 ms 348 KB ok
8 Correct 0 ms 344 KB ok
9 Correct 1 ms 348 KB ok
10 Correct 1 ms 348 KB ok
11 Correct 1 ms 348 KB ok
12 Correct 1 ms 348 KB ok
13 Correct 1 ms 348 KB ok
14 Correct 0 ms 348 KB ok
15 Correct 0 ms 348 KB ok
16 Correct 0 ms 344 KB ok
17 Correct 0 ms 344 KB ok
18 Correct 1 ms 604 KB ok
19 Correct 0 ms 688 KB ok
20 Correct 1 ms 348 KB ok
21 Correct 0 ms 348 KB ok
22 Correct 1 ms 344 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 1 ms 348 KB ok
27 Correct 1 ms 344 KB ok
28 Correct 0 ms 344 KB ok
29 Correct 1 ms 348 KB ok
30 Correct 2 ms 604 KB ok
31 Correct 1 ms 604 KB ok
32 Correct 1 ms 604 KB ok
33 Correct 1 ms 604 KB ok
34 Correct 1 ms 604 KB ok
35 Correct 1 ms 604 KB ok
36 Correct 1 ms 604 KB ok
37 Correct 2 ms 604 KB ok
38 Correct 1 ms 604 KB ok
39 Correct 1 ms 444 KB ok
40 Correct 1 ms 408 KB ok
41 Correct 1 ms 604 KB ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 604 KB ok
6 Correct 0 ms 348 KB ok
7 Correct 0 ms 348 KB ok
8 Correct 0 ms 344 KB ok
9 Correct 1 ms 348 KB ok
10 Correct 1 ms 348 KB ok
11 Correct 1 ms 348 KB ok
12 Correct 1 ms 348 KB ok
13 Correct 1 ms 348 KB ok
14 Correct 0 ms 348 KB ok
15 Correct 0 ms 348 KB ok
16 Correct 0 ms 344 KB ok
17 Correct 0 ms 344 KB ok
18 Correct 1 ms 604 KB ok
19 Correct 0 ms 688 KB ok
20 Correct 1 ms 348 KB ok
21 Correct 0 ms 348 KB ok
22 Correct 1 ms 344 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 1 ms 348 KB ok
27 Correct 1 ms 344 KB ok
28 Correct 0 ms 344 KB ok
29 Correct 1 ms 348 KB ok
30 Correct 2 ms 604 KB ok
31 Correct 1 ms 604 KB ok
32 Correct 1 ms 604 KB ok
33 Correct 1 ms 604 KB ok
34 Correct 1 ms 604 KB ok
35 Correct 1 ms 604 KB ok
36 Correct 1 ms 604 KB ok
37 Correct 2 ms 604 KB ok
38 Correct 1 ms 604 KB ok
39 Correct 1 ms 444 KB ok
40 Correct 1 ms 408 KB ok
41 Correct 1 ms 604 KB ok
42 Correct 621 ms 82236 KB ok
43 Correct 463 ms 77508 KB ok
44 Correct 803 ms 88188 KB ok
45 Correct 778 ms 83792 KB ok
46 Correct 728 ms 86496 KB ok
47 Correct 99 ms 43860 KB ok
48 Correct 300 ms 65052 KB ok
49 Correct 248 ms 63336 KB ok
50 Correct 386 ms 83024 KB ok
51 Correct 358 ms 68692 KB ok
52 Correct 248 ms 70120 KB ok
53 Correct 233 ms 69232 KB ok
54 Correct 274 ms 69632 KB ok
55 Correct 255 ms 70220 KB ok
56 Correct 171 ms 60680 KB ok
57 Correct 345 ms 62904 KB ok
58 Correct 310 ms 63956 KB ok
59 Correct 316 ms 65336 KB ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 604 KB ok
6 Correct 0 ms 348 KB ok
7 Correct 0 ms 348 KB ok
8 Correct 4 ms 2140 KB ok
9 Correct 88 ms 42364 KB ok
10 Correct 1474 ms 792972 KB ok
11 Correct 0 ms 348 KB ok
12 Correct 0 ms 348 KB ok
13 Correct 0 ms 344 KB ok
14 Correct 1 ms 348 KB ok
15 Correct 1 ms 348 KB ok
16 Correct 1 ms 348 KB ok
17 Correct 1 ms 348 KB ok
18 Correct 1 ms 348 KB ok
19 Correct 0 ms 348 KB ok
20 Correct 0 ms 348 KB ok
21 Correct 0 ms 344 KB ok
22 Correct 0 ms 344 KB ok
23 Correct 1 ms 604 KB ok
24 Correct 0 ms 688 KB ok
25 Correct 1 ms 348 KB ok
26 Correct 0 ms 348 KB ok
27 Correct 1 ms 344 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 1 ms 348 KB ok
32 Correct 1 ms 344 KB ok
33 Correct 0 ms 344 KB ok
34 Correct 1 ms 348 KB ok
35 Correct 2 ms 604 KB ok
36 Correct 1 ms 604 KB ok
37 Correct 1 ms 604 KB ok
38 Correct 1 ms 604 KB ok
39 Correct 1 ms 604 KB ok
40 Correct 1 ms 604 KB ok
41 Correct 1 ms 604 KB ok
42 Correct 2 ms 604 KB ok
43 Correct 1 ms 604 KB ok
44 Correct 1 ms 444 KB ok
45 Correct 1 ms 408 KB ok
46 Correct 1 ms 604 KB ok
47 Correct 621 ms 82236 KB ok
48 Correct 463 ms 77508 KB ok
49 Correct 803 ms 88188 KB ok
50 Correct 778 ms 83792 KB ok
51 Correct 728 ms 86496 KB ok
52 Correct 99 ms 43860 KB ok
53 Correct 300 ms 65052 KB ok
54 Correct 248 ms 63336 KB ok
55 Correct 386 ms 83024 KB ok
56 Correct 358 ms 68692 KB ok
57 Correct 248 ms 70120 KB ok
58 Correct 233 ms 69232 KB ok
59 Correct 274 ms 69632 KB ok
60 Correct 255 ms 70220 KB ok
61 Correct 171 ms 60680 KB ok
62 Correct 345 ms 62904 KB ok
63 Correct 310 ms 63956 KB ok
64 Correct 316 ms 65336 KB ok
65 Execution timed out 4578 ms 1064272 KB Time limit exceeded
66 Halted 0 ms 0 KB -