Submission #980240

# Submission time Handle Problem Language Result Execution time Memory
980240 2024-05-12T01:32:46 Z vjudge1 Soccer Stadium (IOI23_soccer) C++17
35.5 / 100
347 ms 40016 KB
    #include "soccer.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define deb(x) cout<<#x<<": "<<x<<endl;
int biggest_stadium(int N, vector<vector<int>> F)
{
    if(N>3){
int numoftree=0;
 for(int i=0; i<N; ++i){
    for(int j=0; j<N; ++j){
        if(F[i][j]==1){
            numoftree++;
        }
    }
 }
if(numoftree<=1){
 for(int i=0; i<N; ++i){
    for(int j=0; j<N; ++j){
        if(F[i][j]==1){
            int ans=min((i+1)*(j+1), (N-i)*(j+1));
            ans=min(ans, (i+1)*(N-j));
            ans=min(ans, (N-i)*(N-j));
            ans=N*N-ans;
            return ans;
        }
    }
 }
 return N*N;
    }
    else{

        bool jala=true;
        for(int i=0; i<N && jala; ++i){
            int notree=0;
            int tree=0;
            for(int j=0; j<N && jala; ++j){
                if(F[i][j]==1){
                  if(notree>0) tree++;
                }
                else{
                    if(notree>0 && tree>0){
                        jala=false;
                    }
                    notree++;
                }
            }
        }
         for(int i=0; i<N && jala; ++i){
            int notree=0;
            int tree=0;
            for(int j=0; j<N && jala; ++j){
                if(F[j][i]==1){
                   if(notree>0) tree++;
                }
                else{
                    if(notree>0 && tree>0){
                        jala=false;
                    }
                    notree++;
                }
            }
        }

        queue<pair<int,int>> q;
        for(int i=0; i<N && q.empty(); ++i){
            for(int j=0; j<N && q.empty(); ++j){
                if(F[i][j]==0){
                    q.push({i,j});
                }
            }
        }
        while(!q.empty()){
            int a=q.front().first;
            int b=q.front().second;
            q.pop();
            if(F[a][b]==2) continue;
            F[a][b]=2;
            if(b-1>=0 && F[a][b-1]==0){
                F[a][b-1]=-1;
                q.push({a, b-1});
            }
            if(a-1>=0 && F[a-1][b]==0){
                F[a-1][b]=-1;
                q.push({a-1, b});
            }
            if(b+1<N && F[a][b+1]==0){
                F[a][b+1]=-1;
                q.push({a, b+1});
            }
            if(a+1<N && F[a+1][b]==0){
                F[a+1][b]=-1;
                q.push({a+1, b});
            }
            
        }
        for(int i=0; i<N && jala; ++i){
            for(int j=0; j<N && jala; ++j){
                if(F[i][j]==0){
                    jala=false;
                }
            }
        }

        if(jala){

            vector<pair<int,int>> ranges;
            for(int i=0; i<N; ++i){
                int l=-1;
                int r=-1;
                for(int j=0; j<N; ++j){
                    if(F[i][j]==2){
                        if(l==-1){
                            l=j;
                        }
                        r=j;
                    }
                }
                if(l!=-1){
                    ranges.pb({l,r});
                }
            }
            for(int i=0; i<ranges.size() && jala; ++i){
                for(int j=i+1; j<ranges.size() && jala; ++j){
                    if(ranges[i].first >= ranges[j].first && ranges[i].first <=ranges[j].second){
                        //uwu
                    }
                    else{
                        if(ranges[i].first <=ranges[j].first && ranges[j].second <= ranges[i].second){
                            //uwu
                        }
                        else{
                            jala=false;
                        }
                    }
                    if(ranges[i].second >= ranges[j].first && ranges[i].second <=ranges[j].second){
                        //uwu
                    }
                    else{
                        if(ranges[i].first <=ranges[j].first && ranges[j].second <= ranges[i].second){
                            //uwu
                        }
                        else{
                            jala=false;
                        }
                    }
                }
            }
            if(jala){
            return N*N-numoftree;
            }
            return N*N-numoftree+1;
        }
        else{
            return N*N-numoftree+1;
        }
    }
    }
    int ans=0;
    int ayuda=N*N;
    int mevoyamorir=pow(2, ayuda);
    
    for(int mask=0;mask < mevoyamorir; ++mask){
        vector<vector<int>> grid (N, vector<int> (N, 0));
        for(int i=0; i<N; ++i){
            for(int j=0; j<N; ++j){
                if(F[i][j]==1){
                    grid[i][j]=-1;
                }
            }
        }
        int aux=mask;
    	int col=0;
        int fil=0;
        vector<pair<int,int>> coord;
        while(aux>0){
            if(aux%2){
                if(grid[fil][col]==-1){
                    break;
                }
                grid[fil][col]=1;
                coord.pb({fil, col});
            }
            col++;
            if(col>=N){
                fil++;
                col=0;
            }
            aux/=2;
        }
        if(aux>0){
            continue;
        }
        bool posib=true;

        for(int i=0; i<coord.size(); ++i){
            for(int j=i+1; j<coord.size(); ++j){
                if(grid[coord[i].first][coord[j].second]==1 || grid[coord[j].first][coord[i].second]==1){
                    if(coord[i].first==coord[j].first){
                        int a=coord[i].second;
                        int b=coord[j].second;
                        if(a>b) swap(a,b);
                        for(int x=a; x<=b; ++x){
                            if(grid[coord[i].first][x]!=1){
                                posib=false;
                                break;
                            }
                        } 
                        if(!posib) break;
                    }
                    if(coord[i].second==coord[j].second){
                        int a=coord[i].first;
                        int b=coord[j].first;
                        if(a>b) swap(a,b);
                        for(int x=a; x<=b; ++x){
                            if(grid[x][coord[i].second]!=1){
                                posib=false;
                                break;
                            }
                        } 
                        if(!posib) break;
                    }
                }
                else{
                    posib=false;
                    break;
                }
            }
            if(!posib) break;
        }
        if(posib){

            ans=max(ans,(int) coord.size());
        }

    }
    return ans;
}

