Submission #973262

# Submission time Handle Problem Language Result Execution time Memory
973262 2024-05-01T16:52:54 Z raphaelp Soccer Stadium (IOI23_soccer) C++17
100 / 100
849 ms 55980 KB
#include<bits/stdc++.h>
using namespace std;
int biggest_stadium(int N, vector<vector<int>> F)
{
    vector<vector<int>> Nextleft(N+1, vector<int>(N+1, -1));
    vector<int> dp(N+1, 0), sz(N+1, 0);
    for (int i=0; i<N; i++)
    {
        for (int j=0; j<N; j++)
        {
            if (F[i][j]==1)Nextleft[i][j]=j;
            else if (j>0)Nextleft[i][j]=Nextleft[i][j-1];
        }
    }
    int maxx=0;
    for (int Right=N-1; Right>=0; Right--)
    {
        vector<int> haut(N+1), bas(N+1),cursize(N+1);
        for (int i=0; i<N; i++)
        {
            haut[i]=i;
            bas[i]=i;
        }
        vector<int> ST;
        for (int i=0; i<N; i++)
        {
            int last=i;
            while(!ST.empty() && Nextleft[i][Right]>=Nextleft[ST.back()][Right])
            {
                last=ST.back();
                ST.pop_back();
            }
            ST.push_back(i);
            haut[i]=haut[last];
        }
        ST.clear();
        for (int i=N-1; i>=0; i--)
        {
            int last=i;
            while(!ST.empty() && Nextleft[i][Right]>=Nextleft[ST.back()][Right])
            {
                last=ST.back();
                ST.pop_back();
            }
            ST.push_back(i);
            bas[i]=bas[last];
            cursize[i]=bas[i]-haut[i]+1;
        }
        vector<pair<int,int>> rectangles;
        vector<int> l(N+1,-1), r(N+1, -1);
        for (int i=0; i<N;i ++)
        {
            l[i]=i-1;
            r[i]=i+1;
            if (!F[i][Right])rectangles.push_back({Nextleft[i][Right], i});
        }
        r[N-1]=-1;
        sort(rectangles.begin(), rectangles.end());
        for (int i=rectangles.size()-1; i>=0; i--)
        {
            int x=rectangles[i].second;
            dp[x]+=(cursize[x]-sz[x])*(Right-Nextleft[x][Right]);
        }
        for (int i=0; i<rectangles.size(); i++)
        {
            int x=rectangles[i].second;
            if (r[x]!=-1)dp[r[x]]=max(dp[r[x]], dp[x]+((cursize[r[x]]-cursize[x])*(Right-Nextleft[r[x]][Right])));
            if (l[x]!=-1)dp[l[x]]=max(dp[l[x]], dp[x]+((cursize[l[x]]-cursize[x])*(Right-Nextleft[l[x]][Right])));
            if (r[x]!=-1)l[r[x]]=l[x];
            if (l[x]!=-1)r[l[x]]=r[x];
            sz[x]=cursize[x];
        }
        for (int i=0; i<N; i++)
        {
            if (F[i][Right]==1)
            {
                maxx=max(maxx, dp[i]);
                dp[i]=0;
                sz[i]=0;
            }
        }
    }
    for (int i=0; i<N; i++)maxx=max(maxx, dp[i]);
    return maxx;
}

/* int main()
{
    int N;
    cin >> N;
    vector<vector<int>> F(N, vector<int>(N));
    for (int i=0; i<N; i++)
    {
        for (int j=0; j<N; j++)
        {
            cin >> F[i][j];
        }
    }
    cout << biggest_stadium(N, F);
} */

Compilation message

soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:64:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         for (int i=0; i<rectangles.size(); i++)
      |                       ~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 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 1 ms 348 KB ok
