답안 #915544

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
915544 2024-01-24T06:53:32 Z vjudge1 Bomb (IZhO17_bomb) C++17
29 / 100
1000 ms 55564 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 <iostream>
#include <vector>
#define pb push_back
#define str string
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")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 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 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 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 17 ms 600 KB Output is correct
19 Correct 46 ms 860 KB Output is correct
20 Correct 54 ms 860 KB Output is correct
21 Correct 20 ms 600 KB Output is correct
22 Correct 52 ms 604 KB Output is correct
23 Correct 83 ms 856 KB Output is correct
24 Correct 31 ms 604 KB Output is correct
25 Correct 120 ms 1012 KB Output is correct
26 Execution timed out 1012 ms 892 KB Time limit exceeded
27 Execution timed out 1016 ms 1880 KB Time limit exceeded
28 Execution timed out 1025 ms 2136 KB Time limit exceeded
29 Execution timed out 1027 ms 2392 KB Time limit exceeded
30 Execution timed out 1050 ms 2904 KB Time limit exceeded
31 Execution timed out 1092 ms 2596 KB Time limit exceeded
32 Execution timed out 1054 ms 2652 KB Time limit exceeded
33 Execution timed out 1020 ms 3160 KB Time limit exceeded
34 Execution timed out 1051 ms 2136 KB Time limit exceeded
35 Execution timed out 1020 ms 3160 KB Time limit exceeded
36 Execution timed out 1065 ms 3164 KB Time limit exceeded
37 Correct 1 ms 348 KB Output is correct
38 Runtime error 38 ms 55124 KB Execution killed with signal 11
39 Correct 1 ms 348 KB Output is correct
40 Runtime error 7 ms 9564 KB Execution killed with signal 11
41 Correct 1 ms 348 KB Output is correct
42 Correct 211 ms 888 KB Output is correct
43 Runtime error 40 ms 55124 KB Execution killed with signal 11
44 Execution timed out 1046 ms 3164 KB Time limit exceeded
45 Runtime error 39 ms 55092 KB Execution killed with signal 11
46 Runtime error 42 ms 54940 KB Execution killed with signal 11
47 Runtime error 48 ms 54936 KB Execution killed with signal 11
48 Runtime error 40 ms 55128 KB Execution killed with signal 11
49 Runtime error 38 ms 55132 KB Execution killed with signal 11
50 Runtime error 39 ms 55056 KB Execution killed with signal 11
51 Runtime error 39 ms 55160 KB Execution killed with signal 11
52 Runtime error 39 ms 55120 KB Execution killed with signal 11
53 Runtime error 38 ms 54960 KB Execution killed with signal 11
54 Runtime error 39 ms 55132 KB Execution killed with signal 11
55 Runtime error 43 ms 55168 KB Execution killed with signal 11
56 Runtime error 40 ms 55120 KB Execution killed with signal 11
57 Runtime error 41 ms 54936 KB Execution killed with signal 11
58 Runtime error 40 ms 55120 KB Execution killed with signal 11
59 Runtime error 40 ms 55164 KB Execution killed with signal 11
60 Runtime error 39 ms 55124 KB Execution killed with signal 11
61 Runtime error 44 ms 55244 KB Execution killed with signal 11
62 Runtime error 40 ms 55176 KB Execution killed with signal 11
63 Runtime error 40 ms 55120 KB Execution killed with signal 11
64 Runtime error 39 ms 55124 KB Execution killed with signal 11
65 Runtime error 40 ms 54972 KB Execution killed with signal 11
66 Runtime error 40 ms 55136 KB Execution killed with signal 11
67 Runtime error 40 ms 54940 KB Execution killed with signal 11
68 Runtime error 39 ms 54996 KB Execution killed with signal 11
69 Runtime error 39 ms 55036 KB Execution killed with signal 11
70 Runtime error 27 ms 36580 KB Execution killed with signal 11
71 Runtime error 44 ms 55120 KB Execution killed with signal 11
72 Runtime error 42 ms 55564 KB Execution killed with signal 11
73 Runtime error 39 ms 55028 KB Execution killed with signal 11
74 Runtime error 40 ms 55124 KB Execution killed with signal 11
75 Runtime error 38 ms 55120 KB Execution killed with signal 11
76 Runtime error 40 ms 55144 KB Execution killed with signal 11
77 Runtime error 41 ms 55124 KB Execution killed with signal 11
78 Runtime error 42 ms 55128 KB Execution killed with signal 11
79 Runtime error 40 ms 55120 KB Execution killed with signal 11
80 Runtime error 40 ms 55288 KB Execution killed with signal 11
81 Runtime error 38 ms 55092 KB Execution killed with signal 11
82 Runtime error 42 ms 55128 KB Execution killed with signal 11
83 Runtime error 39 ms 55120 KB Execution killed with signal 11
84 Runtime error 40 ms 55124 KB Execution killed with signal 11
85 Runtime error 39 ms 55376 KB Execution killed with signal 11
86 Runtime error 46 ms 55120 KB Execution killed with signal 11
87 Runtime error 40 ms 55124 KB Execution killed with signal 11
88 Runtime error 48 ms 55088 KB Execution killed with signal 11
89 Runtime error 40 ms 55124 KB Execution killed with signal 11
90 Runtime error 31 ms 36700 KB Execution killed with signal 11
91 Runtime error 39 ms 55120 KB Execution killed with signal 11
92 Runtime error 38 ms 55004 KB Execution killed with signal 11
93 Runtime error 39 ms 55092 KB Execution killed with signal 11
94 Runtime error 40 ms 54984 KB Execution killed with signal 11
95 Runtime error 40 ms 54968 KB Execution killed with signal 11
96 Runtime error 39 ms 54944 KB Execution killed with signal 11
97 Runtime error 38 ms 55124 KB Execution killed with signal 11
98 Runtime error 39 ms 55120 KB Execution killed with signal 11
99 Runtime error 39 ms 55120 KB Execution killed with signal 11
100 Runtime error 39 ms 55152 KB Execution killed with signal 11