답안 #167417

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167417 2019-12-08T10:41:19 Z GioChkhaidze Bomb (IZhO17_bomb) C++14
44 / 100
644 ms 42360 KB
#include <bits/stdc++.h>
#define Tree int h,int l,int r
#define Left 2*h,l,(l+r)/2
#define Right 2*h+1,(l+r)/2+1,r
#define F first
#define S second
using namespace std;
const int N=2505;
int n,m,width=1e9,length=1e9,last,D[N][N];
bool f[N][N];
string s[N],S;
vector < pair < int , pair < int , int > > > v;
inline bool check(int x,int y) {
	for (int i=0; i<n; i++) 
		for (int j=0; j<m; j++)
			if (s[i][j]=='1') f[i][j]=1;
					     else f[i][j]=0;
						 								     
	for (int i=0; i<n; i++)
		for (int j=0; j<m; j++) 
			if (s[i][j]=='1')
				if (i+x-1<n && j+y-1<m) {
					if (D[i+x][j+y]-D[i][j+y]-D[i+x][j]+D[i][j]!=0 && !f[i][j]) continue;
					if (D[i+x][j+y]-D[i][j+y]-D[i+x][j]+D[i][j]!=0) return 0;
					for (int k1=i; k1<i+x; k1++)
						for (int k2=j; k2<j+y; k2++)
							f[k1][k2]=0;
				}
	
	return 1;
}
 
main () {
	scanf("%d%d",&n,&m);
	getline(cin,S);
	for (int i=0; i<n; i++)  
		getline(cin,s[i]);
	
	for (int i=0; i<n; i++)
		for (int j=0; j<m; j++) 
			D[i+1][j+1]=D[i][j+1]+D[i+1][j]-D[i][j]+(s[i][j]=='0');
	
	for (int i=0; i<n; i++) {
		last=m;
		for (int j=m-1; j>=0; j--) {
			if (s[i][j]=='0' && last-1!=j) 
				if (width>last-j-1) width=last-j-1;
			if (s[i][j]=='0') last=j;
		}
		
		if (last) 
			if (last<width) width=last;
	}
	
	for (int j=0; j<m; j++) {
		last=n;
		for (int i=n-1; i>=0; i--) {
			if (s[i][j]=='0' && last-1!=i) 
				if (length>last-i-1) length=last-i-1;
			if (s[i][j]=='0') last=i;
		}
		
		if (last)
			if (last<length) length=last;
	}
	
	if (width==1e9 || length==1e9) { cout<<0<<endl; return 0; }
 
 	if (1LL*n*m*length*width>=3e8) {
 		cout<<length*width<<endl;
 		return 0;
	}
 
	for (int i=1; i<=length; i++)
		for (int j=1; j<=width; j++)
			v.push_back({i*j,{i,j}});
			
	sort(v.begin(),v.end());
	
	for (int i=v.size()-1; i>=0; i--) {
		if (check(v[i].S.F,v[i].S.S)) {
			cout<<v[i].F<<endl;
			return 0;
		}
	}
}

Compilation message

