Submission #915541

# Submission time Handle Problem Language Result Execution time Memory
915541 2024-01-24T06:39:02 Z vjudge1 Bomb (IZhO17_bomb) C++17
29 / 100
1000 ms 55384 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define str string
#define pii pair<int,int>
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define mii map<int,int>
#define mll map<ll,ll>
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yess cout<<"Yes\n";
#define noo cout<<"No\n";
using namespace std;

int pp[501][501];
int u[501][501];

void solve(){
    int n,m;
    cin>>n>>m;
    if(n==1){
        str s;
        cin>>s;
        vector<int >v;
        int k=0;
        for(int i=0;i<m;i++){
            if(s[i]=='1')k++;
            else{
                if(k>0){
                    v.pb(k);
                    k=0;
                }
            }
        }
        if(k>0){
            v.pb(k);
        }
        int ans=1;
        if(v.size()==0){
            cout<<0;
            return;
        }
        for(int i=2;i<=m;i++){
            k=1;
            for(int j=0;j<(int)v.size();j++){
                if(v[j]<i){
                    k=0;
                    break;
                }
            }
            if(k==1){
                ans=i;
            }
        }
        cout<<ans;
    }
    else if(m==1){
        char s;
        vector<int >v;
        int k=0;
        for(int i=0;i<n;i++){
            cin>>s;
            if(s=='1')k++;
            else{
                if(k>0){
                    v.pb(k);
                    k=0;
                }
            }
        }
        if(k>0){
            v.pb(k);
        }
        int ans=1;
        if(v.size()==0){
            cout<<0;
            return;
        }
        for(int i=2;i<=n;i++){
            k=1;
            for(int j=0;j<(int)v.size();j++){
                if(v[j]<i){
                    k=0;
                    break;
                }
            }
            if(k==1){
                ans=i;
            }
        }
        cout<<ans;
    }
    else{
        str s[n+3];
        int a[n+3][m+3];
        int o=0;
        for(int i=1;i<=n;i++){
            cin>>s[i];
            for(int j=0;j<m;j++){
                a[i][j+1]=s[i][j]-'0';
                o+=(a[i][j]==1);
                pp[i][j+1]=a[i][j+1]+pp[i][j]+pp[i-1][j+1]-pp[i-1][j];
            }
        }
        if(o==0){
            cout<<0;
            return;
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(i*j<=ans){
                    continue;
                }
                for(int i1=1;i1<=n;i1++){
                    for(int j1=1;j1<=m;j1++){
                        u[i1][j1]=0;
                    }
                }
                for(int i1=1;i1<=n;i1++){
                    for(int j1=1;j1<=m;j1++){
                        if(i1+i-1>n || j1+j-1>m)continue;
                        if(pp[i1+i-1][j1+j-1]+pp[i1-1][j1-1]-pp[i1+i-1][j1-1]-pp[i1-1][j1+j-1]==i*j){
                            for(int i2=i1;i2<=i1+i-1;i2++){
                                for(int j2=j1;j2<=j1+j-1;j2++){
                                    u[i2][j2]=1;
                                }
                            }
                        }
                    }
                }
                int k=1;
                for(int i1=1;i1<=n;i1++){
                    for(int j1=1;j1<=m;j1++){
                        if(u[i1][j1]!=a[i1][j1]){
                            k=0;
                            break;
                        }
                    }
                }
                if(k==1){
                    /*cout<<i<<" "<<j<<"\n";
                    for(int i1=1;i1<=n;i1++){
                        for(int j1=1;j1<=m;j1++){
                            cout<<u[i1][j1];
                        }
                        cout<<"\n";
                    }//*/
                    ans=max(ans,i*j);
                }
            }
        }
        cout<<ans;
    }
}

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	//srand( time(0));
	//rand()
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
    int tests=1;
    //cin>>tests;
    for(int i=1;i<=tests;i++){
		//cout<<"TEST CASE : "<<i<<"\n";
		solve();
	}
}


Compilation message

