답안 #1010534

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010534 2024-06-29T07:53:26 Z ttamx 축구 경기장 (IOI23_soccer) C++17
100 / 100
518 ms 175188 KB
#include "soccer.h"
#include <bits/stdc++.h>
#define cerr if(0)cerr

using namespace std;

const int N=2005;

int n;
int a[N][N];
int top[N][N],bot[N][N],pre[N][N][2],dp[N][N];
vector<pair<int,int>> rect[N];
int ans;

int biggest_stadium(int _n,vector<vector<int>> _a){
    n=_n;
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)a[i][j]=_a[i-1][j-1]^1;
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)top[i][j]=a[i][j]?a[i-1][j]?top[i-1][j]:i:top[i-1][j];
    for(int i=1;i<=n;i++)bot[n+1][i]=n+1;
    for(int i=n;i>=1;i--)for(int j=1;j<=n;j++)bot[i][j]=a[i][j]?a[i+1][j]?bot[i+1][j]:i:bot[i+1][j];
    for(int i=1;i<=n;i++){
        int t=0,b=n+1;
        for(int j=1;j<=n;j++){
            for(int x=0;x<2;x++)pre[i][j][x]=a[i][j]==x?j:pre[i][j-1][x];
            if(a[i][j]){
                if(a[i][j-1]){
                    top[i][j]=max(top[i][j],top[i][j-1]);
                    bot[i][j]=min(bot[i][j],bot[i][j-1]);
                }
                rect[j-pre[i][j][0]].emplace_back(i,j);
            }
        }
    }
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cerr << bot[i][j] << " \n"[j==n];
    cerr << "\n";
    for(int w=n;w>=1;w--)for(auto [i,j]:rect[w]){
        int l=pre[i][j][0]+1,r=j,t=top[i][j],b=bot[i][j];
        int lw=l>1?bot[i][l-1]+1:i+1;
        cerr << "(" << i << ", " << j << ") ";
        cerr << l << " " << r << " " << t << " " << b << " : " << lw << "\n";
        if(lw<=b){
            cerr << "SKIP TO " << lw << " " << j << "\n";
            dp[lw][j]=max(dp[lw][j],dp[i][j]);
            continue;
        }
        if(a[i][j+1]&&top[i][j+1]<=t&&bot[i][j+1]>=b)continue;
        int h=b-t+1;
        int res=w*h+dp[i][j];
        cerr << w*h << " + " << dp[i][j] << " = " << res << "\n";
        ans=max(ans,res);
        if(t>1){
            for(int nr=pre[t-1][r][1],nl;nr>=l;nr=pre[t-1][nl][1]){
                nl=max(l-1,pre[t-1][nr][0]);
                int p=nl>=l?t-1:i;
                dp[p][nr]=max(dp[p][nr],res-(nr-nl)*h);
            }
        }
        if(b<n){
            for(int nr=pre[b+1][r][1],nl;nr>=l;nr=pre[b+1][nl][1]){
                nl=max(l-1,pre[b+1][nr][0]);
                int p=nl>=l?b+1:i;
                dp[p][nr]=max(dp[p][nr],res-(nr-nl)*h);
            }
        }
    }
    return ans;
}

Compilation message

soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:22:13: warning: unused variable 't' [-Wunused-variable]
   22 |         int t=0,b=n+1;
      |             ^
