fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(){
  5. int n, k, i, j, sl, stack[100][2], m, max, nn;
  6. char map[1000][1000], str[1000];
  7.  
  8. scanf("%d", &n);
  9.  
  10. gets(str);
  11.  
  12. for(k=0; k<n; k++){
  13. gets(str);
  14. i = 0;
  15. gets(map[i]);
  16. sl = strlen(map[i]);
  17. i++;
  18. while(i!=sl){
  19. gets(map[i]);
  20. i++;
  21. }
  22.  
  23. for( i=0; i<sl; i++){
  24. for( j=0; j<sl; j++){
  25. map[j][i]-='0';
  26. if(j && map[j][i])map[j][i]=map[j-1][i]+1;
  27. }
  28. }
  29.  
  30. stack[0][0]=0;
  31. stack[0][1]=0;
  32. m = 0;
  33. max = 0;
  34. for( i=sl-1; i>=0; i--){
  35. for( j=0; j<sl; j++){
  36. nn = -1;
  37. while(map[i][j]<stack[m][1]){
  38. if((j-stack[m][0])*stack[m][1]>max) max = (j-stack[m][0])*stack[m][1];
  39. if(nn<0) nn = stack[m][0];
  40. else if( nn>stack[m][0]) nn = stack[m][0];
  41. m--;
  42. }
  43. if(map[i][j]>stack[m][1]){
  44. m++;
  45. stack[m][1]=map[i][j];
  46. if(nn<0)stack[m][0]=j;
  47. else stack[m][0] = nn;
  48. }
  49. }
  50. while(m){
  51. if((sl-stack[m][0])*stack[m][1]>max) max = (sl-stack[m][0])*stack[m][1];
  52. m--;
  53. }
  54. }
  55. if(k)printf("\n");
  56. printf("%d\n", max);
  57. }
  58.  
  59. return 0;
  60. }
  61.  
stdin
3

10111000
00010100
00111000
00111010
00111111
01011110
01011110
00011110

0000000000
0111111110
0100000010
0101111010
0101001010
0101001010
0101111010
0100000010
0111111110
0000000000

00
01
compilation info
prog.c: In function ‘main’:
prog.c:8: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
prog.c:10: warning: ignoring return value of ‘gets’, declared with attribute warn_unused_result
prog.c:13: warning: ignoring return value of ‘gets’, declared with attribute warn_unused_result
prog.c:15: warning: ignoring return value of ‘gets’, declared with attribute warn_unused_result
prog.c:19: warning: ignoring return value of ‘gets’, declared with attribute warn_unused_result
In function ‘gets’,
    inlined from ‘main’ at prog.c:19:
/usr/include/bits/stdio2.h:230: warning: call to ‘__gets_warn’ declared with attribute warning: please use fgets or getline instead, gets can't specify buffer size
/home/avR0LJ/ccppBOOj.o: In function `main':
prog.c:(.text+0xbe): warning: the `gets' function is dangerous and should not be used.
prog.c:(.text+0x3f): warning: the `gets' function is dangerous and should not be used.
stdout
16

8

1