Submission #388284

#TimeUsernameProblemLanguageResultExecution timeMemory
388284patrikpavic2Bomb (IZhO17_bomb)C++17
70 / 100
635 ms90316 KiB
#include <cstdio> #include <algorithm> #include <vector> #include <cstring> #define PB push_back using namespace std; const int N = 2505; int n, m; char s[N][N]; int A[N][N], B[N][N]; int par[N], L[N], R[N], un[N], nula[N]; int S[N]; int pr(int x){ if(x == par[x]) return x; return par[x] = pr(par[x]); } void mrg(int x, int y){ if(x < 0 || y >= m || !un[x] || !un[y]) return; // printf("mrg %d %d\n", x, y); x = pr(x), y = pr(y); if(x == y) return; if(nula[x]) S[R[x] - L[x] + 1]--; if(nula[y]) S[R[y] - L[y] + 1]--; if(R[x] - L[x] > R[y] - L[y]){ par[y] = x; R[x] = R[y]; nula[x] |= nula[y]; if(nula[x]) S[R[x] - L[x] + 1]++; } else{ par[x] = y; L[y] = L[x]; nula[y] |= nula[x]; if(nula[y]) S[R[y] - L[y] + 1]++; } } vector < int > kon[N]; int ans[N]; void odradi_redak(int rd){ for(int i = 0;i <= m;i++) S[i] = 0; for(int i = 0;i <= n;i++) kon[i].clear(); for(int i = 0;i < m;i++){ un[i] = 0; if(s[rd][i] == '0') continue; par[i] = i; nula[i] = (B[rd][i] == 1); L[i] = i, R[i] = i; kon[A[rd][i]].PB(i); if(nula[i]) S[0]++; } if(!S[0]) return; int cur = 0; for(int i = n;i >= 1;i--){ for(int x : kon[i]){ if(nula[x]) S[0]--, S[1]++; // printf("x = %d nula = %d\n", x, nula[x]); un[x] = 1; mrg(x - 1, x); mrg(x, x + 1); } while(!S[cur]) cur++; //printf("rd = %d i = %d cur = %d\n", rd, i, cur); ans[i] = min(ans[i], cur); } } int main(){ //freopen("bomb.in", "r", stdin); //freopen("bomb.out", "w", stdout); scanf("%d%d", &n, &m); int fin = n * m; for(int i = 0;i < n;i++) for(int j = 0;j < m;j++) scanf(" %c", &s[i][j]); for(int bla = 0;bla < 2;bla++){ memset(A, 0, sizeof(A)); memset(B, 0, sizeof(B)); for(int i = 0;i < n;i++) for(int j = 0;j < m;j++) A[i][j] = (1 + (i ? A[i - 1][j] : 0)) * (s[i][j] - '0'); for(int i = n - 1;i >= 0;i--) for(int j = 0;j < m;j++) B[i][j] = (1 + B[i + 1][j]) * (s[i][j] - '0'); for(int i = 1;i <= n;i++) ans[i] = m; for(int i = 0;i < n;i++) odradi_redak(i); int sol = 1; for(int i = 1;i <= n;i++){ sol = max(sol, ans[i] * i); //printf("ans[ %d ] = %d\n", i, ans[i]); } fin = min(fin, sol); for(int i = 0;n - i - 1 > i;i++){ for(int j = 0;j < m;j++) swap(s[i][j], s[n - i - 1][j]); } } printf("%d\n", fin); return 0; } /* 5 6 000000 111110 111110 111110 001000 */

Compilation message (stderr)

bomb.cpp: In function 'int main()':
bomb.cpp:79:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   79 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
bomb.cpp:83:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   83 |    scanf(" %c", &s[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...