bomb.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization("unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 16 ms 600 KB Output is correct
18 Correct 18 ms 604 KB Output is correct
19 Correct 54 ms 1112 KB Output is correct
20 Correct 51 ms 860 KB Output is correct
21 Correct 20 ms 604 KB Output is correct
22 Correct 52 ms 604 KB Output is correct
23 Correct 91 ms 860 KB Output is correct
24 Correct 39 ms 604 KB Output is correct
25 Correct 115 ms 892 KB Output is correct
26 Execution timed out 1035 ms 884 KB Time limit exceeded
27 Execution timed out 1031 ms 1884 KB Time limit exceeded
28 Execution timed out 1057 ms 2140 KB Time limit exceeded
29 Execution timed out 1016 ms 2392 KB Time limit exceeded
30 Execution timed out 1052 ms 2904 KB Time limit exceeded
31 Execution timed out 1049 ms 2392 KB Time limit exceeded
32 Execution timed out 1044 ms 2648 KB Time limit exceeded
33 Execution timed out 1022 ms 3160 KB Time limit exceeded
34 Execution timed out 1072 ms 2140 KB Time limit exceeded
35 Execution timed out 1008 ms 3160 KB Time limit exceeded
36 Execution timed out 1025 ms 3160 KB Time limit exceeded
37 Correct 1 ms 344 KB Output is correct
38 Runtime error 39 ms 55180 KB Execution killed with signal 11
39 Correct 1 ms 348 KB Output is correct
40 Runtime error 7 ms 9680 KB Execution killed with signal 11
41 Correct 1 ms 348 KB Output is correct
42 Correct 213 ms 888 KB Output is correct
43 Runtime error 40 ms 55116 KB Execution killed with signal 11
44 Execution timed out 1024 ms 3160 KB Time limit exceeded
45 Runtime error 40 ms 55132 KB Execution killed with signal 11
46 Runtime error 40 ms 55120 KB Execution killed with signal 11
47 Runtime error 40 ms 55164 KB Execution killed with signal 11
48 Runtime error 41 ms 55132 KB Execution killed with signal 11
49 Runtime error 48 ms 54968 KB Execution killed with signal 11
50 Runtime error 40 ms 55124 KB Execution killed with signal 11
51 Runtime error 41 ms 55124 KB Execution killed with signal 11
52 Runtime error 39 ms 55120 KB Execution killed with signal 11
53 Runtime error 39 ms 55124 KB Execution killed with signal 11
54 Runtime error 42 ms 55336 KB Execution killed with signal 11
55 Runtime error 41 ms 55168 KB Execution killed with signal 11
56 Runtime error 40 ms 55132 KB Execution killed with signal 11
57 Runtime error 42 ms 55120 KB Execution killed with signal 11
58 Runtime error 47 ms 54996 KB Execution killed with signal 11
59 Runtime error 41 ms 54964 KB Execution killed with signal 11
60 Runtime error 40 ms 55120 KB Execution killed with signal 11
61 Runtime error 38 ms 55124 KB Execution killed with signal 11
62 Runtime error 40 ms 55040 KB Execution killed with signal 11
63 Runtime error 44 ms 55092 KB Execution killed with signal 11
64 Runtime error 41 ms 55120 KB Execution killed with signal 11
65 Runtime error 47 ms 55084 KB Execution killed with signal 11
66 Runtime error 42 ms 55132 KB Execution killed with signal 11
67 Runtime error 40 ms 55124 KB Execution killed with signal 11
68 Runtime error 42 ms 54988 KB Execution killed with signal 11
69 Runtime error 40 ms 55124 KB Execution killed with signal 11
70 Runtime error 27 ms 36700 KB Execution killed with signal 11
71 Runtime error 42 ms 55132 KB Execution killed with signal 11
72 Runtime error 45 ms 54992 KB Execution killed with signal 11
73 Runtime error 49 ms 55160 KB Execution killed with signal 11
74 Runtime error 42 ms 55132 KB Execution killed with signal 11
75 Runtime error 40 ms 55120 KB Execution killed with signal 11
76 Runtime error 39 ms 55120 KB Execution killed with signal 11
77 Runtime error 39 ms 55124 KB Execution killed with signal 11
78 Runtime error 40 ms 55008 KB Execution killed with signal 11
79 Runtime error 40 ms 55000 KB Execution killed with signal 11
80 Runtime error 50 ms 55384 KB Execution killed with signal 11
81 Runtime error 44 ms 55088 KB Execution killed with signal 11
82 Runtime error 40 ms 55136 KB Execution killed with signal 11
83 Runtime error 43 ms 55120 KB Execution killed with signal 11
84 Runtime error 40 ms 55132 KB Execution killed with signal 11
85 Runtime error 41 ms 55124 KB Execution killed with signal 11
86 Runtime error 42 ms 55120 KB Execution killed with signal 11
87 Runtime error 40 ms 55120 KB Execution killed with signal 11
88 Runtime error 39 ms 55120 KB Execution killed with signal 11
89 Runtime error 44 ms 55124 KB Execution killed with signal 11
90 Runtime error 27 ms 36696 KB Execution killed with signal 11
91 Runtime error 38 ms 55132 KB Execution killed with signal 11
92 Runtime error 40 ms 55160 KB Execution killed with signal 11
93 Runtime error 47 ms 55124 KB Execution killed with signal 11
94 Runtime error 42 ms 55132 KB Execution killed with signal 11
95 Runtime error 41 ms 55004 KB Execution killed with signal 11
96 Runtime error 41 ms 55040 KB Execution killed with signal 11
97 Runtime error 43 ms 55064 KB Execution killed with signal 11
98 Runtime error 48 ms 55056 KB Execution killed with signal 11
99 Runtime error 43 ms 55120 KB Execution killed with signal 11
100 Runtime error 40 ms 55040 KB Execution killed with signal 11