QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#184429#7109. Traveling on the Axisliuzhenhao09#WA 6ms6944kbC++20812b2023-09-20 19:05:172023-09-20 19:05:18

Judging History

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

  • [2023-09-20 19:05:18]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:6944kb
  • [2023-09-20 19:05:17]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,tot = 0;
char s[100010];
int l[100010],r[100010],nxt[100010],val[100010];
signed main(){
	scanf("%lld",&T);
	while(T--){
		scanf("%s",s + 1);
		int n = strlen(s + 1);
		tot = 0;
		char pre = s[1];
		for(int i = 1; i <= n; i++){
			if(pre == s[i]){
				r[tot] = i - 1;
				tot++;
				l[tot] = i;
			}
			pre = s[i];
		}
		r[tot] = n;
		int ans = 0;
		for(int i = tot; i >= 1; i--) nxt[i] = nxt[i + 1] + (r[i] - l[i] + 1),val[i] = val[i + 1] + (r[i] - l[i] + 1) * i;
		for(int i = 1; i <= tot; i++) ans += (r[i] - l[i] + 1) * (val[i] - i * nxt[i]);
		for(int i = 1; i <= n; i++) ans += i * (n - i + 1);
		for(int i = 1; i <= n; i++) if(s[i] == '0') ans += (n - i + 1);
		printf("%lld\n",ans);
	}
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5680kb

input:

3
101
011
11010

output:

12
15
43

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 6ms
memory: 6944kb

input:

6107
1010101
010110100110101
1010
1010101010010101010
101011
0101101011010101010
0101101011
11011010101
010
1011010
10110101010101010100
010101010110101
10101010101011
0101010101010101011
00101010011000
1010101010010110110
01010101001010101010
101010101010101
100100101010101010
01
011
0101010100101
...

output:

96
889
116
1813
176
1727
394
425
110
261
1912
1016
853
1764
764
1754
2098
1216
1487
94
121
1007
269
2458
2141
540
1022
809
677
132
2180
835
555
117
695
92
1483
1564
313
907
173
151
665
1096
1141
1301
70
33
507
160
971
822
365
978
139
236
282
158
637
28
282
745
434
339
353
21
353
1364
292
958
348
25
...

result:

wrong answer 3rd lines differ - expected: '24', found: '116'