답안 #1118849

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1118849 2024-11-26T09:29:37 Z Younis_Dwai Bomb (IZhO17_bomb) C++14
44 / 100
1000 ms 12696 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define endl "\n"
#define F first
#define S second
#define pb push_back
//#define int long long
#define in insert
//#define mid (l+r)/2
#define in insert
using namespace std;
const int N=2505;
char b[N][N];
int n,m,pref[505][505],d[505][505];
void init(){
     for(int i=1;i<=n;i++){
         for(int j=1;j<=m;j++){
             pref[i][j]=pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1]+bool(b[i][j]=='1');
         }
     }
     return ;
}
int query(int x , int y , int x1 , int y1){
    return pref[x1][y1]-pref[x1][y-1]-pref[x-1][y1]+pref[x-1][y-1];
}
int Query(int x , int y , int x1 , int y1){
    return d[x1][y1]-d[x1][y-1]-d[x-1][y1]+d[x-1][y-1];
}
bool ok(int h  , int w){
     for(int i=1;i<=n;i++){
         for(int j=1;j<=m;j++){
             d[i][j]=0;
         }
     }
     for(int i=1;i+h-1<=n;i++){
         for(int j=1;j+w-1<=m;j++){
             if(query(i,j,i+h-1,j+w-1)==h*w){
                d[i][j]=1;
             }
         }
     }
     for(int i=1;i<=n;i++){
         for(int j=1;j<=m;j++){
             d[i][j]=d[i-1][j]+d[i][j-1]-d[i-1][j-1]+d[i][j];
         }
     }
     bool can=1;
     for(int i=1;i<=n;i++){
         for(int j=1;j<=m;j++){
             if(b[i][j]=='1'){
                int i1=max(1,i-h+1),j1=max(1,j-w+1);
                if(Query(i1,j1,i,j)==0) can=0;
             }
         }
     }
     return can;
}
int32_t main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>b[i][j];
        }
    }
    if(n<=500 && m<=500 && n!=1 && m!=1){
       int mx=0;
       init();
       for(int i=1;i<=n;i++){
           int l=1,r=n,mid=(l+r+1)/2;
           while(l<r){
                 if(ok(i,mid)) l=mid;
                 else r=mid-1;
                 mid=(l+r+1)/2;
           }
           if(ok(i,mid)) mx=max(mx,i*mid);
       }
       cout<<mx;
    }
    else{
        int h=n,w=m;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(b[i][j]=='1'){
                   int cnt=1;
                   while(j+1<=m && b[i][j+1]=='1'){
                         ++cnt;
                         ++j;
                   }
                   w=min(w,cnt);
                }
            }
        }
        for(int j=1;j<=m;j++){
            for(int i=1;i<=n;i++){
                if(b[i][j]=='1'){
                   int cnt=1;
                   while(i+1<=n && b[i+1][j]=='1'){
                         ++i;
                         ++cnt;
                   }
                   h=min(h,cnt);
                }
            }
        }
        cout<<h*w;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 472 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 5 ms 6656 KB Output is correct
