QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#411197#6299. Binary StringN_z_WA 1ms3736kbC++145.2kb2024-05-15 09:32:452024-05-15 09:32:45

Judging History

你现在查看的是最新测评结果

  • [2024-05-15 09:32:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3736kb
  • [2024-05-15 09:32:45]
  • 提交

answer

#define LUOGU
#if defined(LOCAL) or not defined(LUOGU)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,unroll-loops")
#endif
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include"dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
#define Setprecision 10
#define between '\n'
#define __int128 long long
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(T x){for(auto &y:x)*this<<y<<between;*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-Setprecision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(T c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(std::string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl

void solve();
main()
{
    int t=1;
    cin>>t;
    while(t--)solve();
}
void solve()
{
    string s;
    cin>>s;
    if(count(s.begin(),s.end(),'1')<count(s.begin(),s.end(),'0'))
    {
        reverse(s.begin(),s.end());
        transform(s.begin(),s.end(),s.begin(),[&](char c){return c^1;});
    }
    if(count(s.begin(),s.end(),'1')==s.size())
    {
        cout<<1<<endl;return;
    }
    vector<int>t(s.size()),u(s.size());
    int sum=0;
    transform(s.begin(),s.end(),t.begin(),[&](char c){return sum+=(c=='0'?1:-1);});
    rotate(s.begin(),max_element(t.begin(),t.end())-t.begin()+s.begin()+1,s.end());
    int ans=0;
    for(int x=s.size()-1,lst=-1,ct=0,len=0;x>=0;x--)
    if(s[x]=='0')
    {
        if(lst!=-1)
        {
            u[len++]=ct++;
            len-=min(len,lst-x-1);
        }
        if(!len)t[x]=0;
        else ans=max(ans,ct-u[0]),t[x]=len;
        lst=x;
    }
    string v(s.size(),'0');
    for(int x=0;x<s.size();x++)
    if(s[x]=='0')v[(x+ans-t[x])%s.size()]='1';
    vector<int>fail(s.size(),-1);
    for(int x=1,y=-1;x<s.size();x++)
    {
        while(y>=0&&v[y+1]!=v[x])y=fail[y];
        y+=(v[y+1]==v[x]);
        fail[x]=y;
    }
    for(int x=fail[s.size()-1];x>=0;x=fail[x])
    if(s.size()%(s.size()-x-1)==0){cout<<ans+(s.size()-x-1)<<endl;return;}
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3736kb

input:

3
1
001001
0001111

output:

1
3

result:

wrong answer Answer contains longer sequence [length = 3], but output contains 2 elements