QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#160103#7109. Traveling on the Axisucup-team1412#AC ✓235ms4948kbC++111.5kb2023-09-02 19:28:022023-09-02 19:28:02

Judging History

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

  • [2023-09-02 19:28:02]
  • 评测
  • 测评结果:AC
  • 用时:235ms
  • 内存:4948kb
  • [2023-09-02 19:28:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int t,n;
int steps[100000+5];
long long houzhui[100000+5];
long long ans;
string s;
long long len;
long long pos,ti,cnt;
int main()
{
	cin>>t;
	while(t--)
	{
		
	 memset(steps,0,sizeof(steps));
	 memset(houzhui,0,sizeof(houzhui));
	 ans=0;
	 pos=0;
	 ti=0;
	 
		
	cin>>s;
	len=s.length();
    
    while(pos<=len)
    {
    
    	
    	int flag;
    	
    	
    	
    	if(ti%2)flag=1-(s[pos]-'0');
    	else flag=s[pos]-'0';
    	
    	//cout<<"pos="<<pos<<"   ti="<<ti<<"  flag="<<flag<<"  s[pos]="<<s[pos]<<endl;
    	//system("pause");
    	if(flag==1)
    	{
    		pos++;ti++;
			steps[pos]=ti;
    	    if(pos==len)break;
		}
		else 
		ti++;
		
	}
	
	
    
    houzhui[len]=steps[len];
    for(int i=len-1;i>=0;i--)
    {
    	ans+=steps[i+1];
    	houzhui[i]=houzhui[i+1]+steps[i];
	}
	/*
	for(int i=0;i<=len;i++)
	cout<<steps[i]<<" ";
	cout<<endl;
	
    for(int i=0;i<=len;i++)
	cout<<houzhui[i]<<" ";
	cout<<endl;
	
    */
    
    for(int i=1;i<len;i++)
    {
    	int ifchanged;
    	if(steps[i]%2==1)ifchanged=1;
    	else ifchanged=0;
    	
    	if(!ifchanged)
		{
			ans+=houzhui[i+1]-(len-i)*steps[i];
		}
		else 
		{
			if(s[i]=='0')
			{
				ans+=houzhui[i+1]-(len-i)*steps[i];
				ans+=(len-i);
			}
			else
			{
				i++;
				ans+=houzhui[i+1]-(len-i)*steps[i];
				ans+=(len-i+1);
				i--;
				
			}
		}
		
    	
    	
    
		
	}
    cout<<ans<<endl;
    
    }
	return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 4764kb

input:

3
101
011
11010

output:

12
15
43

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 235ms
memory: 4948kb

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
24
1515
69
1567
279
345
14
106
1702
791
621
1447
764
1615
1755
736
1333
6
15
542
44
1689
1515
140
833
497
596
24
1640
694
462
30
425
14
1041
1446
96
504
124
75
560
970
771
945
6
1
321
137
786
720
206
769
46
103
225
74
554
2
100
529
260
207
197
2
197
1041
140
857
207
1
74
1604
41
343
1041
14
1...

result:

ok 6107 lines

Extra Test:

score: 0
Extra Test Passed