QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#582617#6624. String ProblemSoestxWA 2ms5828kbC++141.2kb2024-09-22 16:59:322024-09-22 16:59:39

Judging History

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

  • [2024-09-22 16:59:39]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5828kb
  • [2024-09-22 16:59:32]
  • 提交

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]!=s[len]) j=ne[j];
	if(s[j+1]==s[len]) 
	{
		//cout<<s<<" "<<s[j+1]<<" "<<s[len]<<endl;
		j++;
	}
	ne[len]=j;
}

void to(int l)
{
	len=l;
	j=ne[l];
}

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];
				//cout<<p<<endl;
			}
			if(idx!=-1) L=i-idx,to(idx);
			add(s[i]);
		}
		cout<<L<<" "<<i<<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: 5660kb

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: 0ms
memory: 5564kb

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: 5576kb

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: 5828kb

input:

gtgggtgttgggggtgtgggtgttggtttggggtggtgtgggttggtggggtgggttgttggttgggtttggggtgttgggggtgggttttggttgttggtggggttgttggtggtggggtgggttttgggttggtgggtgggtggttgtgttggttttttttgttgggtttgggtgttgttgtggtgggttttggttggggtgttggttggtgtggtgtgggttttggttttttgtttgtggtggtgttttgtttttggtggggtgtttgttgttttggggttggggtgggggttgtgg...

output:

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

result:

wrong answer 17th words differ - expected: '8', found: '6'