Compilation message

soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:123:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |             for(int i=0; i<ranges.size() && jala; ++i){
      |                          ~^~~~~~~~~~~~~~
soccer.cpp:124:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  124 |                 for(int j=i+1; j<ranges.size() && jala; ++j){
      |                                ~^~~~~~~~~~~~~~
soccer.cpp:196:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  196 |         for(int i=0; i<coord.size(); ++i){
      |                      ~^~~~~~~~~~~~~
soccer.cpp:197:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  197 |             for(int j=i+1; j<coord.size(); ++j){
      |                            ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 348 KB partial
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB ok
2 Correct 1 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 1 ms 348 KB ok
8 Correct 16 ms 2392 KB ok
9 Correct 266 ms 31724 KB ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB ok
2 Correct 1 ms 348 KB ok
3 Correct 1 ms 348 KB ok
4 Correct 1 ms 344 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 1 ms 344 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
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 348 KB partial
2 Correct 0 ms 348 KB ok
3 Correct 1 ms 348 KB ok
4 Correct 1 ms 348 KB ok
5 Correct 1 ms 344 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 344 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 0 ms 348 KB ok
15 Partially correct 0 ms 348 KB partial
16 Partially correct 1 ms 348 KB partial
17 Partially correct 1 ms 348 KB partial
18 Partially correct 0 ms 348 KB partial
19 Partially correct 1 ms 348 KB partial
20 Correct 0 ms 348 KB ok
21 Correct 1 ms 348 KB ok
22 Partially correct 0 ms 348 KB partial
23 Partially correct 0 ms 348 KB partial
24 Partially correct 1 ms 348 KB partial
25 Partially correct 0 ms 348 KB partial
26 Partially correct 0 ms 344 KB partial
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 348 KB partial
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 1 ms 348 KB ok
7 Correct 1 ms 344 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 1 ms 344 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 0 ms 348 KB ok
17 Partially correct 0 ms 348 KB partial
18 Partially correct 1 ms 348 KB partial
19 Partially correct 1 ms 348 KB partial
20 Partially correct 0 ms 348 KB partial
21 Partially correct 1 ms 348 KB partial
22 Correct 0 ms 348 KB ok
23 Correct 1 ms 348 KB ok
24 Partially correct 0 ms 348 KB partial
25 Partially correct 0 ms 348 KB partial
26 Partially correct 1 ms 348 KB partial
27 Partially correct 0 ms 348 KB partial
28 Partially correct 0 ms 344 KB partial
29 Partially correct 1 ms 348 KB partial
30 Partially correct 0 ms 348 KB partial
31 Partially correct 1 ms 348 KB partial
32 Partially correct 0 ms 348 KB partial
33 Partially correct 1 ms 348 KB partial
34 Correct 0 ms 348 KB ok
35 Correct 0 ms 348 KB ok
36 Partially correct 0 ms 348 KB partial
37 Partially correct 1 ms 344 KB partial
38 Partially correct 0 ms 348 KB partial
39 Partially correct 0 ms 348 KB partial
40 Partially correct 0 ms 348 KB partial
41 Partially correct 0 ms 348 KB partial
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 348 KB partial
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 1 ms 348 KB ok
7 Correct 1 ms 344 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 1 ms 344 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 0 ms 348 KB ok
17 Partially correct 0 ms 348 KB partial
18 Partially correct 1 ms 348 KB partial
19 Partially correct 1 ms 348 KB partial
20 Partially correct 0 ms 348 KB partial
21 Partially correct 1 ms 348 KB partial
22 Correct 0 ms 348 KB ok
23 Correct 1 ms 348 KB ok
24 Partially correct 0 ms 348 KB partial
25 Partially correct 0 ms 348 KB partial
26 Partially correct 1 ms 348 KB partial
27 Partially correct 0 ms 348 KB partial
28 Partially correct 0 ms 344 KB partial
29 Partially correct 1 ms 348 KB partial
30 Partially correct 0 ms 348 KB partial
31 Partially correct 1 ms 348 KB partial
32 Partially correct 0 ms 348 KB partial
33 Partially correct 1 ms 348 KB partial
34 Correct 0 ms 348 KB ok
35 Correct 0 ms 348 KB ok
36 Partially correct 0 ms 348 KB partial
37 Partially correct 1 ms 344 KB partial
38 Partially correct 0 ms 348 KB partial
39 Partially correct 0 ms 348 KB partial
40 Partially correct 0 ms 348 KB partial
41 Partially correct 0 ms 348 KB partial
42 Partially correct 21 ms 2908 KB partial
43 Partially correct 19 ms 2896 KB partial
44 Partially correct 19 ms 2684 KB partial
45 Partially correct 22 ms 2908 KB partial
46 Partially correct 19 ms 2644 KB partial
47 Partially correct 18 ms 2908 KB partial
48 Correct 19 ms 2908 KB ok
49 Partially correct 18 ms 2904 KB partial
50 Partially correct 18 ms 2924 KB partial
51 Partially correct 16 ms 2908 KB partial
52 Partially correct 19 ms 2696 KB partial
53 Partially correct 18 ms 2908 KB partial
54 Partially correct 17 ms 2820 KB partial
55 Partially correct 18 ms 2908 KB partial
56 Partially correct 17 ms 2904 KB partial
57 Partially correct 18 ms 2908 KB partial
58 Partially correct 17 ms 2904 KB partial
59 Partially correct 18 ms 2908 KB partial
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 348 KB partial
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 1 ms 348 KB ok
8 Correct 1 ms 348 KB ok
9 Correct 16 ms 2392 KB ok
10 Correct 266 ms 31724 KB ok
11 Correct 1 ms 348 KB ok
12 Correct 1 ms 344 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 1 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 Partially correct 0 ms 348 KB partial
23 Partially correct 1 ms 348 KB partial
24 Partially correct 1 ms 348 KB partial
25 Partially correct 0 ms 348 KB partial
26 Partially correct 1 ms 348 KB partial
27 Correct 0 ms 348 KB ok
28 Correct 1 ms 348 KB ok
29 Partially correct 0 ms 348 KB partial
30 Partially correct 0 ms 348 KB partial
31 Partially correct 1 ms 348 KB partial
32 Partially correct 0 ms 348 KB partial
33 Partially correct 0 ms 344 KB partial
34 Partially correct 1 ms 348 KB partial
35 Partially correct 0 ms 348 KB partial
36 Partially correct 1 ms 348 KB partial
37 Partially correct 0 ms 348 KB partial
38 Partially correct 1 ms 348 KB partial
39 Correct 0 ms 348 KB ok
40 Correct 0 ms 348 KB ok
41 Partially correct 0 ms 348 KB partial
42 Partially correct 1 ms 344 KB partial
43 Partially correct 0 ms 348 KB partial
44 Partially correct 0 ms 348 KB partial
45 Partially correct 0 ms 348 KB partial
46 Partially correct 0 ms 348 KB partial
47 Partially correct 21 ms 2908 KB partial
48 Partially correct 19 ms 2896 KB partial
49 Partially correct 19 ms 2684 KB partial
50 Partially correct 22 ms 2908 KB partial
51 Partially correct 19 ms 2644 KB partial
52 Partially correct 18 ms 2908 KB partial
53 Correct 19 ms 2908 KB ok
54 Partially correct 18 ms 2904 KB partial
55 Partially correct 18 ms 2924 KB partial
56 Partially correct 16 ms 2908 KB partial
57 Partially correct 19 ms 2696 KB partial
58 Partially correct 18 ms 2908 KB partial
59 Partially correct 17 ms 2820 KB partial
60 Partially correct 18 ms 2908 KB partial
61 Partially correct 17 ms 2904 KB partial
62 Partially correct 18 ms 2908 KB partial
63 Partially correct 17 ms 2904 KB partial
64 Partially correct 18 ms 2908 KB partial
65 Partially correct 309 ms 39684 KB partial
66 Partially correct 258 ms 39504 KB partial
67 Partially correct 251 ms 39720 KB partial
68 Partially correct 297 ms 39584 KB partial
69 Partially correct 301 ms 39760 KB partial
70 Partially correct 295 ms 39508 KB partial
71 Partially correct 295 ms 39704 KB partial
72 Partially correct 294 ms 39696 KB partial
73 Correct 305 ms 36000 KB ok
74 Correct 347 ms 39736 KB ok
75 Partially correct 277 ms 39508 KB partial
76 Partially correct 293 ms 39632 KB partial
77 Partially correct 298 ms 39808 KB partial
78 Partially correct 257 ms 39508 KB partial
79 Partially correct 251 ms 39464 KB partial
80 Partially correct 250 ms 39760 KB partial
81 Partially correct 237 ms 39504 KB partial
82 Partially correct 223 ms 39628 KB partial
83 Partially correct 249 ms 39504 KB partial
84 Partially correct 282 ms 40016 KB partial
85 Partially correct 283 ms 39680 KB partial
86 Partially correct 292 ms 39588 KB partial
87 Partially correct 283 ms 39504 KB partial
88 Partially correct 291 ms 39560 KB partial
89 Partially correct 304 ms 39700 KB partial
90 Partially correct 284 ms 39508 KB partial
91 Partially correct 295 ms 39940 KB partial
92 Partially correct 251 ms 39568 KB partial
93 Partially correct 259 ms 39816 KB partial
94 Partially correct 230 ms 39504 KB partial
95 Partially correct 250 ms 39508 KB partial
96 Partially correct 251 ms 39812 KB partial
97 Partially correct 259 ms 39556 KB partial
98 Partially correct 256 ms 39560 KB partial
99 Partially correct 258 ms 39556 KB partial
100 Partially correct 314 ms 39508 KB partial
101 Partially correct 255 ms 39512 KB partial
102 Partially correct 270 ms 39508 KB partial
103 Partially correct 287 ms 39764 KB partial
104 Partially correct 274 ms 39504 KB partial
105 Partially correct 253 ms 39504 KB partial
106 Partially correct 292 ms 39560 KB partial
107 Partially correct 269 ms 39560 KB partial
108 Partially correct 251 ms 39440 KB partial
109 Partially correct 252 ms 31828 KB partial