vijosP1195 "very male and female" program

Source: Internet
Author: User

vijosP1195 "very male and female" program

Links: https://vijos.org/p/1195

Ideas

The number is poor.

There must be an equal number of males and females in the interval between two points with the same number of differences.

So far to I of 1 is sum1,0 for SUM0, then the number of the difference is T, with the L [t] array record difference T appears the leftmost point, compared to ans.

Code

1#include <iostream>2#include <cstdio>3 using namespacestd;4 5 Const intMAXN =200000+Ten;6 Const intn=100000+2;7 intL[maxn],r;8 intN;9 TenInlineintRead_int () { One     CharC=GetChar (); A      while(!isdigit (c)) c=GetChar (); -     intx=0; -      while(IsDigit (c)) { thex=x*Ten+c-'0'; -C=GetChar (); -     } -     returnx; + } - intMain () { +n=read_int (); A     intans=0; at     intsum0=0, sum1=0; -l[0+n]=0; -      for(intI=1; i<=n;i++) { -         intx=read_int (); -         if(x) sum1++;Elsesum0++; -         intt=sum1-sum0+N; in         if((t-n) &&!l[t]) l[t]=i; -Ans=max (ans,i-l[t]); to     } +cout<<ans; -     return 0; the}

vijosP1195 "very male and female" program

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.