Codeforces Round #513 by Barcelona bootcamp (rated, div. 1 + div. 2) c. Maximum Subrectangle

Source: Internet
Author: User

Yesterday, just remember to write a blog, remember how to do this matrix problem.

First I did not realize that in each direction tired and, get two tired and array, their sub-sequence of the product, is the sub-sequence corresponding to the rectangular region of the sum of all the numbers , said a little abstract, but to raise a chestnut bar,

Just like this hint in the use case, the horizontal axis I choose the sub-column 2, 3, then and 5, the ordinate I choose the sub-column 1, 2, then and 3. Then 3 and 5, the product is 15, and the corresponding region of the matrix and add, is also 15,. The problem is easy: just enumerate one-dimensional arrays. However, if you enumerate one-dimensional arrays, wouldn't it be a four-cycle loop? actually otherwise

The topic wants us to obtain a maximum value that is not more than the limit value, before which we need to do a preprocessing on one of the sequences: The double loop enumerates all the sub-columns, computes the minimum sub-columns (minimum, to the length of the corresponding sub-column), to ensure that more points are taken, that is, longer lengths, i.e. larger areas After that, you can select another sequence in two, use a double loop to get the sub-columns, and then divide the limit by this sum to get a target value. After that, in the array of initial preprocessing to find the target value, return is greater than its first value, that is, with Upper_bound, to find the length minus one, so that the longest length. Finally, by multiplying the length of the lookup with the length of the current child column, the result is always the maximum value, and after the loop is over, the answer is.

  #include <bits/stdc++.h> #define N 2005#define INF 0x7fffffffusing namespace Std;typedef    Long Long Ll;int a[n],b[n];ll ma[n],x;int main () {Ios::sync_with_stdio (false);    Cin.tie (0);    int n,m,ans=0;    Fill (Ma,ma+n,inf);    cin>>n>>m;    for (int i=1;i<=n;i++) {cin>>a[i];a[i]=a[i-1]+a[i];}    for (int i=1;i<=m;i++) {cin>>b[i];b[i]=b[i-1]+b[i];}    cin>>x;            for (int i=1;i<=n;i++) {for (int j=i;j<=n;j++) {ll tsm=a[j]-a[i-1];            int len=j-i+1;        Ma[len]=min (MA[LEN],TSM);            }} for (int i=1;i<=m;i++) {for (int j=i;j<=m;j++) {ll sc=x/(b[j]-b[i-1]);            int len=j-i+1;            int Mxa=upper_bound (MA+1,MA+N+1,SC)-ma-1;        Ans=max (ANS,LEN*MXA);    }} cout<<ans<<endl; return 0;}  

Codeforces Round #513 by Barcelona bootcamp (rated, div. 1 + div. 2) C. Maximum Subrectangle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.