QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#766918#9571. Border Jump 2UnrealityRE 130ms150072kbC++206.0kb2024-11-20 19:17:162024-11-20 19:17:26

Judging History

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

  • [2024-11-20 19:17:26]
  • 评测
  • 测评结果:RE
  • 用时:130ms
  • 内存:150072kb
  • [2024-11-20 19:17:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define _rep(i_,a_,b_) for(int i_ = (a_); i_ <= (b_); ++i_)
#define mid ((L+R) >> 1)
#define multiCase() int testCnt = in(); _rep(curCase,1,testCnt)
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
using ll = long long;
using pii = pair<int,int>;
using ull = unsigned long long;
const int inf = 0x3f3f3f3f;
const ll inf64 = 0x3f3f3f3f3f3f3f3fll;
int in(void) { int x; scanf("%d", &x); return x; } ll inl(void) { ll x; scanf("%lld", &x); return x; }
void out(int x) { printf("%d ", x); } void outln(int x) { printf("%d\n", x); }
void out(unsigned x) { printf("%u ", x); } void outln(unsigned x) { printf("%u\n", x); }
void out(ll x) { printf("%lld ", x); } void outln(ll x) { printf("%lld\n", x); }
void out(ull x) { printf("%llu ", x); } void outln(ull x) { printf("%llu\n", x); }
template<typename T, typename U> void chkmax(T &a, const U &b) { if(b > a) a = b; } 
template<typename T, typename U> void chkmin(T &a, const U &b) { if(b < a) a = b; } 
const int kN = 205000;
char s[kN]; int n;
int ch[kN][26], fail[kN], len[kN], slink[kN], dep[kN], nc, last, pre[kN], ans[kN];
void RESET(int x) { memset(ch[x], 0, sizeof(ch[x])), fail[x] = len[x] = slink[x] = dep[x] = ans[x] = 0; }
void init(void) {
	nc = 1, last = 0; RESET(1), RESET(0);
	len[1] = -1;
	fail[0] = fail[1] = 1;
}
int getfail(int x, int i) {
	while(s[i - len[x] - 1] != s[i]) x = fail[x];
	return x;
}
void extend(int i) {
	int y = getfail(last, i); 
	if(!ch[y][s[i] - 'a']) {
		int cur = ++nc; RESET(cur);
		len[cur] = len[y] + 2, fail[cur] = ch[getfail(fail[y], i)][s[i] - 'a'];
		if(len[cur] <= 2 * len[fail[cur]]) slink[cur] = slink[fail[cur]], dep[cur] = dep[fail[cur]] + 1;
		else slink[cur] = cur, dep[cur] = 1;
		ch[y][s[i] - 'a'] = cur;
	} last = ch[y][s[i] - 'a'];
}
namespace SAM {
	const int kM = kN << 1;
	int ch[kM][26], link[kM], len[kM], nc, last, rt[kM];
	void RESET(int x) { memset(ch[x], 0, sizeof(ch[x])), link[x] = len[x] = rt[x] = 0; } 
	int clone(int x) { return ++nc, memcpy(ch[nc], ch[x], sizeof(ch[nc])), link[nc] = link[x], rt[nc] = 0, nc; }
	void init(void) { nc = last = 0; RESET(0); link[0] = -1; }
	void extend(char c) { c -= 'a';
		int cur = ++nc; RESET(cur); len[cur] = len[last] + 1;
		while(~last && !ch[last][c]) ch[last][c] = cur, last = link[last];
		if(last == -1) link[cur] = 0;
		else {
			int p = ch[last][c]; 
			if(len[p] == len[last] + 1) link[cur] = p;
			else {
				int q = clone(p); len[q] = len[last] + 1;
				while(~last && ch[last][c] == p) ch[last][c] = q, last = link[last];
				link[cur] = link[p] = q;
			}
		}
		last = cur;
	}
	namespace SEG {
		int ch[kM * 50][2], siz[kM * 50], nc;
		void insert(int &x, int L, int R, int p) { 
			x = ++nc, ch[x][0] = ch[x][1] = siz[x] = 0; ++siz[x];
			if(L == R) return; p <= mid ? insert(ch[x][0], L, mid, p) : insert(ch[x][1], mid + 1, R, p);
		}
		int merge(int x, int y) {
			if(!x || !y || x == y) return x | y;
			int z = ++nc; 
			ch[z][0] = merge(ch[x][0], ch[y][0]), 
			ch[z][1] = merge(ch[x][1], ch[y][1]); 
			siz[z] = siz[ch[z][0]] + siz[ch[z][1]];
			return z;
		}
		int query(int x, int L, int R, int p) {
			if(!x || p <= L) return -1;
			if(L == R) return L;
			if(int tmp = query(ch[x][1], mid + 1, R, p); tmp != -1) return tmp;
			return query(ch[x][0], L, mid, p);
		}
	} using SEG::insert, SEG::merge, SEG::query;
	int fa[20][kN], prenode[kN];
	void init(char *s, int n) {
		init(); SEG::nc = 0; _rep(i,1,n) extend(s[i]), insert(rt[last], 1, n, i), prenode[i] = last;
		_rep(i,1,nc) fa[0][i] = link[i];
		_rep(i,1,19) _rep(j,1,nc) fa[i][j] = fa[i - 1][fa[i - 1][j]];
		static int ord[kM], cnt[kM];
		_rep(i,0,nc) cnt[i] = 0;
		_rep(i,1,nc) ++cnt[len[i]];
		_rep(i,1,nc) cnt[i] += cnt[i - 1];
		_rep(i,1,nc) ord[cnt[len[i]]--] = i;
		for(int i = nc, u = ord[i]; i; --i, u = ord[i]) rt[link[u]] = merge(rt[link[u]], rt[u]); 
	}
	int locate(int l, int r) {
		int u = prenode[r];
		for(int i = 19; ~i; --i) if(len[fa[i][u]] >= r - l + 1) u = fa[i][u];
		return u;
	}
}
int ask(int l, int r) {
	return SAM::query(SAM::rt[SAM::locate(2 * n - r + 1, 2 * n - l + 1)], 1, n * 2, r);	
}
struct Info {
	int top, bot, cnt;
};
int main() { 
	multiCase() {
		scanf("%s", s + 1);
		init();
		n = strlen(s + 1);
		_rep(i,1,n) extend(i), pre[i] = last;
		_rep(i,1,n) s[n + i] = s[n - i + 1];
		SAM::init(s, n * 2);
		debug("%s\n", s + 1);
		debug("%d\n", ask(3, 3));
		_rep(i,1,n) {
			debug("i = %d\n", i);
			vector<Info> L;
			int cur = pre[i], sum = 0;
			while(cur > 1) {
				L.push_back(Info{slink[cur], cur, dep[cur]});
				cur = fail[slink[cur]];
			}
			reverse(L.begin(), L.end());
			for(auto &u : L) debug("%d -- (%d) --> %d\n", u.top, u.cnt, u.bot);
			vector<int> ext(L.size());
			_rep(j,0,L.size() - 1) {
				int l = i - len[L[j].bot] + 1, r = i;
				int goal = (j == L.size() - 1 ? inf : len[L[j + 1].top]), cnt = 0;
				while(1) {
					int pos = ask(l, r); 
					if(pos == -1) break;
					l = pos - (r - l);
					debug("l = %d, r = %d\n", l, r);
					if(r - l + 1 == goal) break;
					++cnt;
				}
				ext[j] = cnt;
				debug("%d%c", ext[j], " \n"[j == L.size() - 1]);
			}
			for(int i = L.size() - 1; ~i; --i) {
				sum += ext[i];
				chkmax(ans[L[i].bot], sum);
				sum += L[i].cnt;
			}
		}
		for(int i = nc; i > 1; --i) {
			_rep(j,0,25) if(ch[i][j]) chkmax(ans[i], ans[ch[i][j]] + 1);
			chkmax(ans[fail[i]], ans[i] + 1);
		}
		int res = 0;
		_rep(i,0,25) if(ch[1][i]) chkmax(res, ans[ch[1][i]]);
		outln(res);
	}
	return 0;
}

/* 
a list of keywords
clear empty push_back pop_back push pop top front back
emplace_back emplace push_front pop_front insert erase
find count set reset bitset map vector string multiset
first second iterator prev next deque multimap reverse
sort begin end list modify query init check calc prime
putchar getchar puts scanf printf max min swap replace
make_pair make_tuple numeric_limits auto function null
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
aaaa
abbaabba
xy

output:

3
4
0

result:

ok 3 number(s): "3 4 0"

Test #2:

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

input:

15
eeee
ooom
bbcb
yyaa
ssdn
wgww
hrhr
exer
hcch
qyyy
lppa
ocvo
orxr
lrjj
pztv

output:

3
2
1
1
1
1
1
1
2
2
1
1
1
1
0

result:

ok 15 numbers

Test #3:

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

input:

52
eeeee
oooom
bbbcb
yyyaa
sssdn
wwgww
hhrhr
eexer
hhcch
qqyyy
llppa
oocvo
oorxr
llrjj
ppztv
tnttt
vnvvn
hthhp
jzjzj
nrnrr
gqgqt
uruyu
cdchd
djdhh
ktkfy
piipp
zaaza
uffuq
bvvvb
hkkkk
pcccj
qccpq
wqqaq
appgg
cxxvg
ewfee
peupe
odfof
kdpkh
zotoz
yzkzz
irtrt
vxyxi
dlood
akrrk
nsbbb
rdjjc
bfexb
uxsex
ise...

output:

4
3
2
2
2
2
1
1
2
2
1
1
1
1
1
2
2
1
2
1
1
1
1
1
1
2
2
2
3
3
2
1
1
1
1
1
1
1
1
2
1
1
1
1
2
2
1
1
1
1
1
0

result:

ok 52 numbers

Test #4:

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

input:

203
eeeeee
ooooom
bbbbcb
yyyyaa
ssssdn
wwwgww
hhhrhr
eeexer
hhhcch
qqqyyy
lllppa
ooocvo
ooorxr
lllrjj
pppztv
ttnttt
vvnvvn
hhthhp
jjzjzj
nnrnrr
ggqgqt
uuruyu
ccdchd
ddjdhh
kktkfy
ppiipp
zzaaza
uuffuq
bbvvvb
hhkkkk
ppcccj
qqccpq
wwqqaq
aappgg
ccxxvg
eewfee
ppeupe
oodfof
kkdpkh
zzotoz
yyzkzz
iirtrt
vv...

output:

5
4
3
3
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
1
1
1
1
1
3
2
2
3
3
2
1
1
1
1
2
1
1
1
2
1
1
1
1
2
2
1
1
1
1
1
1
3
3
2
3
2
2
1
1
1
1
2
2
2
2
2
1
1
1
1
1
1
2
1
1
1
1
1
1
2
1
2
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
3
3
3
4
4
3
2
2
2
2
1
1
1
1
1
2
1
1
1
2
2
1
1
1
1
1
1
2
1
2
1
1
1
1
1
1
2
1
1
1
1
1
1
1
2
2
2
2
1
2
2
...

result:

ok 203 numbers

Test #5:

score: 0
Accepted
time: 4ms
memory: 40644kb

input:

877
eeeeeee
oooooom
bbbbbcb
yyyyyaa
sssssdn
wwwwgww
hhhhrhr
eeeexer
hhhhcch
qqqqyyy
llllppa
oooocvo
oooorxr
llllrjj
ppppztv
tttnttt
vvvnvvn
hhhthhp
jjjzjzj
nnnrnrr
gggqgqt
uuuruyu
cccdchd
dddjdhh
kkktkfy
pppiipp
zzzaaza
uuuffuq
bbbvvvb
hhhkkkk
pppcccj
qqqccpq
wwwqqaq
aaappgg
cccxxvg
eeewfee
pppeupe
...

output:

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

result:

ok 877 numbers

Test #6:

score: 0
Accepted
time: 11ms
memory: 40608kb

input:

4140
eeeeeeee
ooooooom
bbbbbbcb
yyyyyyaa
ssssssdn
wwwwwgww
hhhhhrhr
eeeeexer
hhhhhcch
qqqqqyyy
lllllppa
ooooocvo
ooooorxr
lllllrjj
pppppztv
ttttnttt
vvvvnvvn
hhhhthhp
jjjjzjzj
nnnnrnrr
ggggqgqt
uuuuruyu
ccccdchd
ddddjdhh
kkkktkfy
ppppiipp
zzzzaaza
uuuuffuq
bbbbvvvb
hhhhkkkk
ppppcccj
qqqqccpq
wwwwqqa...

output:

7
6
5
5
5
4
4
4
4
4
4
4
4
4
4
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
2
2
2
2
2
2
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
4
3
3
2
2
2
2
2
2
2
4
3
3
4
4
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
2
2
2
2
2
2
...

result:

ok 4140 numbers

Test #7:

score: 0
Accepted
time: 71ms
memory: 40732kb

input:

21147
eeeeeeeee
oooooooom
bbbbbbbcb
yyyyyyyaa
sssssssdn
wwwwwwgww
hhhhhhrhr
eeeeeexer
hhhhhhcch
qqqqqqyyy
llllllppa
oooooocvo
oooooorxr
llllllrjj
ppppppztv
tttttnttt
vvvvvnvvn
hhhhhthhp
jjjjjzjzj
nnnnnrnrr
gggggqgqt
uuuuuruyu
cccccdchd
dddddjdhh
kkkkktkfy
pppppiipp
zzzzzaaza
uuuuuffuq
bbbbbvvvb
hhhh...

output:

8
7
6
6
6
5
5
5
5
5
5
5
5
5
5
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
4
3
3
3
3
3
3
3
3
3
4
3
3
4
4
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
...

result:

ok 21147 numbers

Test #8:

score: 0
Accepted
time: 130ms
memory: 150072kb

input:

2
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee...

output:

99999
99999

result:

ok 2 number(s): "99999 99999"

Test #9:

score: -100
Runtime Error

input:

2
eeegeeeggegegeeeegegeeeeegeeegeeeggeeeggegggegeggeeeeegegeeggeeeggggeggggegegeegggegggggeggggeegggegeeegggeegeeegeeeegeggegeggeggeggegggeeeeggeggggggeggegggeegegegggeggegggeegeeggegeegegggeegegegggegggeeeggeggeeegeeggeeggeggegggeggeegegegeeggggegggggegegggeeeegegeeggeggegggegegeggeegggeeeggeeggegg...

output:


result: