QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#377825 | #6185. Best Problem | 275307894a | AC ✓ | 74ms | 92460kb | C++14 | 2.5kb | 2024-04-05 18:27:25 | 2024-04-05 18:27:25 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=5e6+5,M=(1<<20)+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
char s[N];int n;
pii s1[N],s2[N];int h1,h2,st[N],sh;
ll f[N],dp[N][2];
ll calc(int x,int ox,int y,int oy){
int w=0;ll tot=0;
int z=x;
while(s2[z+1].se==s2[z].se) z++;
if(ox) w+=(s2[x].fi-s2[x-1].fi)/4*4,tot+=1ll*(s2[x].fi-s2[x-1].fi)/4*(z-x+1);
if(!oy) w+=(s2[y+1].fi-s2[y].fi)/4*4,tot+=1ll*(s2[y+1].fi-s2[y].fi)/4*(y-z);
w+=s2[z+1].fi-s2[z].fi-1;
return f[w]+tot;
}
void chkmax(ll &x,ll y){if(y>x) x=y;}
void Solve(){
int i,j;scanf("%s",s+3);
s[1]=s[2]='1';n=strlen(s+1);s[n+1]=s[n+2]='0';n+=2;
h1=h2=0;for(i=1;i<n;i++) if(s[i]==s[i+1]) s1[++h1]=make_pair(i,s[i]);
ll ans=0;
// for(i=1;i<=h1;i++) gdb(s1[i].fi,s1[i].se);
for(i=1;i<=h1;i++){
s2[++h2]=s1[i];
if(h2>=2&&s2[h2-1].se=='0'&&s2[h2].se=='1'&&(s2[h2].fi-s2[h2-1].fi)%4==0) ans+=(s2[h2].fi-s2[h2-1].fi)/4,h2-=2;
}
for(i=2;i<=h2;i++) if(s2[i-1].se=='1'&&s2[i].se=='1'){
int w=s2[i].fi-s2[i-1].fi>>2;
ans+=w;s2[i].fi-=w*4;
}
for(i=h2-1;i;i--) if(s2[i].se=='0'&&s2[i+1].se=='0'){
int w=s2[i+1].fi-s2[i].fi>>2;
ans+=w;s2[i].fi+=w*4;
}
for(i=5;i<=n;i++){
int w=(i-5+1)/4;
f[i]=f[3+w*4]+w+1;
}
st[sh=1]=0;for(i=1;i<h2;i++) if(s2[i].se=='0'&&s2[i+1].se=='1') st[++sh]=i;st[++sh]=h2;
for(i=1;i<=sh;i++) Me(dp[i],-0x3f)/*,gdb(st[i],s2[st[i]].fi)*/;
dp[1][0]=0;
for(i=2;i<=sh;i++){
for(int x:{0,1}) for(int y:{0,1}) chkmax(dp[i][x],dp[i-1][y]+calc(st[i-1]+1,y,st[i],x));
}
printf("%lld\n",dp[sh][1]+ans);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4060kb
input:
10100010011001011111
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 4052kb
input:
0000010101100110101101010110000110100111000010010111111100101101110101000111101111010101010010101010
output:
58
result:
ok 1 number(s): "58"
Test #3:
score: 0
Accepted
time: 7ms
memory: 21728kb
input:
100011000011001011010100111110011001000110111101101001100000110101101001101111100101110001101101000001001011011111001100111010101111001110000110001100101100101001001110000111100001100110000101111110001010101100100110010001110011101011110011101111000111010111100110100011110000011111110000111110111110...
output:
302244
result:
ok 1 number(s): "302244"
Test #4:
score: 0
Accepted
time: 7ms
memory: 14444kb
input:
100101010101010101010101010101010101010101100101101010101101010110101001001010101010101101010101010010101010010101010110101010101010101010101101010110101010101010101010101010101010101010101010101010101010101010101010101010101011010101010101010101010101011010010101110101010110101010101010101010111010...
output:
3328566
result:
ok 1 number(s): "3328566"
Test #5:
score: 0
Accepted
time: 3ms
memory: 12968kb
input:
101010101010101010101101010101010101010101010101010101010100101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101001010101010101010101010101010101010101010101010101010101010110...
output:
36918913
result:
ok 1 number(s): "36918913"
Test #6:
score: 0
Accepted
time: 0ms
memory: 12700kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
371689423
result:
ok 1 number(s): "371689423"
Test #7:
score: 0
Accepted
time: 0ms
memory: 12808kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
3378077368
result:
ok 1 number(s): "3378077368"
Test #8:
score: 0
Accepted
time: 3ms
memory: 12804kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
31250155082
result:
ok 1 number(s): "31250155082"
Test #9:
score: 0
Accepted
time: 3ms
memory: 12816kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
21976748120
result:
ok 1 number(s): "21976748120"
Test #10:
score: 0
Accepted
time: 3ms
memory: 12688kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
31249989871
result:
ok 1 number(s): "31249989871"
Test #11:
score: 0
Accepted
time: 3ms
memory: 12812kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
15417990032
result:
ok 1 number(s): "15417990032"
Test #12:
score: 0
Accepted
time: 0ms
memory: 12804kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
31249770935
result:
ok 1 number(s): "31249770935"
Test #13:
score: 0
Accepted
time: 74ms
memory: 92460kb
input:
001001110010100110000111011111010010000100110011010111100100011110101100000001000011001011010000100101101110001010011110010000000101110101101101001011000101011000001001110011001101111010111010000100011011111101101001000001111000001101100011011011111100001000000011001111110000100001111110111000011110...
output:
1529176
result:
ok 1 number(s): "1529176"
Test #14:
score: 0
Accepted
time: 66ms
memory: 77024kb
input:
111100101110111001010010100101010101110101100100011110100001010110101101000010100111001101110011011010010101100101010111001001100111001010111010100111010001110110000001001100001010000101011011010101010011000111010111111011011000010101101001010101010101111010101100101000010100101101110101110101011100...
output:
3453809
result:
ok 1 number(s): "3453809"
Test #15:
score: 0
Accepted
time: 52ms
memory: 64972kb
input:
010100110101010101111100101010101010010100101010010101010010010101011010101010100101010101010011100110101011010011100101010101001010101010110011001010101101101110101010101010101010100101010101100100101010101100010101001010101010101010110100101001010010100101101010101010101010101011101001010101101010...
output:
7267243
result:
ok 1 number(s): "7267243"
Test #16:
score: 0
Accepted
time: 40ms
memory: 59984kb
input:
101100101010101010100010101010101001101010101010101010101101011010100101010101001010110101010101011011001010010101010101010001101010010010101010101101010100010101010101010100101010100101010101010101010101010010101000101010111010010110100101001010101101010101010110101001001010101001101010101010101010...
output:
11025428
result:
ok 1 number(s): "11025428"
Test #17:
score: 0
Accepted
time: 19ms
memory: 56252kb
input:
101010101010101101001010101010101011010110010101001010101010100101010101010101010101010101010101010101010110101010101010101010101010101010110101010101010101010101010011010010101010110101010101001010110101010010101010100101011101010110101010010100101010010101101010101010101010101101010101010011010101...
output:
16770603
result:
ok 1 number(s): "16770603"
Test #18:
score: 0
Accepted
time: 11ms
memory: 48724kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101001010101010101010101010101010101010101010101010101010101010101010101010101010110101001010101010101010101010101010101010101010101010101010101010101...
output:
188646665
result:
ok 1 number(s): "188646665"
Test #19:
score: 0
Accepted
time: 14ms
memory: 48044kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010110101010101010101010101010101010101010101010101010101010101010101010101010101010101010100101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
1815374361
result:
ok 1 number(s): "1815374361"
Test #20:
score: 0
Accepted
time: 12ms
memory: 47956kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
16307938305
result:
ok 1 number(s): "16307938305"
Test #21:
score: 0
Accepted
time: 20ms
memory: 48004kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
184171987292
result:
ok 1 number(s): "184171987292"
Test #22:
score: 0
Accepted
time: 16ms
memory: 47964kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
128638532514
result:
ok 1 number(s): "128638532514"
Test #23:
score: 0
Accepted
time: 12ms
memory: 48000kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
434363327492
result:
ok 1 number(s): "434363327492"
Test #24:
score: 0
Accepted
time: 18ms
memory: 47928kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
493093081142
result:
ok 1 number(s): "493093081142"
Test #25:
score: 0
Accepted
time: 20ms
memory: 47952kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
669857207760
result:
ok 1 number(s): "669857207760"
Test #26:
score: 0
Accepted
time: 16ms
memory: 47968kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
468842033630
result:
ok 1 number(s): "468842033630"
Test #27:
score: 0
Accepted
time: 29ms
memory: 47956kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
639985723182
result:
ok 1 number(s): "639985723182"
Test #28:
score: 0
Accepted
time: 16ms
memory: 47992kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
391921131742
result:
ok 1 number(s): "391921131742"
Test #29:
score: 0
Accepted
time: 7ms
memory: 47956kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
781249375000
result:
ok 1 number(s): "781249375000"
Test #30:
score: 0
Accepted
time: 7ms
memory: 47956kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
781249997600
result:
ok 1 number(s): "781249997600"
Extra Test:
score: 0
Extra Test Passed