Submission #842436

# Submission time Handle Problem Language Result Execution time Memory
842436 2023-09-02T21:44:36 Z firewater Soccer Stadium (IOI23_soccer) C++17
36 / 100
1856 ms 144308 KB
#include "soccer.h"
#include<bits/stdc++.h>
#define fs first
#define sn second
#define mp make_pair
#define MX 2023
using namespace std;
int n,now,ans,sl,sr,l,r,a[MX][MX],sum[MX][MX],stl[MX][20],str[MX][20],fl[MX][MX],fr[MX][MX];
pair<int,pair<int,int> >f[MX][MX];
vector<pair<int,int> >d[MX];
int getl(int l,int r)
{
    int k=__lg(r-l+1);
    return min(stl[l][k],stl[r-(1<<k)+1][k]);
}
int getr(int l,int r)
{
    int k=__lg(r-l+1);
    return min(str[l][k],str[r-(1<<k)+1][k]);
}
int biggest_stadium(int N, std::vector<std::vector<int>> F)
{
    n=N;

    for(int i=1;i<=n;++i)
        for(int j=1;j<=n;++j){
            a[i][j]=F[i-1][j-1];
            sum[i][j]=sum[i][j-1]+a[i][j];
        }
    for(int i=1;i<=n;++i){
        now=1;
        for(int j=1;j<=n;++j){
            if(a[i][j])now=j+1;
            else fl[i][j]=j-now+1;
        }
        now=n;
        for(int j=n;j>0;--j){
            if(a[i][j])now=j-1;
            else fr[i][j]=now-j+1;
        }
    }
    for(int j=1;j<=n;++j){
        for(int i=1;i<=n;++i){
            stl[i][0]=fl[i][j];
            str[i][0]=fr[i][j];
        }
        for(int k=1;k<=17;++k){
            for(int i=1;i<=n;++i){
                stl[i][k]=min(stl[i][k-1],(i+(1<<k-1)<=n?stl[i+(1<<k-1)][k-1]:n));
                str[i][k]=min(str[i][k-1],(i+(1<<k-1)<=n?str[i+(1<<k-1)][k-1]:n));
            }
        }
        for(int i=1;i<=n;++i)
            d[i].clear();
        for(int i=1;i<=n;++i){
            f[i][i]=mp(max(0,fl[i][j]+fr[i][j]-1),mp(fl[i][j],fr[i][j]));
            d[1].push_back(mp(i,i));
        }
        for(int len=1;len<=n;++len){
            int i,k;
            for(int g=0;g<d[len].size();++g){
                i=d[len][g].fs;k=d[len][g].sn;
                sl=f[i][k].sn.fs;
                sr=f[i][k].sn.sn;
                // printf("%d %d %d %d              (%d %d)\n",j,i,k,f[i][k].fs,sl,sr);
                if(sl+sr<1)continue;
                ans=max(ans,f[i][k].fs);
                
                if(i>1){
                    sl=min(f[i][k].sn.fs,fl[i-1][j]);
                    sr=min(f[i][k].sn.sn,fr[i-1][j]);
                    if(sl+sr<1)continue;
                    l=1;r=i-1;
                    while(l<r){
                        int mid=l+r>>1;
                        if(getl(mid,i-1)>=sl&&getr(mid,i-1)>=sr)r=mid;
                        else l=mid+1;
                    }
                    // printf("%d %d %d:%d ----->>>> %d %d:%d          (%d %d)\n",j,i,k,f[i][k].fs,l,k,f[i][k].fs+max(sr+sl-1,0)*(i-l),sl,sr);
                    f[l][k]=max(f[l][k],mp(f[i][k].fs+max(sr+sl-1,0)*(i-l),mp(sl,sr)));
                    d[k-l+1].push_back(mp(l,k));
                }
                if(k<n){
                    sl=min(f[i][k].sn.fs,fl[k+1][j]);
                    sr=min(f[i][k].sn.sn,fr[k+1][j]);
                    if(sl+sr<1)continue;
                    l=k+1;r=n;
                    while(l<r){
                        // printf("%d %d\n",l,r);
                        int mid=l+r+1>>1;
                        if(getl(k+1,mid)>=sl&&getr(k+1,mid)>=sr)l=mid;
                        else r=mid-1;
                    }
                    f[i][l]=max(f[i][l],mp(f[i][k].fs+max(sr+sl-1,0)*(l-k),mp(sl,sr)));
                    d[l-i+1].push_back(mp(i,l));
                }
                f[i][k]=mp(0,mp(0,0));
            }
            // for(int i=1;i<=n-len+1;++i){
            //     int k=i+len-1;
            //     ans=max(ans,f[i][k].fs);
            //     if(i>1){
            //         sl=min(f[i][k].sn.fs,fl[i-1][j]);
            //         sr=min(f[i][k].sn.sn,fr[i-1][j]);
            //         f[i-1][k]=max(f[i-1][k],mp(f[i][k].fs+max(sl+sr-1,0),mp(sl,sr)));
            //     }
            //     if(k<n){
            //         sl=min(f[i][k].sn.fs,fl[k+1][j]);
            //         sr=min(f[i][k].sn.sn,fr[k+1][j]);
            //         f[i][k+1]=max(f[i][k+1],mp(f[i][k].fs+max(sl+sr-1,0),mp(sl,sr)));
            //     }
            // }
        }
    }
    return ans;
}

