QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#532856#2840. 绿绿与串串RainPPRAC ✓262ms53240kbC++202.2kb2024-08-25 13:28:442024-08-25 13:28:44

Judging History

This is the latest submission verdict.

  • [2024-08-25 13:28:44]
  • Judged
  • Verdict: AC
  • Time: 262ms
  • Memory: 53240kb
  • [2024-08-25 13:28:44]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

// -----------------------------------------------------------------------------

using u64 = uint64_t;

constexpr u64 p1 = 131, m1 = 13331;
constexpr u64 p2 = 13331, m2 = 1e9 + 9;

constexpr int N = 1e6 + 10;

u64 b1[N], b2[N];

void init() {
	b1[0] = b2[0] = 1;
	for (int i = 1; i < N; ++i) {
		b1[i] = b1[i - 1] * p1 % m1;
		b2[i] = b2[i - 1] * p2 % m2;
	}
}

u64 h1[N], h2[N];
u64 r1[N], r2[N];

void init(string str) {
	int n = str.size();
	h1[0] = h2[0] = 0;
	for (int i = 1; i <= n; ++i) {
		int c = str[i - 1];
		h1[i] = (h1[i - 1] * p1 % m1 + c) % m1;
		h2[i] = (h2[i - 1] * p2 % m2 + c) % m2;
	}
	r1[n + 1] = r2[n + 1] = 0;
	for (int i = n; i >= 1; --i) {
		int c = str[i - 1];
		r1[i] = (r1[i + 1] * p1 % m1 + c) % m1;
		r2[i] = (r2[i + 1] * p2 % m2 + c) % m2;
	}
}

u64 geth(u64 m, u64 *h, u64 *b, int l, int r) {
	return (h[r] - h[l - 1] * b[r - l + 1] % m + m) % m;
}

u64 get_h1(int l, int r) {
	return geth(m1, h1, b1, l, r);
}

u64 get_h2(int l, int r) {
	return geth(m2, h2, b2, l, r);
}

u64 getr(u64 m, u64 *h, u64 *b, int l, int r) {
	return (h[l] - h[r + 1] * b[r - l + 1] % m + m) % m;
}

u64 get_r1(int l, int r) {
	return getr(m1, r1, b1, l, r);
}

u64 get_r2(int l, int r) {
	return getr(m2, r2, b2, l, r);
}

bool is_req(int a, int b, int c, int d) {
	return (get_h1(a, b) == get_r1(c, d)) && (get_h2(a, b) == get_r2(c, d));
}

bool check(int n, int len) {
	if (len == n)
		return true;
	while (2 * len - 1 <= n) {
		if (!is_req(1, len, len, 2 * len - 1))
			return false;
		// [1, len] [len, 2 * len - 1]
		len = 2 * len - 1;
	}
	// [*, len] [len, n]
	if (!is_req(2 * len - n, len, len, n))
		return false;
	return true;
}

void Main(int _) {
	_ = _;
	string str;
	cin >> str;
	if (str.size() == 1) {
		cout << "1" << endl;
		return;
	}
	init(str);
	for (size_t i = 2; i <= str.size(); ++i)
		if (check((int)str.size(), i))
			cout << i << " ";
	cout << endl;
}

void Main() {
	init();
	int T;
	cin >> T;
	while (T--)
		Main(T);
}

// -----------------------------------------------------------------------------

signed main() {
//	freopen("string.in", "r", stdin);
//	freopen("string.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	Main();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 27192kb

input:

7
abcdcb
qwqwq
qaqaqqq
carnation
c
ab
aa

output:

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

result:

ok 7 lines

Test #2:

score: 0
Accepted
time: 262ms
memory: 53184kb

input:

5
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...

output:

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 10...

result:

ok 5 lines

Test #3:

score: 0
Accepted
time: 128ms
memory: 53204kb

input:

5
accabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbacca...

output:

1000000 
500005 500012 500019 500026 500033 500040 500047 500054 500061 500068 500075 500082 500089 500096 500103 500110 500117 500124 500131 500138 500145 500152 500159 500166 500173 500180 500187 500194 500201 500208 500215 500222 500229 500236 500243 500250 500257 500264 500271 500278 500285 5002...

result:

ok 5 lines

Test #4:

score: 0
Accepted
time: 138ms
memory: 53240kb

input:

5
wwcunkdbrnrbzqtgvzpnpyrpafjdnznmxpgkzlorbfsayoitnziexcuxhdaxeojdfrpfedyflshjgrewqmanowlybnvfdgkjxaqdfolqgsbpkfncunqimdinqdvujffihvonlzdrtfifmviglyrxdzktdfponuzurnhconwhuepgcxpnxgkafwvkenbrjalbpvfdkbmgidokadxzjjbphzblmccxeqytngyxhndrqrbtxauglwxtxzejbjgizhbmnclwrqojjrcguxnfvmaslhdpqlxruafjeqgvgwfppj...

output:

999995 
500500 501000 501500 502000 502500 503000 503500 504000 504500 505000 505500 506000 506500 507000 507500 508000 508500 509000 509500 510000 510500 511000 511500 512000 512500 513000 513500 514000 514500 515000 515500 516000 516500 517000 517500 518000 518500 519000 519500 520000 520500 52100...

result:

ok 5 lines