6 Correct 0 ms 348 KB ok
7 Correct 1 ms 348 KB ok
8 Correct 25 ms 3420 KB ok
9 Correct 590 ms 47652 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 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 348 KB ok
7 Correct 0 ms 348 KB ok
8 Correct 0 ms 348 KB ok
9 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB ok
2 Correct 0 ms 600 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 Correct 0 ms 348 KB ok
8 Correct 0 ms 348 KB ok
9 Correct 0 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 348 KB ok
14 Correct 0 ms 348 KB ok
15 Correct 0 ms 348 KB ok
16 Correct 1 ms 344 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 1 ms 348 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB ok
2 Correct 0 ms 600 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 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 348 KB ok
12 Correct 1 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 1 ms 344 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 0 ms 348 KB ok
28 Correct 1 ms 348 KB ok
29 Correct 0 ms 348 KB ok
30 Correct 0 ms 348 KB ok
31 Correct 0 ms 344 KB ok
32 Correct 1 ms 348 KB ok
33 Correct 1 ms 348 KB ok
34 Correct 0 ms 348 KB ok
35 Correct 1 ms 344 KB ok
36 Correct 0 ms 348 KB ok
37 Correct 1 ms 344 KB ok
38 Correct 1 ms 344 KB ok
39 Correct 1 ms 592 KB ok
40 Correct 0 ms 348 KB ok
41 Correct 1 ms 344 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB ok
2 Correct 0 ms 600 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 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 348 KB ok
12 Correct 1 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 1 ms 344 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 0 ms 348 KB ok
28 Correct 1 ms 348 KB ok
29 Correct 0 ms 348 KB ok
30 Correct 0 ms 348 KB ok
31 Correct 0 ms 344 KB ok
32 Correct 1 ms 348 KB ok
33 Correct 1 ms 348 KB ok
34 Correct 0 ms 348 KB ok
35 Correct 1 ms 344 KB ok
36 Correct 0 ms 348 KB ok
37 Correct 1 ms 344 KB ok
38 Correct 1 ms 344 KB ok
39 Correct 1 ms 592 KB ok
40 Correct 0 ms 348 KB ok
41 Correct 1 ms 344 KB ok
42 Correct 40 ms 3932 KB ok
43 Correct 38 ms 3932 KB ok
44 Correct 39 ms 3672 KB ok
45 Correct 35 ms 3664 KB ok
46 Correct 40 ms 3792 KB ok
47 Correct 29 ms 3928 KB ok
48 Correct 25 ms 3928 KB ok
49 Correct 25 ms 3932 KB ok
50 Correct 25 ms 3912 KB ok
51 Correct 31 ms 3932 KB ok
52 Correct 20 ms 3664 KB ok
53 Correct 19 ms 3672 KB ok
54 Correct 19 ms 3928 KB ok
55 Correct 36 ms 3708 KB ok
56 Correct 26 ms 3932 KB ok
57 Correct 28 ms 3672 KB ok
58 Correct 28 ms 3928 KB ok
59 Correct 28 ms 3932 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB ok
2 Correct 0 ms 600 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 1 ms 348 KB ok
9 Correct 25 ms 3420 KB ok
10 Correct 590 ms 47652 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 1 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 1 ms 344 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 0 ms 348 KB ok
31 Correct 0 ms 348 KB ok
32 Correct 0 ms 348 KB ok
33 Correct 1 ms 348 KB ok
34 Correct 0 ms 348 KB ok
35 Correct 0 ms 348 KB ok
36 Correct 0 ms 344 KB ok
37 Correct 1 ms 348 KB ok
38 Correct 1 ms 348 KB ok
39 Correct 0 ms 348 KB ok
40 Correct 1 ms 344 KB ok
41 Correct 0 ms 348 KB ok
42 Correct 1 ms 344 KB ok
43 Correct 1 ms 344 KB ok
44 Correct 1 ms 592 KB ok
45 Correct 0 ms 348 KB ok
46 Correct 1 ms 344 KB ok
47 Correct 40 ms 3932 KB ok
48 Correct 38 ms 3932 KB ok
49 Correct 39 ms 3672 KB ok
50 Correct 35 ms 3664 KB ok
51 Correct 40 ms 3792 KB ok
52 Correct 29 ms 3928 KB ok
53 Correct 25 ms 3928 KB ok
54 Correct 25 ms 3932 KB ok
55 Correct 25 ms 3912 KB ok
56 Correct 31 ms 3932 KB ok
57 Correct 20 ms 3664 KB ok
58 Correct 19 ms 3672 KB ok
59 Correct 19 ms 3928 KB ok
60 Correct 36 ms 3708 KB ok
61 Correct 26 ms 3932 KB ok
62 Correct 28 ms 3672 KB ok
63 Correct 28 ms 3928 KB ok
64 Correct 28 ms 3932 KB ok
65 Correct 822 ms 55376 KB ok
66 Correct 561 ms 55636 KB ok
67 Correct 436 ms 55428 KB ok
68 Correct 764 ms 55376 KB ok
69 Correct 849 ms 55980 KB ok
70 Correct 843 ms 55376 KB ok
71 Correct 747 ms 55308 KB ok
72 Correct 661 ms 55536 KB ok
73 Correct 568 ms 55632 KB ok
74 Correct 560 ms 55544 KB ok
75 Correct 564 ms 55632 KB ok
76 Correct 564 ms 55640 KB ok
77 Correct 596 ms 55432 KB ok
78 Correct 639 ms 55544 KB ok
79 Correct 400 ms 55512 KB ok
80 Correct 402 ms 55380 KB ok
81 Correct 419 ms 55380 KB ok
82 Correct 472 ms 55524 KB ok
83 Correct 466 ms 55576 KB ok
84 Correct 408 ms 55592 KB ok
85 Correct 370 ms 55304 KB ok
86 Correct 393 ms 55532 KB ok
87 Correct 403 ms 55312 KB ok
88 Correct 423 ms 55536 KB ok
89 Correct 579 ms 55764 KB ok
90 Correct 575 ms 55544 KB ok
91 Correct 619 ms 55724 KB ok
92 Correct 431 ms 55380 KB ok
93 Correct 439 ms 55632 KB ok
94 Correct 412 ms 55300 KB ok
95 Correct 420 ms 55508 KB ok
96 Correct 547 ms 55376 KB ok
97 Correct 410 ms 55380 KB ok
98 Correct 396 ms 55632 KB ok
99 Correct 702 ms 55696 KB ok
100 Correct 576 ms 55512 KB ok
101 Correct 585 ms 55608 KB ok
102 Correct 594 ms 55840 KB ok
103 Correct 597 ms 55432 KB ok
104 Correct 631 ms 55572 KB ok
105 Correct 633 ms 55552 KB ok
106 Correct 608 ms 55380 KB ok
107 Correct 642 ms 55512 KB ok
108 Correct 628 ms 55304 KB ok
109 Correct 687 ms 47764 KB ok