Compilation message

soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:49:51: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   49 |                 stl[i][k]=min(stl[i][k-1],(i+(1<<k-1)<=n?stl[i+(1<<k-1)][k-1]:n));
      |                                                  ~^~
soccer.cpp:49:69: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   49 |                 stl[i][k]=min(stl[i][k-1],(i+(1<<k-1)<=n?stl[i+(1<<k-1)][k-1]:n));
      |                                                                    ~^~
soccer.cpp:50:51: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   50 |                 str[i][k]=min(str[i][k-1],(i+(1<<k-1)<=n?str[i+(1<<k-1)][k-1]:n));
      |                                                  ~^~
soccer.cpp:50:69: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   50 |                 str[i][k]=min(str[i][k-1],(i+(1<<k-1)<=n?str[i+(1<<k-1)][k-1]:n));
      |                                                                    ~^~
soccer.cpp:61:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |             for(int g=0;g<d[len].size();++g){
      |                         ~^~~~~~~~~~~~~~
soccer.cpp:75:34: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   75 |                         int mid=l+r>>1;
      |                                 ~^~
soccer.cpp:90:36: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   90 |                         int mid=l+r+1>>1;
      |                                 ~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB ok
2 Correct 2 ms 8540 KB ok
3 Correct 1 ms 10588 KB ok
4 Correct 2 ms 10588 KB ok
5 Correct 1 ms 8540 KB ok
6 Correct 1 ms 8540 KB ok
7 Correct 5 ms 15436 KB ok
8 Correct 107 ms 38236 KB ok
9 Correct 1856 ms 144308 KB ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB ok
2 Correct 2 ms 8540 KB ok
3 Correct 1 ms 8540 KB ok
4 Correct 1 ms 8720 KB ok
5 Correct 1 ms 8716 KB ok
6 Correct 1 ms 8540 KB ok
7 Correct 1 ms 8540 KB ok
8 Correct 1 ms 8540 KB ok
9 Correct 1 ms 8540 KB ok
10 Correct 1 ms 8540 KB ok
11 Correct 1 ms 8540 KB ok
12 Correct 1 ms 8536 KB ok
13 Correct 1 ms 8540 KB ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB ok
2 Correct 1 ms 8540 KB ok
3 Correct 2 ms 8540 KB ok
4 Correct 1 ms 8540 KB ok
5 Correct 1 ms 8720 KB ok
6 Correct 1 ms 8716 KB ok
7 Correct 1 ms 8540 KB ok
8 Correct 1 ms 8540 KB ok
9 Correct 1 ms 8540 KB ok
10 Correct 1 ms 8540 KB ok
11 Correct 1 ms 8540 KB ok
12 Correct 1 ms 8540 KB ok
13 Correct 1 ms 8536 KB ok
14 Correct 1 ms 8540 KB ok
15 Correct 1 ms 10584 KB ok
16 Correct 1 ms 10588 KB ok
17 Correct 1 ms 10588 KB ok
18 Correct 1 ms 10584 KB ok
19 Correct 1 ms 10588 KB ok
20 Correct 1 ms 10588 KB ok
21 Correct 1 ms 10588 KB ok
22 Correct 1 ms 10588 KB ok
23 Correct 1 ms 10588 KB ok
24 Correct 1 ms 10584 KB ok
25 Correct 1 ms 10588 KB ok
26 Correct 1 ms 10588 KB ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB ok
2 Correct 1 ms 8540 KB ok
3 Correct 2 ms 8540 KB ok
4 Correct 1 ms 10588 KB ok
5 Correct 2 ms 10588 KB ok
6 Correct 1 ms 8540 KB ok
7 Correct 1 ms 8720 KB ok
8 Correct 1 ms 8716 KB ok
9 Correct 1 ms 8540 KB ok
10 Correct 1 ms 8540 KB ok
11 Correct 1 ms 8540 KB ok
12 Correct 1 ms 8540 KB ok
13 Correct 1 ms 8540 KB ok
14 Correct 1 ms 8540 KB ok
15 Correct 1 ms 8536 KB ok
16 Correct 1 ms 8540 KB ok
17 Correct 1 ms 10584 KB ok
18 Correct 1 ms 10588 KB ok
19 Correct 1 ms 10588 KB ok
20 Correct 1 ms 10584 KB ok
21 Correct 1 ms 10588 KB ok
22 Correct 1 ms 10588 KB ok
23 Correct 1 ms 10588 KB ok
24 Correct 1 ms 10588 KB ok
25 Correct 1 ms 10588 KB ok
26 Correct 1 ms 10584 KB ok
27 Correct 1 ms 10588 KB ok
28 Correct 1 ms 10588 KB ok
29 Correct 1 ms 10588 KB ok
30 Partially correct 2 ms 12892 KB partial
31 Correct 2 ms 12892 KB ok
32 Correct 2 ms 12892 KB ok
33 Correct 2 ms 12892 KB ok
34 Correct 2 ms 12892 KB ok
35 Incorrect 2 ms 12892 KB wrong
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB ok
2 Correct 1 ms 8540 KB ok
3 Correct 2 ms 8540 KB ok
4 Correct 1 ms 10588 KB ok
5 Correct 2 ms 10588 KB ok
6 Correct 1 ms 8540 KB ok
7 Correct 1 ms 8720 KB ok
8 Correct 1 ms 8716 KB ok
9 Correct 1 ms 8540 KB ok
10 Correct 1 ms 8540 KB ok
11 Correct 1 ms 8540 KB ok
12 Correct 1 ms 8540 KB ok
13 Correct 1 ms 8540 KB ok
14 Correct 1 ms 8540 KB ok
15 Correct 1 ms 8536 KB ok
16 Correct 1 ms 8540 KB ok
17 Correct 1 ms 10584 KB ok
18 Correct 1 ms 10588 KB ok
19 Correct 1 ms 10588 KB ok
20 Correct 1 ms 10584 KB ok
21 Correct 1 ms 10588 KB ok
22 Correct 1 ms 10588 KB ok
23 Correct 1 ms 10588 KB ok
24 Correct 1 ms 10588 KB ok
25 Correct 1 ms 10588 KB ok
26 Correct 1 ms 10584 KB ok
27 Correct 1 ms 10588 KB ok
28 Correct 1 ms 10588 KB ok
29 Correct 1 ms 10588 KB ok
30 Partially correct 2 ms 12892 KB partial
31 Correct 2 ms 12892 KB ok
32 Correct 2 ms 12892 KB ok
33 Correct 2 ms 12892 KB ok
34 Correct 2 ms 12892 KB ok
35 Incorrect 2 ms 12892 KB wrong
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB ok
2 Correct 1 ms 8540 KB ok
3 Correct 2 ms 8540 KB ok
4 Correct 1 ms 10588 KB ok
5 Correct 2 ms 10588 KB ok
6 Correct 1 ms 8540 KB ok
7 Correct 1 ms 8540 KB ok
8 Correct 5 ms 15436 KB ok
9 Correct 107 ms 38236 KB ok
10 Correct 1856 ms 144308 KB ok
11 Correct 1 ms 8540 KB ok
12 Correct 1 ms 8720 KB ok
13 Correct 1 ms 8716 KB ok
14 Correct 1 ms 8540 KB ok
15 Correct 1 ms 8540 KB ok
16 Correct 1 ms 8540 KB ok
17 Correct 1 ms 8540 KB ok
18 Correct 1 ms 8540 KB ok
19 Correct 1 ms 8540 KB ok
20 Correct 1 ms 8536 KB ok
21 Correct 1 ms 8540 KB ok
22 Correct 1 ms 10584 KB ok
23 Correct 1 ms 10588 KB ok
24 Correct 1 ms 10588 KB ok
25 Correct 1 ms 10584 KB ok
26 Correct 1 ms 10588 KB ok
27 Correct 1 ms 10588 KB ok
28 Correct 1 ms 10588 KB ok
29 Correct 1 ms 10588 KB ok
30 Correct 1 ms 10588 KB ok
31 Correct 1 ms 10584 KB ok
32 Correct 1 ms 10588 KB ok
33 Correct 1 ms 10588 KB ok
34 Correct 1 ms 10588 KB ok
35 Partially correct 2 ms 12892 KB partial
36 Correct 2 ms 12892 KB ok
37 Correct 2 ms 12892 KB ok
38 Correct 2 ms 12892 KB ok
39 Correct 2 ms 12892 KB ok
40 Incorrect 2 ms 12892 KB wrong
41 Halted 0 ms 0 KB -