Submission #100577

#TimeUsernameProblemLanguageResultExecution timeMemory
100577alexpetrescuBomb (IZhO17_bomb)C++14
100 / 100
541 ms60280 KiB
#include <cstdio> #include <algorithm> //FILE *fin = fopen("a.in", "r"), *fout = fopen("a.out", "w"); #define fin stdin #define fout stdout #define MAXN 2500 int left[MAXN + 2][MAXN + 2], right[MAXN + 2][MAXN + 2]; int d[MAXN + 2]; char m[MAXN + 2][MAXN + 10]; int nrlin, nrcol; inline void solve() { for (int i = 1; i <= nrlin; i++) { left[i][0] = 0; for (int j = 1; j <= nrcol; j++) if (m[i][j] == '1') left[i][j] = left[i][j - 1]; else left[i][j] = j; right[i][nrcol + 1] = nrcol + 1; for (int j = nrcol; j > 0; j--) if (m[i][j] == '1') right[i][j] = right[i][j + 1]; else right[i][j] = j; for (int j = 1; j <= nrcol; j++) if (m[i][j] == '1') d[1] = std::min(d[1], right[i][j] - left[i][j] - 1); } for (int j = 1; j <= nrcol; j++) { int st = 0, dr = nrcol + 1, cat = 0; for (int i = 1; i <= nrlin; i++) { if (m[i][j] == '1') { st = std::max(st, left[i][j]); dr = std::min(dr, right[i][j]); cat++; d[cat] = std::min(d[cat], dr - st - 1); } else { if (cat) d[cat + 1] = 0; st = 0, dr = nrcol + 1; cat = 0; } } if (cat) d[cat + 1] = 0; } } int main() { fscanf(fin, "%d%d ", &nrlin, &nrcol); for (int i = 1; i <= nrlin; i++) fgets(m[i] + 1, MAXN + 5, fin), d[i] = nrcol; solve(); for (int i = 1; i <= nrlin / 2; i++) for (int j = 1; j <= nrcol; j++) std::swap(m[i][j], m[nrlin - i + 1][j]); solve(); for (int i = 2; i <= nrlin; i++) d[i] = std::min(d[i], d[i - 1]); int ans = d[1]; for (int i = 2; i <= nrlin; i++) ans = std::max(ans, i * d[i]); fprintf(fout, "%d\n", ans); fclose(fin); fclose(fout); return 0; }

Compilation message (stderr)

bomb.cpp: In function 'int main()':
bomb.cpp:56:11: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin, "%d%d ", &nrlin, &nrcol);
     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bomb.cpp:59:39: warning: ignoring return value of 'char* fgets(char*, int, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         fgets(m[i] + 1, MAXN + 5, fin), d[i] = nrcol;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...