私が話をしてみましょう\(\シータ(N ^ 2 )\) の暴力のペアを。
どうやらアイデアが隣接する二つで答えを列挙することです\(1 \)を間に\(0 \)番号。
その後貪欲試合、注意裁判官最後の段落は、制限を満たしています。
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define MEM(x,y) memset ( x , y , sizeof ( x ) )
#define rep(i,a,b) for (int i = (a) ; i <= (b) ; ++ i)
#define per(i,a,b) for (int i = (a) ; i >= (b) ; -- i)
#define pii pair < int , int >
#define one first
#define two second
#define rint read<int>
#define int long long
#define pb push_back
using std::queue ;
using std::set ;
using std::pair ;
using std::max ;
using std::min ;
using std::priority_queue ;
using std::vector ;
using std::swap ;
using std::sort ;
using std::unique ;
using std::greater ;
template < class T >
inline T read () {
T x = 0 , f = 1 ; char ch = getchar () ;
while ( ch < '0' || ch > '9' ) {
if ( ch == '-' ) f = - 1 ;
ch = getchar () ;
}
while ( ch >= '0' && ch <= '9' ) {
x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ;
ch = getchar () ;
}
return f * x ;
}
const int N = 1e5 + 100 ;
char s[N] ;
int n , ans , tmp[N] ;
bool v[N] ;
inline bool check () {
return true ;
}
signed main (int argc , char * argv[]) {
scanf ("%s" , s + 1 ) ; n = strlen ( s + 1 ) ;
rep ( i , 1 , n ) v[i] = ( s[i] == '1' ) ;
rep ( i , 0 , n ) {
int time = 0 , res = 0 , cur = 0 ;
bool f = false , d = 0 , able = false ;
rep ( j , 1 , n ) {
if ( ! d && ! v[j] ) {
++ cur ;
if ( cur == i ) d = true , ++ time ;
}
if ( d && v[j] ) {
cur = 0 ; d = false ;
res += ( i + 1 ) ;
able = true ;
}
}
if ( able ) {
if ( time < 2 ) continue ;
if ( d ) { ans = max ( ans , res + i ) ; }
else ans = max ( ans , res - 1 ) ;
}
}
printf ("%lld\n" , ans ) ;
return 0 ;
}
その後、我々は、このボトルネックアルゴリズムは、文字列と一致することです見つけ\(0 \)ルートパーティションに精通している場合、パーティションをrootにしたいのは当然かもしれないが、それは完全に可能である。
しかし、我々は言わなければなりませんこれは私たちが考えるアプローチではありません、元のシーケンスが\(0 \)数は単調で存在していませんが、接頭辞\(0 \)数は単調性を持っている。
そしてだけのために集中する必要があります\(1 \ )コミュニティを分割することであるので、我々はいくつか見つけるために半分/乗数を行くことができます\(0 \) 。
コードは書いていません。