4 Correct 5 ms 6480 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 2 ms 336 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 8 ms 732 KB Output is correct
18 Correct 6 ms 848 KB Output is correct
19 Correct 10 ms 848 KB Output is correct
20 Correct 14 ms 848 KB Output is correct
21 Correct 4 ms 592 KB Output is correct
22 Correct 8 ms 880 KB Output is correct
23 Correct 15 ms 1104 KB Output is correct
24 Correct 7 ms 848 KB Output is correct
25 Correct 16 ms 1104 KB Output is correct
26 Correct 25 ms 1132 KB Output is correct
27 Correct 714 ms 2436 KB Output is correct
28 Correct 645 ms 2384 KB Output is correct
29 Execution timed out 1056 ms 2896 KB Time limit exceeded
30 Execution timed out 1052 ms 3328 KB Time limit exceeded
31 Correct 989 ms 2756 KB Output is correct
32 Execution timed out 1025 ms 3152 KB Time limit exceeded
33 Execution timed out 1027 ms 3408 KB Time limit exceeded
34 Correct 535 ms 2836 KB Output is correct
35 Execution timed out 1047 ms 3492 KB Time limit exceeded
36 Execution timed out 1056 ms 3496 KB Time limit exceeded
37 Correct 1 ms 592 KB Output is correct
38 Correct 91 ms 12548 KB Output is correct
39 Correct 2 ms 592 KB Output is correct
40 Incorrect 11 ms 3152 KB Output isn't correct
41 Correct 2 ms 592 KB Output is correct
42 Correct 20 ms 1104 KB Output is correct
43 Correct 96 ms 12496 KB Output is correct
44 Execution timed out 1039 ms 3408 KB Time limit exceeded
45 Incorrect 93 ms 12496 KB Output isn't correct
46 Correct 83 ms 12468 KB Output is correct
47 Incorrect 98 ms 12568 KB Output isn't correct
48 Incorrect 83 ms 12616 KB Output isn't correct
49 Correct 91 ms 12564 KB Output is correct
50 Incorrect 114 ms 12524 KB Output isn't correct
51 Incorrect 101 ms 12476 KB Output isn't correct
52 Incorrect 76 ms 12608 KB Output isn't correct
53 Incorrect 106 ms 12616 KB Output isn't correct
54 Incorrect 93 ms 12548 KB Output isn't correct
55 Incorrect 88 ms 12616 KB Output isn't correct
56 Correct 72 ms 12616 KB Output is correct
57 Incorrect 78 ms 12604 KB Output isn't correct
58 Incorrect 91 ms 12512 KB Output isn't correct
59 Incorrect 71 ms 12616 KB Output isn't correct
60 Correct 81 ms 12616 KB Output is correct
61 Correct 72 ms 12520 KB Output is correct
62 Correct 92 ms 12624 KB Output is correct
63 Correct 77 ms 12584 KB Output is correct
64 Correct 80 ms 12616 KB Output is correct
65 Incorrect 96 ms 12516 KB Output isn't correct
66 Incorrect 77 ms 12616 KB Output isn't correct
67 Incorrect 75 ms 12556 KB Output isn't correct
68 Incorrect 81 ms 12628 KB Output isn't correct
69 Incorrect 89 ms 12468 KB Output isn't correct
70 Incorrect 88 ms 9136 KB Output isn't correct
71 Incorrect 142 ms 12616 KB Output isn't correct
72 Incorrect 92 ms 12616 KB Output isn't correct
73 Incorrect 82 ms 12544 KB Output isn't correct
74 Incorrect 104 ms 12616 KB Output isn't correct
75 Incorrect 79 ms 12524 KB Output isn't correct
76 Incorrect 63 ms 12620 KB Output isn't correct
77 Incorrect 71 ms 12564 KB Output isn't correct
78 Incorrect 94 ms 12696 KB Output isn't correct
79 Incorrect 80 ms 12520 KB Output isn't correct
80 Incorrect 91 ms 12616 KB Output isn't correct
81 Incorrect 69 ms 12616 KB Output isn't correct
82 Incorrect 67 ms 12620 KB Output isn't correct
83 Incorrect 70 ms 12568 KB Output isn't correct
84 Incorrect 70 ms 12620 KB Output isn't correct
85 Incorrect 62 ms 12616 KB Output isn't correct
86 Incorrect 84 ms 12480 KB Output isn't correct
87 Incorrect 82 ms 12516 KB Output isn't correct
88 Incorrect 88 ms 12584 KB Output isn't correct
89 Incorrect 86 ms 12616 KB Output isn't correct
90 Incorrect 57 ms 9028 KB Output isn't correct
91 Incorrect 76 ms 12616 KB Output isn't correct
92 Incorrect 71 ms 12616 KB Output isn't correct
93 Incorrect 86 ms 12472 KB Output isn't correct
94 Incorrect 134 ms 12616 KB Output isn't correct
95 Incorrect 78 ms 12584 KB Output isn't correct
96 Incorrect 72 ms 12500 KB Output isn't correct
97 Incorrect 90 ms 12568 KB Output isn't correct
98 Incorrect 68 ms 12544 KB Output isn't correct
99 Incorrect 77 ms 12520 KB Output isn't correct
100 Incorrect 70 ms 12596 KB Output isn't correct