QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#582673#6624. String ProblemSoestxWA 2ms5872kbC++141.3kb2024-09-22 17:08:032024-09-22 17:08:04

Judging History

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

  • [2024-09-22 17:08:04]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5872kb
  • [2024-09-22 17:08:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fi first
#define se second
#define lowbit(x) x&(-x)
#define pll pair<int,int>
typedef long long ll;
//typedef unsigned long long ull;
const int N=1e6+10,M=1e6,mod=998244353;
int n,m,k;
int num[N];
int res;

string s;
int ne[N],len=0,j=0;

void ini(char c)
{
	s="x";
	s+=c;
	len=1;
	j=0;
	ne[1]=0;
}

void add(char c)
{
	s+=c;
	len++;
	while(j&&s[j+1]!=c) j=ne[j];
	if(s[j+1]==c)
	{
		//cout<<s<<" "<<s[j+1]<<" "<<s[len]<<endl;
		j++;
	}
	ne[len]=j;
}

void to(int l)
{
	len=l;
	j=ne[l];
	//cout<<"TO _----"<<l<<" "<<j<<endl;
	//for(int i=1;i<=l;i++) cout<<ne[i]<<" ";cout<<endl;
}

void solve()
{
	string s;
	cin>>s;
	n=s.size();
	s='a'+s;
	ini(s[1]);
	int L=1;
	//for(int j=1;j<=len;j++) cout<<ne[j]<<" ";cout<<endl;
	cout<<"1 1"<<endl;
	for(int i=2;i<=n;i++)
	{
		if(s[i]>s[L]) L=i,ini(s[i]);
		else
		{
			int idx=-1;
			int p=len;
			while(p>1)
			{
				if(s[L+ne[p]]<s[i]) idx=ne[p];
				p=ne[p];
			}
			if(idx!=-1) L=i-idx,to(idx);
			add(s[i]);
		}
		cout<<L<<" "<<i<<endl;
		//cout<<i<<"-"<<j<<endl;
		//for(int j=1;j<=len;j++) cout<<ne[j]<<" ";cout<<endl;
	}
}

signed main()
{
	//ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T;
	T=1;
	//cin>>T;
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5872kb

input:

potato

output:

1 1
1 2
3 3
3 4
3 5
5 6

result:

ok 12 tokens

Test #2:

score: 0
Accepted
time: 1ms
memory: 5648kb

input:

pbpbppb

output:

1 1
1 2
1 3
1 4
1 5
5 6
5 7

result:

ok 14 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 5852kb

input:

dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd...

output:

1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 61
1 62...

result:

ok 1990 tokens

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 5852kb

input:

gtgggtgttgggggtgtgggtgttggtttggggtggtgtgggttggtggggtgggttgttggttgggtttggggtgttgggggtgggttttggttgttggtggggttgttggtggtggggtgggttttgggttggtgggtgggtggttgtgttggttttttttgttgggtttgggtgttgttgtggtgggttttggttggggtgttggttggtgtggtgtgggttttggttttttgtttgtggtggtgttttgtttttggtggggtgtttgttgttttggggttggggtgggggttgtgg...

output:

1 1
2 2
2 3
2 4
2 5
2 6
2 7
6 8
8 9
8 10
8 11
8 12
8 13
8 14
13 15
13 16
17 17
17 18
17 19
17 20
17 21
17 22
21 23
23 24
23 25
23 26
25 27
28 28
28 29
28 30
28 31
28 32
28 33
28 34
28 35
28 36
28 37
28 38
28 39
28 40
28 41
28 42
28 43
28 44
28 45
28 46
43 47
43 48
43 49
43 50
43 51
43 52
43 53
43 54...

result:

wrong answer 29th words differ - expected: '8', found: '13'