# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
118030 | 2019-06-17T18:08:21 Z | andremfq | Luxury burrow (IZhO13_burrow) | C++17 | 556 ms | 14088 KB |
//codigo do Ivan Carvalho //Busca Binaria no menor valor + Histograma no grid //N*N*log1000000000 = 3 * 10000000 que passa #include <bits/stdc++.h> using namespace std; const int MAXN = 1001; int matriz[MAXN][MAXN],vetor[MAXN],anterior[MAXN],posterior[MAXN],N,M,K; int solve(){ vetor[0] = -1; int ans = 0; stack<int> pilha; pilha.push(0); for(int i = 1;i<=N;i++){ while(vetor[i] < vetor[pilha.top()]){ posterior[pilha.top()] = i; pilha.pop(); } if(vetor[pilha.top()] == vetor[i]){ anterior[i] = anterior[pilha.top()]; } else{ anterior[i] = pilha.top(); } pilha.push(i); } while(!pilha.empty()){ posterior[pilha.top()] = N+1; pilha.pop(); } for(int i = 1;i<=N;i++){ anterior[i]++; posterior[i]--; ans = max(ans, vetor[i]*(posterior[i] - anterior[i] + 1) ); } return ans; } int func(int val){ int ans = 0; memset(vetor,0,sizeof(vetor)); for(int coluna = M;coluna>=1;coluna--){ for(int linha = 1;linha<=N;linha++){ int davez = (matriz[linha][coluna] >= val); if(davez == 0){ vetor[linha] = 0; } else{ vetor[linha]++; } } ans = max(ans, solve() ); } 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",&matriz[i][j]); } } int ini = 1,fim = (int)1e9, meio,resp = 0; while(ini <= fim){ meio = (ini+fim)/2; if(func(meio) >= K){ resp =meio; ini = meio + 1; } else{ fim = meio - 1; } } printf("%d %d\n",resp,func(resp)); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 512 KB | Output is correct |
6 | Correct | 3 ms | 556 KB | Output is correct |
7 | Correct | 3 ms | 384 KB | Output is correct |
8 | Correct | 6 ms | 768 KB | Output is correct |
9 | Correct | 9 ms | 1280 KB | Output is correct |
10 | Correct | 23 ms | 1408 KB | Output is correct |
11 | Correct | 33 ms | 1920 KB | Output is correct |
12 | Correct | 22 ms | 2432 KB | Output is correct |
13 | Correct | 29 ms | 1152 KB | Output is correct |
14 | Correct | 60 ms | 2424 KB | Output is correct |
15 | Correct | 64 ms | 2576 KB | Output is correct |
16 | Correct | 69 ms | 3048 KB | Output is correct |
17 | Correct | 84 ms | 2816 KB | Output is correct |
18 | Correct | 193 ms | 5624 KB | Output is correct |
19 | Correct | 222 ms | 4980 KB | Output is correct |
20 | Correct | 372 ms | 9080 KB | Output is correct |
21 | Correct | 406 ms | 10104 KB | Output is correct |
22 | Correct | 534 ms | 14088 KB | Output is correct |
23 | Correct | 556 ms | 14072 KB | Output is correct |
24 | Correct | 343 ms | 7036 KB | Output is correct |
25 | Correct | 414 ms | 7160 KB | Output is correct |