QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#396220#244. Turn Off The Lightczc0 212ms24432kbC++141.1kb2024-04-22 15:25:032024-04-22 15:25:05

Judging History

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

  • [2024-04-22 15:25:05]
  • 评测
  • 测评结果:0
  • 用时:212ms
  • 内存:24432kb
  • [2024-04-22 15:25:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
const int maxn=1e6+5;
int ans[maxn],f[maxn][2],g[maxn],a[maxn],n;
char s[maxn];
inline void calc(){
    int l=n+1,r=0;
    for(int i=1;i<=n;i++) if(a[i]) l=min(l,i),r=max(r,i);
    if(l>r){for(int i=1;i<=n;i++) ans[i]=0; return ;}
    f[r][0]=0,f[r][1]=3;
    f[r-1][0]=1,f[r-1][1]=2;
    for(int i=r-2;i>=1;i--){
        f[i][0]=f[i+1][a[i+1]^1]+1;
        f[i][1]=f[i+1][a[i+1]]+3;
    }
    int p=0,w=0;
    for(int i=1;i<=r;i++){
        if(i<l) ans[i]=f[i][a[i]];
        else p^=a[i],ans[i]=f[i][p]+w,w+=2+(p?0:2);
    }
    for(int i=r+1;i<=n;i++) ans[i]=1919810;
}
inline void solve(){
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++) a[i]=s[i]-'0';
    calc();
    for(int i=1;i<=n;i++) g[i]=ans[i];
    reverse(a+1,a+n+1);
    calc();
    reverse(ans+1,ans+n+1);
    ll ret=0;
    for(int i=1;i<=n;i++){
        g[i]=min(g[i],ans[i]);
        ret=(ret+(ll)i*g[i])%mod;
    }
    printf("%lld\n",ret);
}
int main(){
    int T; scanf("%d",&T);
    while(T--) solve();
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 212ms
memory: 24432kb

input:

146645
2
00
2
10
2
01
2
11
3
000
3
100
3
010
3
110
3
001
3
101
3
011
3
111
4
0000
4
1000
4
0100
4
1100
4
0010
4
1010
4
0110
4
1110
4
0001
4
1001
4
0101
4
1101
4
0011
4
1011
4
0111
4
1111
5
00000
5
10000
5
01000
5
11000
5
00100
5
10100
5
01100
5
11100
5
00010
5
10010
5
01010
5
11010
5
00110
5
10110
5...

output:

0
5
7
6
0
14
10
12
14
24
12
26
0
34
22
36
18
40
20
38
26
60
40
58
24
62
42
60
0
69
47
66
33
80
50
83
31
90
60
93
34
87
57
80
45
120
90
123
64
117
87
110
42
123
93
120
67
118
88
129
0
123
89
126
63
128
86
125
49
150
108
147
70
153
111
152
51
168
126
165
88
171
129
170
54
165
123
168
85
154
112
159
73...

result:

wrong answer 146643rd lines differ - expected: '153920011', found: '551438642'