{"id":1136,"date":"2015-06-29T03:44:50","date_gmt":"2015-06-28T19:44:50","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=1136"},"modified":"2015-10-28T04:03:51","modified_gmt":"2015-10-27T20:03:51","slug":"poj-3494-largest-submatrix-of-all-1s","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/poj-3494-largest-submatrix-of-all-1s\/","title":{"rendered":"POJ 3494. Largest Submatrix of All 1\u2019s"},"content":{"rendered":"<p><!--more--><br \/>\nhttp:\/\/poj.org\/problem?id=3494<br \/>\nhttp:\/\/zhuanlan.zhihu.com\/qinchao\/19873823<\/p>\n<p>\u505a\u6cd5\u4e00\uff1a\u5355\u8c03\u6808<br \/>\nhttp:\/\/poj.org\/problem?id=2559<br \/>\nhttps:\/\/www.shuizilong.com\/house\/archives\/ad-infinitum-math-programming-contest-september14<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\/\/}\/* .................................................................................................................................. *\/\r\n\r\nconst int N = int(2e3) + 9;\r\n\r\nint A&#x5B;N]&#x5B;N], h&#x5B;N], l&#x5B;N], r&#x5B;N];\r\nint n, m;\r\n\r\nint main(){\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n        \/\/freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n\r\n    while (~scanf(&quot;%d %d&quot;, &amp;n, &amp;m)){\r\n        REP_2_1(i, j, n, m) RD(A&#x5B;i]&#x5B;j]);\r\n\r\n        int z = 0; h&#x5B;0] = 0, h&#x5B;m+1] = 0; REP_1(i, n){\r\n            REP_1(j, m) h&#x5B;j] = (A&#x5B;i]&#x5B;j] == 1 ? h&#x5B;j] + 1 : 0);\r\n\r\n            stack&lt;int&gt; s; s.push(0); REP_1(i, m){\r\n                if (h&#x5B;i]){\r\n                    while (h&#x5B;i] &lt;= h&#x5B;s.top()]) s.pop();\r\n                    l&#x5B;i] = s.top()+1;\r\n                }\r\n                else{\r\n                    CLR(s);\r\n                }\r\n                s.push(i);\r\n            }\r\n\r\n            CLR(s); s.push(m+1); DWN_1(i, m, 1){\r\n                if (h&#x5B;i]){\r\n                    while (h&#x5B;i] &lt;= h&#x5B;s.top()]) s.pop();\r\n                    r&#x5B;i] = s.top();\r\n                }\r\n                else{\r\n                    CLR(s);\r\n                }\r\n                s.push(i);\r\n            }\r\n\r\n            REP_1(i, m) checkMax(z, h&#x5B;i]*(r&#x5B;i]-l&#x5B;i]));\r\n        }\r\n        OT(z);\r\n    }\r\n}\r\n\r\n<\/pre>\n<p>\u505a\u6cd5\u4e8c\uff1a\u60ac\u7ebf\u6cd5<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\r\n\r\n\/\/}\/* .................................................................................................................................. *\/\r\n\r\nconst int N = int(2e3) + 9;\r\n\r\nint A&#x5B;N]&#x5B;N], h&#x5B;N]&#x5B;N], l&#x5B;N]&#x5B;N], r&#x5B;N]&#x5B;N];\r\nint n, m;\r\n\r\nint main(){\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n        \/\/freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    fill(A&#x5B;0], A&#x5B;0]+N, 1);\r\n    fill(r&#x5B;0], r&#x5B;0]+N, INF);\r\n\r\n    while (~scanf(&quot;%d %d&quot;, &amp;n, &amp;m)){\r\n\r\n\r\n        REP_2_1(i, j, n, m) RD(A&#x5B;i]&#x5B;j]);\r\n\r\n        int z = 0; RST(h, l, r); REP_1(i, n){\r\n\r\n            FOR_1(j, 1, m) l&#x5B;i]&#x5B;j] = A&#x5B;i]&#x5B;j] ? l&#x5B;i]&#x5B;j-1] + 1 : 0;\r\n            DWN_1(j, m, 1) r&#x5B;i]&#x5B;j] = A&#x5B;i]&#x5B;j] ? r&#x5B;i]&#x5B;j+1] + 1 : 0;\r\n\r\n            REP_1(j, m) if (A&#x5B;i]&#x5B;j] &amp;&amp; A&#x5B;i-1]&#x5B;j]){\r\n                h&#x5B;i]&#x5B;j] = h&#x5B;i-1]&#x5B;j] + 1;\r\n                checkMin(l&#x5B;i]&#x5B;j], l&#x5B;i-1]&#x5B;j]);\r\n                checkMin(r&#x5B;i]&#x5B;j], r&#x5B;i-1]&#x5B;j]);\r\n            }\r\n            REP_1(j, m) checkMax(z, (h&#x5B;i]&#x5B;j]+1)*(r&#x5B;i]&#x5B;j]+l&#x5B;i]&#x5B;j]-1));\r\n        }\r\n\r\n        OT(z);\r\n    }\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[19],"tags":[],"class_list":["post-1136","post","type-post","status-publish","format-standard","hentry","category-poj"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-ik","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=1136"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1136\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=1136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=1136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=1136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}