답안 #915535

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
915535 2024-01-24T06:31:47 Z vjudge1 Bomb (IZhO17_bomb) C++17
29 / 100
1000 ms 56584 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();
	}
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 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 460 KB Output is correct
12 Correct 0 ms 464 KB Output is correct
13 Correct 1 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 27 ms 604 KB Output is correct
18 Correct 24 ms 604 KB Output is correct
19 Correct 69 ms 860 KB Output is correct
20 Correct 75 ms 856 KB Output is correct
21 Correct 29 ms 600 KB Output is correct
22 Correct 63 ms 600 KB Output is correct
23 Correct 130 ms 908 KB Output is correct
24 Correct 46 ms 804 KB Output is correct
25 Correct 189 ms 912 KB Output is correct
26 Execution timed out 1035 ms 856 KB Time limit exceeded
27 Execution timed out 1069 ms 1884 KB Time limit exceeded
28 Execution timed out 1046 ms 2140 KB Time limit exceeded
29 Execution timed out 1062 ms 2652 KB Time limit exceeded
30 Execution timed out 1053 ms 3164 KB Time limit exceeded
31 Execution timed out 1047 ms 2648 KB Time limit exceeded
32 Execution timed out 1051 ms 2904 KB Time limit exceeded
33 Execution timed out 1039 ms 3420 KB Time limit exceeded
34 Execution timed out 1032 ms 2140 KB Time limit exceeded
35 Execution timed out 1049 ms 3420 KB Time limit exceeded
36 Execution timed out 1027 ms 3420 KB Time limit exceeded
37 Correct 1 ms 348 KB Output is correct
38 Runtime error 46 ms 56148 KB Execution killed with signal 11
39 Correct 1 ms 348 KB Output is correct
40 Runtime error 10 ms 10332 KB Execution killed with signal 11
41 Correct 1 ms 348 KB Output is correct
42 Correct 698 ms 904 KB Output is correct
43 Runtime error 47 ms 56320 KB Execution killed with signal 11
44 Execution timed out 1073 ms 3420 KB Time limit exceeded
45 Runtime error 52 ms 55928 KB Execution killed with signal 11
46 Runtime error 47 ms 56228 KB Execution killed with signal 11
47 Runtime error 45 ms 56144 KB Execution killed with signal 11
48 Runtime error 49 ms 56148 KB Execution killed with signal 11
49 Runtime error 47 ms 56036 KB Execution killed with signal 11
50 Runtime error 46 ms 56072 KB Execution killed with signal 11
51 Runtime error 46 ms 56152 KB Execution killed with signal 11
52 Runtime error 57 ms 56404 KB Execution killed with signal 11
53 Runtime error 50 ms 56260 KB Execution killed with signal 11
54 Runtime error 47 ms 56240 KB Execution killed with signal 11
55 Runtime error 47 ms 56180 KB Execution killed with signal 11
56 Runtime error 52 ms 56076 KB Execution killed with signal 11
57 Runtime error 47 ms 56140 KB Execution killed with signal 11
58 Runtime error 46 ms 56556 KB Execution killed with signal 11
59 Runtime error 47 ms 55940 KB Execution killed with signal 11
60 Runtime error 52 ms 56144 KB Execution killed with signal 11
61 Runtime error 45 ms 55376 KB Execution killed with signal 11
62 Runtime error 48 ms 56088 KB Execution killed with signal 11
63 Runtime error 44 ms 56088 KB Execution killed with signal 11
64 Runtime error 44 ms 55520 KB Execution killed with signal 11
65 Runtime error 50 ms 55892 KB Execution killed with signal 11
66 Runtime error 45 ms 56404 KB Execution killed with signal 11
67 Runtime error 46 ms 55744 KB Execution killed with signal 11
68 Runtime error 55 ms 55888 KB Execution killed with signal 11
69 Runtime error 45 ms 56144 KB Execution killed with signal 11
70 Runtime error 30 ms 37456 KB Execution killed with signal 11
71 Runtime error 49 ms 56584 KB Execution killed with signal 11
72 Runtime error 51 ms 55920 KB Execution killed with signal 11
73 Runtime error 56 ms 56404 KB Execution killed with signal 11
74 Runtime error 46 ms 56144 KB Execution killed with signal 11
75 Runtime error 45 ms 56304 KB Execution killed with signal 11
76 Runtime error 45 ms 56144 KB Execution killed with signal 11
77 Runtime error 47 ms 56556 KB Execution killed with signal 11
78 Runtime error 45 ms 56148 KB Execution killed with signal 11
79 Runtime error 46 ms 55892 KB Execution killed with signal 11
80 Runtime error 49 ms 56112 KB Execution killed with signal 11
81 Runtime error 46 ms 56144 KB Execution killed with signal 11
82 Runtime error 46 ms 56148 KB Execution killed with signal 11
83 Runtime error 46 ms 55380 KB Execution killed with signal 11
84 Runtime error 45 ms 55892 KB Execution killed with signal 11
85 Runtime error 56 ms 55892 KB Execution killed with signal 11
86 Runtime error 49 ms 56152 KB Execution killed with signal 11
87 Runtime error 46 ms 55896 KB Execution killed with signal 11
88 Runtime error 54 ms 56140 KB Execution killed with signal 11
89 Runtime error 45 ms 56400 KB Execution killed with signal 11
90 Runtime error 32 ms 37396 KB Execution killed with signal 11
91 Runtime error 44 ms 55888 KB Execution killed with signal 11
92 Runtime error 45 ms 56144 KB Execution killed with signal 11
93 Runtime error 55 ms 56144 KB Execution killed with signal 11
94 Runtime error 46 ms 55888 KB Execution killed with signal 11
95 Runtime error 48 ms 56160 KB Execution killed with signal 11
96 Runtime error 45 ms 55624 KB Execution killed with signal 11
97 Runtime error 44 ms 55700 KB Execution killed with signal 11
98 Runtime error 46 ms 55892 KB Execution killed with signal 11
99 Runtime error 44 ms 56028 KB Execution killed with signal 11
100 Runtime error 57 ms 55632 KB Execution killed with signal 11