QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#99230 | #6299. Binary String | CharlieVinnie | Compile Error | / | / | C++20 | 1.9kb | 2023-04-21 17:51:18 | 2023-04-21 17:51:19 |
Judging History
你现在查看的是最新测评结果
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-04-21 17:51:19]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-04-21 17:51:18]
- 提交
answer
#include "bits/stdc++.h"
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
#define assume(expr) ((!!(expr))||(exit((fprintf(stderr,"Assumption Failed: %s on Line %d\n",#expr,__LINE__),-1)),false))
using namespace std;
const int N=1e7+5; typedef long long ll;
char s[N]; int n,st[N],tp,mv,cnt1[N],a[N],nxt[N];
void solve(){
cin>>(s+1); n=strlen(s+1); For(i,1,n) s[i]-='0',s[i]^=1;
int ccc[2]={0}; For(i,1,n) ccc[s[i]]++;
if(ccc[0]<ccc[1]){
reverse(s+1,s+1+n); For(i,1,n) s[i]^=1;
}
mv=tp=0;
Rev(i,n,1){
if(s[i]==0){
if(tp) tp--;
}
else{
mv++; st[++tp]=1-mv;
}
}
int mx=0;
Rev(i,n,1){
if(s[i]==0){
if(tp) tp--;
}
else{
mv++; st[++tp]=1-mv;
}
cnt1[i]=tp;
if(tp) mx=max(mx,st[1]+mv);
}
// cout<<"mx="<<mx<<'\n';
// For(i,1,n) cout<<cnt1[i]<<' ';; cout<<'\n';
if(mx==0){
cout<<"1\n"; return;
}
For(i,1,n) a[i]=0;
For(i,1,n) if(s[i]==1){
int o=(i+mx-cnt1[i]-1)%n+1;
// printf("i=%d: o=%d\n",i,o);
assume(a[o]==0); a[o]=1;
}
// For(i,1,n) cout<<a[i];; cout<<'\n';
int ans=mx-1;
nxt[1]=0;
for(int i=1,j=0;i<n;i++){
while(j&&a[i+1]!=a[j+1]) j=nxt[j];
if(a[i+1]==a[j+1]) j++;
nxt[i+1]=j;
}
int t=n-nxt[n];
if(n%t==0) ans+=t;
else ans+=n;
cout<<ans<<'\n';
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int T; cin>>T; while(T--) solve();
cerr<<"Time = "<<clock()<<" ms"<<endl;
return 0;
}
// START TYPING IF YOU DON'T KNOW WHAT TO DO
// STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
// CONTINUE, NON-STOPPING, FOR CHARLIEVINNIE
Details
answer.code: In function ‘void solve()’: answer.code:11:8: error: no match for ‘operator>>’ (operand types are ‘std::istream’ {aka ‘std::basic_istream<char>’} and ‘char*’) 11 | cin>>(s+1); n=strlen(s+1); For(i,1,n) s[i]-='0',s[i]^=1; | ~~~^~~~~~~ | | | | | char* | std::istream {aka std::basic_istream<char>} In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from answer.code:1: /usr/include/c++/11/istream:168:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ (near match) 168 | operator>>(bool& __n) | ^~~~~~~~ /usr/include/c++/11/istream:168:7: note: conversion of argument 1 would be ill-formed: answer.code:11:12: error: cannot bind non-const lvalue reference of type ‘bool&’ to a value of type ‘char*’ 11 | cin>>(s+1); n=strlen(s+1); For(i,1,n) s[i]-='0',s[i]^=1; | ~~^~~ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from answer.code:1: /usr/include/c++/11/istream:172:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]’ (near match) 172 | operator>>(short& __n); | ^~~~~~~~ /usr/include/c++/11/istream:172:7: note: conversion of argument 1 would be ill-formed: answer.code:11:12: error: invalid conversion from ‘char*’ to ‘short int’ [-fpermissive] 11 | cin>>(s+1); n=strlen(s+1); For(i,1,n) s[i]-='0',s[i]^=1; | ~~^~~ | | | char* answer.code:11:12: error: cannot bind rvalue ‘(short int)(((char*)(& s)) + 1)’ to ‘short int&’ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from answer.code:1: /usr/include/c++/11/istream:175:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ (near match) 175 | operator>>(unsigned short& __n) | ^~~~~~~~ /usr/include/c++/11/istream:175:7: note: conversion of argument 1 would be ill-formed: answer.code:11:12: error: invalid conversion from ‘char*’ to ‘short unsigned int’ [-fpermissive] 11 | cin>>(s+1); n=strlen(s+1); For(i,1,n) s[i]-='0',s[i]^=1; | ~~^~~ | | | char* answer.code:11:12: error: cannot bind rvalue ‘(short unsigned int)(((char*)(& s)) + 1)’ to ‘short unsigned int&’ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from answer.code:1: /usr/include/c++/11/istream:179:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]’ (near match) 179 | operator>>(int& __n); | ^~~~~~~~ /usr/include/c++/11/istream:179:7: note: conversion of argument 1 would be ill-formed: answer.code:11:12: error: invalid conversion from ‘char*’ to ‘int’ [-fpermissive] 11 | cin>>(s+1); n=strlen(s+1); For(i,1,n) s[i]-='0',s[i]^=1; | ~~^~~ | | | char* answer.code:11:12: error: cannot bind rvalue ‘(int)(((char*)(& s)) + 1)’ to ‘int&’ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from answer.code:1: /usr/include/c++/11/istream:182:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ (near match) 182 | operator>>(unsigned int& __n) | ^~~~~~~~ /usr/include/c++/11/is...