QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#377620 | #6185. Best Problem | std | AC ✓ | 66ms | 62912kb | C++ | 2.0kb | 2024-04-05 16:02:23 | 2024-04-05 16:06:17 |
This submission is the standard solution.
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=5010000;
char ss[N];
int s[N],n,m;
vector<PII> v;
array<int,3> p[N];
int main() {
scanf("%s",ss);
n=strlen(ss);
rep(i,0,n) s[i+2]=ss[i]-'0';
s[0]=s[1]=1; s[n+2]=s[n+3]=0;
n+=4;
ll ans=0;
rep(i,0,n-1) if (s[i]==s[i+1]) {
if (!v.empty()&&v.back().fi!=s[i]&&s[i]==1&&(i-v.back().se)%4==0) {
ans+=(i-v.back().se)/4;
v.pop_back();
} else {
v.pb(mp(s[i],i));
}
}
rep(i,0,SZ(v)) {
if (v[i].fi==1&&i>0&&v[i-1].fi==1) {
int d=v[i-1].se+1;
while (d%4!=v[i].se%4) ++d;
ans+=(v[i].se-d)/4;
v[i].se=d;
}
}
per(i,0,SZ(v)) {
if (v[i].fi==0&&i+1<SZ(v)&&v[i+1].fi==0) {
int d=v[i+1].se-1;
while (d%4!=v[i].se%4) --d;
ans+=(d-v[i].se)/4;
v[i].se=d;
}
}
rep(i,0,SZ(v)) {
int j=i;
while (j+1<SZ(v)&&v[j+1].fi==v[i].fi) ++j;
p[m++]={v[i].se,v[j].se,j-i+1};
i=j;
}
assert(m%2==0);
vector<ll> dp,pd;
dp=vector<ll>{0};
for (int i=1;i<m;i++) {
pd=dp;
dp.clear();
if (i%2==1) {
int rs=(i==m-1)?0:(p[i+1][0]-p[i][1]-2)/4;
int ls=(p[i][0]-p[i-1][1]-2)/4;
dp.resize(rs+1);
rep(k,0,SZ(pd)) pd[k]+=(ll)k*(k+1)/2+(ll)ls*k;
rep(j,0,rs+1) {
for (int k:{0,SZ(pd)-1}) dp[j]=max(dp[j],pd[k]+(ll)j*k);
dp[j]+=(ll)(j+ls)*(j+ls+1)/2+(ll)p[i][2]*j;
}
} else {
int ls=(p[i][0]-p[i-1][1]-2)/4;
dp.resize(ls+1);
rep(j,0,ls+1) dp[j]=max(dp[j],
(ll)p[i][2]*j+pd[ls-j]);
}
}
printf("%lld\n",dp[0]+ans);
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 7876kb
input:
10100010011001011111
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 8156kb
input:
0000010101100110101101010110000110100111000010010111111100101101110101000111101111010101010010101010
output:
58
result:
ok 1 number(s): "58"
Test #3:
score: 0
Accepted
time: 16ms
memory: 17396kb
input:
100011000011001011010100111110011001000110111101101001100000110101101001101111100101110001101101000001001011011111001100111010101111001110000110001100101100101001001110000111100001100110000101111110001010101100100110010001110011101011110011101111000111010111100110100011110000011111110000111110111110...
output:
302244
result:
ok 1 number(s): "302244"
Test #4:
score: 0
Accepted
time: 9ms
memory: 12544kb
input:
100101010101010101010101010101010101010101100101101010101101010110101001001010101010101101010101010010101010010101010110101010101010101010101101010110101010101010101010101010101010101010101010101010101010101010101010101010101011010101010101010101010101011010010101110101010110101010101010101010111010...
output:
3328566
result:
ok 1 number(s): "3328566"
Test #5:
score: 0
Accepted
time: 3ms
memory: 12120kb
input:
101010101010101010101101010101010101010101010101010101010100101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101001010101010101010101010101010101010101010101010101010101010110...
output:
36918913
result:
ok 1 number(s): "36918913"
Test #6:
score: 0
Accepted
time: 0ms
memory: 14372kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
371689423
result:
ok 1 number(s): "371689423"
Test #7:
score: 0
Accepted
time: 0ms
memory: 12212kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
3378077368
result:
ok 1 number(s): "3378077368"
Test #8:
score: 0
Accepted
time: 6ms
memory: 12188kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
31250155082
result:
ok 1 number(s): "31250155082"
Test #9:
score: 0
Accepted
time: 3ms
memory: 12996kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
21976748120
result:
ok 1 number(s): "21976748120"
Test #10:
score: 0
Accepted
time: 6ms
memory: 14020kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
31249989871
result:
ok 1 number(s): "31249989871"
Test #11:
score: 0
Accepted
time: 3ms
memory: 13064kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
15417990032
result:
ok 1 number(s): "15417990032"
Test #12:
score: 0
Accepted
time: 5ms
memory: 12268kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
31249770935
result:
ok 1 number(s): "31249770935"
Test #13:
score: 0
Accepted
time: 66ms
memory: 62912kb
input:
001001110010100110000111011111010010000100110011010111100100011110101100000001000011001011010000100101101110001010011110010000000101110101101101001011000101011000001001110011001101111010111010000100011011111101101001000001111000001101100011011011111100001000000011001111110000100001111110111000011110...
output:
1529176
result:
ok 1 number(s): "1529176"
Test #14:
score: 0
Accepted
time: 54ms
memory: 46480kb
input:
111100101110111001010010100101010101110101100100011110100001010110101101000010100111001101110011011010010101100101010111001001100111001010111010100111010001110110000001001100001010000101011011010101010011000111010111111011011000010101101001010101010101111010101100101000010100101101110101110101011100...
output:
3453809
result:
ok 1 number(s): "3453809"
Test #15:
score: 0
Accepted
time: 32ms
memory: 41280kb
input:
010100110101010101111100101010101010010100101010010101010010010101011010101010100101010101010011100110101011010011100101010101001010101010110011001010101101101110101010101010101010100101010101100100101010101100010101001010101010101010110100101001010010100101101010101010101010101011101001010101101010...
output:
7267243
result:
ok 1 number(s): "7267243"
Test #16:
score: 0
Accepted
time: 37ms
memory: 36784kb
input:
101100101010101010100010101010101001101010101010101010101101011010100101010101001010110101010101011011001010010101010101010001101010010010101010101101010100010101010101010100101010100101010101010101010101010010101000101010111010010110100101001010101101010101010110101001001010101001101010101010101010...
output:
11025428
result:
ok 1 number(s): "11025428"
Test #17:
score: 0
Accepted
time: 33ms
memory: 34136kb
input:
101010101010101101001010101010101011010110010101001010101010100101010101010101010101010101010101010101010110101010101010101010101010101010110101010101010101010101010011010010101010110101010101001010110101010010101010100101011101010110101010010100101010010101101010101010101010101101010101010011010101...
output:
16770603
result:
ok 1 number(s): "16770603"
Test #18:
score: 0
Accepted
time: 12ms
memory: 29024kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101001010101010101010101010101010101010101010101010101010101010101010101010101010110101001010101010101010101010101010101010101010101010101010101010101...
output:
188646665
result:
ok 1 number(s): "188646665"
Test #19:
score: 0
Accepted
time: 11ms
memory: 29328kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010110101010101010101010101010101010101010101010101010101010101010101010101010101010101010100101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
1815374361
result:
ok 1 number(s): "1815374361"
Test #20:
score: 0
Accepted
time: 18ms
memory: 30088kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
16307938305
result:
ok 1 number(s): "16307938305"
Test #21:
score: 0
Accepted
time: 13ms
memory: 31120kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
184171987292
result:
ok 1 number(s): "184171987292"
Test #22:
score: 0
Accepted
time: 11ms
memory: 29408kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
128638532514
result:
ok 1 number(s): "128638532514"
Test #23:
score: 0
Accepted
time: 7ms
memory: 33712kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
434363327492
result:
ok 1 number(s): "434363327492"
Test #24:
score: 0
Accepted
time: 15ms
memory: 30980kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
493093081142
result:
ok 1 number(s): "493093081142"
Test #25:
score: 0
Accepted
time: 22ms
memory: 41800kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
669857207760
result:
ok 1 number(s): "669857207760"
Test #26:
score: 0
Accepted
time: 13ms
memory: 30060kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
468842033630
result:
ok 1 number(s): "468842033630"
Test #27:
score: 0
Accepted
time: 14ms
memory: 35220kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
639985723182
result:
ok 1 number(s): "639985723182"
Test #28:
score: 0
Accepted
time: 3ms
memory: 29012kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
391921131742
result:
ok 1 number(s): "391921131742"
Test #29:
score: 0
Accepted
time: 17ms
memory: 28784kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
781249375000
result:
ok 1 number(s): "781249375000"
Test #30:
score: 0
Accepted
time: 10ms
memory: 30172kb
input:
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
output:
781249997600
result:
ok 1 number(s): "781249997600"
Extra Test:
score: 0
Extra Test Passed