bomb.cpp:33:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
bomb.cpp: In function 'int main()':
bomb.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 20 ms 16504 KB Output is correct
4 Correct 20 ms 16504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 508 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 3 ms 888 KB Output is correct
18 Correct 3 ms 888 KB Output is correct
19 Correct 6 ms 1124 KB Output is correct
20 Correct 7 ms 1016 KB Output is correct
21 Correct 3 ms 760 KB Output is correct
22 Correct 3 ms 892 KB Output is correct
23 Correct 11 ms 1144 KB Output is correct
24 Correct 7 ms 1016 KB Output is correct
25 Correct 63 ms 1144 KB Output is correct
26 Correct 5 ms 1144 KB Output is correct
27 Correct 10 ms 2808 KB Output is correct
28 Correct 14 ms 2936 KB Output is correct
29 Incorrect 12 ms 2796 KB Output isn't correct
30 Incorrect 17 ms 3288 KB Output isn't correct
31 Incorrect 14 ms 2680 KB Output isn't correct
32 Incorrect 15 ms 3064 KB Output isn't correct
33 Incorrect 19 ms 3448 KB Output isn't correct
34 Correct 12 ms 3192 KB Output is correct
35 Incorrect 18 ms 3320 KB Output isn't correct
36 Correct 219 ms 4648 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 431 ms 35188 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Incorrect 56 ms 8568 KB Output isn't correct
41 Correct 2 ms 504 KB Output is correct
42 Correct 342 ms 1236 KB Output is correct
43 Correct 429 ms 36132 KB Output is correct
44 Incorrect 18 ms 3448 KB Output isn't correct
45 Incorrect 432 ms 36284 KB Output isn't correct
46 Correct 432 ms 36388 KB Output is correct
47 Incorrect 426 ms 36232 KB Output isn't correct
48 Incorrect 426 ms 36220 KB Output isn't correct
49 Correct 644 ms 42360 KB Output is correct
50 Incorrect 428 ms 36344 KB Output isn't correct
51 Incorrect 429 ms 36200 KB Output isn't correct
52 Incorrect 445 ms 36296 KB Output isn't correct
53 Incorrect 432 ms 36176 KB Output isn't correct
54 Incorrect 431 ms 36120 KB Output isn't correct
55 Incorrect 435 ms 36064 KB Output isn't correct
56 Correct 432 ms 36128 KB Output is correct
57 Incorrect 430 ms 35824 KB Output isn't correct
58 Incorrect 430 ms 35912 KB Output isn't correct
59 Incorrect 445 ms 35992 KB Output isn't correct
60 Correct 490 ms 36304 KB Output is correct
61 Correct 476 ms 36088 KB Output is correct
62 Correct 429 ms 36216 KB Output is correct
63 Correct 423 ms 36272 KB Output is correct
64 Correct 446 ms 36216 KB Output is correct
65 Incorrect 425 ms 35840 KB Output isn't correct
66 Incorrect 432 ms 35896 KB Output isn't correct
67 Incorrect 441 ms 36020 KB Output isn't correct
68 Incorrect 450 ms 35980 KB Output isn't correct
69 Incorrect 437 ms 36068 KB Output isn't correct
70 Incorrect 278 ms 29048 KB Output isn't correct
71 Incorrect 518 ms 36344 KB Output isn't correct
72 Incorrect 430 ms 35860 KB Output isn't correct
73 Incorrect 434 ms 36056 KB Output isn't correct
74 Incorrect 430 ms 35908 KB Output isn't correct
75 Incorrect 436 ms 36020 KB Output isn't correct
76 Incorrect 486 ms 35960 KB Output isn't correct
77 Incorrect 436 ms 35956 KB Output isn't correct
78 Incorrect 533 ms 36000 KB Output isn't correct
79 Incorrect 432 ms 36220 KB Output isn't correct
80 Incorrect 433 ms 36404 KB Output isn't correct
81 Incorrect 430 ms 36392 KB Output isn't correct
82 Incorrect 433 ms 36208 KB Output isn't correct
83 Incorrect 442 ms 36216 KB Output isn't correct
84 Incorrect 434 ms 36396 KB Output isn't correct
85 Incorrect 426 ms 36472 KB Output isn't correct
86 Incorrect 423 ms 36396 KB Output isn't correct
87 Incorrect 428 ms 36712 KB Output isn't correct
88 Incorrect 431 ms 36124 KB Output isn't correct
89 Incorrect 425 ms 36496 KB Output isn't correct
90 Incorrect 326 ms 29308 KB Output isn't correct
91 Incorrect 431 ms 36808 KB Output isn't correct
92 Incorrect 429 ms 37368 KB Output isn't correct
93 Incorrect 431 ms 37088 KB Output isn't correct
94 Incorrect 432 ms 36996 KB Output isn't correct
95 Incorrect 429 ms 36260 KB Output isn't correct
96 Incorrect 428 ms 36280 KB Output isn't correct
97 Incorrect 482 ms 36800 KB Output isn't correct
98 Incorrect 431 ms 36152 KB Output isn't correct
99 Incorrect 429 ms 36856 KB Output isn't correct
100 Incorrect 424 ms 36856 KB Output isn't correct