Submission #84652

# Submission time Handle Problem Language Result Execution time Memory
84652 2018-11-16T11:28:15 Z farukkastamonuda Luxury burrow (IZhO13_burrow) C++14
100 / 100
1107 ms 50768 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define lo long long 
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 1005
#define ii pair<int,int>
using namespace std;
int n,m,k,A[li][li],cur[li],ans,fa[li],sz[li];
vector<int> nxt[li];
int dsu(int x){
	if(fa[x]==x) return x;
	return fa[x]=dsu(fa[x]);
}
void union1(int a,int b){
	int s1=dsu(a);
	int s2=dsu(b);
	if(s1==s2) return ;
	if(sz[s1]<sz[s2]) swap(s1,s2);
	fa[s2]=s1;
	sz[s1]+=sz[s2];
	sz[s2]=0;
}
void solve(int ind){
	for(int i=0;i<=m;i++) nxt[i].clear();
	for(int i=1;i<=n;i++){
		nxt[cur[i]-ind].pb(i);
	}
	for(int i=1;i<=n;i++){
		fa[i]=-1;
		sz[i]=1;
	}
	for(int i=m;i>=1;i--){
		for(int j=0;j<(int)nxt[i].size();j++){
			int go=nxt[i][j];
			fa[go]=go;
			if(go>1 && fa[go-1]!=-1){
				union1(go,go-1);
			}
			if(go<n && fa[go+1]!=-1){
				union1(go,go+1);
			}
			ans=max(ans,i*sz[dsu(go)]);
		}
	}
}
int check(int x){
	ans=0;
	for(int i=1;i<=n;i++) cur[i]=m+1;
	for(int i=m;i>=1;i--){
		for(int j=1;j<=n;j++){
			if(A[j][i]<x) cur[j]=i;
		}
		solve(i);
	}
	return ans;
}
int main(){
	scanf("%d %d %d",&n,&m,&k);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			scanf("%d",&A[i][j]);
		}
	}
	int bas=1,son=inf;
	while(bas<=son){
		int mid=(bas+son)/2;
		if(check(mid)>=k) bas=mid+1;
		else son=mid-1;
	}
	printf("%d %d",son,check(son));
	return 0;
}

Compilation message

burrow.cpp: In function 'int main()':
burrow.cpp:62:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&m,&k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
burrow.cpp:65:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&A[i][j]);
    ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 608 KB Output is correct
5 Correct 3 ms 672 KB Output is correct
6 Correct 3 ms 696 KB Output is correct
7 Correct 5 ms 696 KB Output is correct
8 Correct 8 ms 980 KB Output is correct
9 Correct 13 ms 1668 KB Output is correct
10 Correct 25 ms 1852 KB Output is correct
11 Correct 69 ms 2820 KB Output is correct
12 Correct 28 ms 3948 KB Output is correct
13 Correct 40 ms 3948 KB Output is correct
14 Correct 98 ms 5172 KB Output is correct
15 Correct 103 ms 5380 KB Output is correct
16 Correct 126 ms 7132 KB Output is correct
17 Correct 96 ms 7220 KB Output is correct
18 Correct 370 ms 11384 KB Output is correct
19 Correct 346 ms 13172 KB Output is correct
20 Correct 784 ms 19140 KB Output is correct
21 Correct 770 ms 29052 KB Output is correct
22 Correct 1107 ms 39556 KB Output is correct
23 Correct 1056 ms 49232 KB Output is correct
24 Correct 486 ms 49232 KB Output is correct
25 Correct 431 ms 50768 KB Output is correct