soccer.cpp:22:17: warning: unused variable 'b' [-Wunused-variable]
   22 |         int t=0,b=n+1;
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB ok
2 Correct 0 ms 348 KB ok
3 Correct 0 ms 604 KB ok
4 Correct 1 ms 604 KB ok
5 Correct 0 ms 348 KB ok
6 Correct 0 ms 500 KB ok
7 Correct 2 ms 2908 KB ok
8 Correct 25 ms 20904 KB ok
9 Correct 355 ms 165956 KB ok
# 결과 실행 시간 메모리 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 1 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 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 1 ms 344 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB ok
2 Correct 1 ms 344 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 0 ms 348 KB ok
9 Correct 1 ms 348 KB ok
10 Correct 0 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 1 ms 344 KB ok
15 Correct 0 ms 604 KB ok
16 Correct 1 ms 600 KB ok
17 Correct 0 ms 604 KB ok
18 Correct 1 ms 604 KB ok
19 Correct 0 ms 604 KB ok
20 Correct 1 ms 604 KB ok
21 Correct 1 ms 604 KB ok
22 Correct 1 ms 604 KB ok
23 Correct 1 ms 604 KB ok
24 Correct 1 ms 600 KB ok
25 Correct 1 ms 604 KB ok
26 Correct 1 ms 604 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB ok
2 Correct 1 ms 344 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 0 ms 604 KB ok
5 Correct 1 ms 604 KB ok
6 Correct 0 ms 348 KB ok
7 Correct 1 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 1 ms 348 KB ok
12 Correct 0 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 1 ms 344 KB ok
17 Correct 0 ms 604 KB ok
18 Correct 1 ms 600 KB ok
19 Correct 0 ms 604 KB ok
20 Correct 1 ms 604 KB ok
21 Correct 0 ms 604 KB ok
22 Correct 1 ms 604 KB ok
23 Correct 1 ms 604 KB ok
24 Correct 1 ms 604 KB ok
25 Correct 1 ms 604 KB ok
26 Correct 1 ms 600 KB ok
27 Correct 1 ms 604 KB ok
28 Correct 1 ms 604 KB ok
29 Correct 1 ms 600 KB ok
30 Correct 1 ms 1116 KB ok
31 Correct 1 ms 1116 KB ok
32 Correct 1 ms 1116 KB ok
33 Correct 0 ms 1004 KB ok
34 Correct 1 ms 860 KB ok
35 Correct 1 ms 860 KB ok
36 Correct 0 ms 860 KB ok
37 Correct 1 ms 860 KB ok
38 Correct 1 ms 860 KB ok
39 Correct 1 ms 904 KB ok
40 Correct 1 ms 1116 KB ok
41 Correct 1 ms 1116 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB ok
2 Correct 1 ms 344 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 0 ms 604 KB ok
5 Correct 1 ms 604 KB ok
6 Correct 0 ms 348 KB ok
7 Correct 1 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 1 ms 348 KB ok
12 Correct 0 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 1 ms 344 KB ok
17 Correct 0 ms 604 KB ok
18 Correct 1 ms 600 KB ok
19 Correct 0 ms 604 KB ok
20 Correct 1 ms 604 KB ok
21 Correct 0 ms 604 KB ok
22 Correct 1 ms 604 KB ok
23 Correct 1 ms 604 KB ok
24 Correct 1 ms 604 KB ok
25 Correct 1 ms 604 KB ok
26 Correct 1 ms 600 KB ok
27 Correct 1 ms 604 KB ok
28 Correct 1 ms 604 KB ok
29 Correct 1 ms 600 KB ok
30 Correct 1 ms 1116 KB ok
31 Correct 1 ms 1116 KB ok
32 Correct 1 ms 1116 KB ok
33 Correct 0 ms 1004 KB ok
34 Correct 1 ms 860 KB ok
35 Correct 1 ms 860 KB ok
36 Correct 0 ms 860 KB ok
37 Correct 1 ms 860 KB ok
38 Correct 1 ms 860 KB ok
39 Correct 1 ms 904 KB ok
40 Correct 1 ms 1116 KB ok
41 Correct 1 ms 1116 KB ok
42 Correct 26 ms 20944 KB ok
43 Correct 30 ms 20672 KB ok
44 Correct 31 ms 21332 KB ok
45 Correct 25 ms 21328 KB ok
46 Correct 41 ms 21120 KB ok
47 Correct 29 ms 20980 KB ok
48 Correct 25 ms 18516 KB ok
49 Correct 34 ms 18516 KB ok
50 Correct 22 ms 18776 KB ok
51 Correct 26 ms 21208 KB ok
52 Correct 35 ms 17244 KB ok
53 Correct 19 ms 16324 KB ok
54 Correct 20 ms 17244 KB ok
55 Correct 35 ms 17760 KB ok
56 Correct 20 ms 18264 KB ok
57 Correct 37 ms 21436 KB ok
58 Correct 26 ms 21556 KB ok
59 Correct 25 ms 21596 KB ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB ok
2 Correct 1 ms 344 KB ok
3 Correct 0 ms 348 KB ok
4 Correct 0 ms 604 KB ok
5 Correct 1 ms 604 KB ok
6 Correct 0 ms 348 KB ok
7 Correct 0 ms 500 KB ok
8 Correct 2 ms 2908 KB ok
9 Correct 25 ms 20904 KB ok
10 Correct 355 ms 165956 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 1 ms 348 KB ok
15 Correct 0 ms 348 KB ok
16 Correct 1 ms 348 KB ok
17 Correct 0 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 1 ms 344 KB ok
22 Correct 0 ms 604 KB ok
23 Correct 1 ms 600 KB ok
24 Correct 0 ms 604 KB ok
25 Correct 1 ms 604 KB ok
26 Correct 0 ms 604 KB ok
27 Correct 1 ms 604 KB ok
28 Correct 1 ms 604 KB ok
29 Correct 1 ms 604 KB ok
30 Correct 1 ms 604 KB ok
31 Correct 1 ms 600 KB ok
32 Correct 1 ms 604 KB ok
33 Correct 1 ms 604 KB ok
34 Correct 1 ms 600 KB ok
35 Correct 1 ms 1116 KB ok
36 Correct 1 ms 1116 KB ok
37 Correct 1 ms 1116 KB ok
38 Correct 0 ms 1004 KB ok
39 Correct 1 ms 860 KB ok
40 Correct 1 ms 860 KB ok
41 Correct 0 ms 860 KB ok
42 Correct 1 ms 860 KB ok
43 Correct 1 ms 860 KB ok
44 Correct 1 ms 904 KB ok
45 Correct 1 ms 1116 KB ok
46 Correct 1 ms 1116 KB ok
47 Correct 26 ms 20944 KB ok
48 Correct 30 ms 20672 KB ok
49 Correct 31 ms 21332 KB ok
50 Correct 25 ms 21328 KB ok
51 Correct 41 ms 21120 KB ok
52 Correct 29 ms 20980 KB ok
53 Correct 25 ms 18516 KB ok
54 Correct 34 ms 18516 KB ok
55 Correct 22 ms 18776 KB ok
56 Correct 26 ms 21208 KB ok
57 Correct 35 ms 17244 KB ok
58 Correct 19 ms 16324 KB ok
59 Correct 20 ms 17244 KB ok
60 Correct 35 ms 17760 KB ok
61 Correct 20 ms 18264 KB ok
62 Correct 37 ms 21436 KB ok
63 Correct 26 ms 21556 KB ok
64 Correct 25 ms 21596 KB ok
65 Correct 518 ms 166228 KB ok
66 Correct 342 ms 144552 KB ok
67 Correct 296 ms 136768 KB ok
68 Correct 448 ms 174416 KB ok
69 Correct 448 ms 169016 KB ok
70 Correct 485 ms 168732 KB ok
71 Correct 377 ms 173632 KB ok
72 Correct 358 ms 165972 KB ok
73 Correct 348 ms 146492 KB ok
74 Correct 338 ms 147024 KB ok
75 Correct 345 ms 146124 KB ok
76 Correct 346 ms 154060 KB ok
77 Correct 354 ms 154188 KB ok
78 Correct 391 ms 171948 KB ok
79 Correct 277 ms 135876 KB ok
80 Correct 272 ms 135872 KB ok
81 Correct 342 ms 137920 KB ok
82 Correct 334 ms 142944 KB ok
83 Correct 394 ms 141188 KB ok
84 Correct 271 ms 125524 KB ok
85 Correct 246 ms 122432 KB ok
86 Correct 247 ms 128080 KB ok
87 Correct 245 ms 128848 KB ok
88 Correct 286 ms 140116 KB ok
89 Correct 341 ms 153024 KB ok
90 Correct 313 ms 145232 KB ok
91 Correct 346 ms 154960 KB ok
92 Correct 276 ms 138036 KB ok
93 Correct 304 ms 138176 KB ok
94 Correct 328 ms 136756 KB ok
95 Correct 231 ms 136252 KB ok
96 Correct 267 ms 135628 KB ok
97 Correct 248 ms 134996 KB ok
98 Correct 236 ms 127304 KB ok
99 Correct 383 ms 166872 KB ok
100 Correct 369 ms 173800 KB ok
101 Correct 367 ms 173900 KB ok
102 Correct 354 ms 173904 KB ok
103 Correct 363 ms 173908 KB ok
104 Correct 396 ms 175168 KB ok
105 Correct 352 ms 174928 KB ok
106 Correct 368 ms 174280 KB ok
107 Correct 380 ms 175188 KB ok
108 Correct 317 ms 164832 KB ok
109 Correct 288 ms 165896 KB ok