QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#111771#5666. Repetitive Elementsxaphoenix#AC ✓3ms3396kbC++142.4kb2023-06-08 17:31:132023-06-08 17:31:17

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-08 17:31:17]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3396kb
  • [2023-06-08 17:31:13]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define LC k<<1
#define RC k<<1|1
#define IO cin.sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,n) for (int i = a; i < n; i++)
#define repn(i,a,n) for (int i = a; i <= n; i++)
#define per(i,a,n) for (int i = (n) - 1; i >= a; i--)
#define pern(i,a,n) for (int i = n; i >= a; i--)

typedef long long LL;
typedef long double LD;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
typedef pair<double, double> PDD;
typedef pair<ull, ull> PUU;
typedef pair<LL, LL> PLL;

const int N = 110000;
const int M = 1100000;
const int mod = 1e9+7;
const int inf = (int)1e9;
const LL INF = 1e18;
const double eps = 1e-9;

mt19937_64 Rand((unsigned long long)new char);
#define rand Rand

struct StringHash {
	// string is 0-index, arrays are 1-index
	string s;
	int n;
	StringHash () {}
	const ull base = 137;
	vector<ull> hsh, rhsh, pw;
	void init(string _s) {
		s = _s;
		n = s.size();
		hsh.resize(n + 2), rhsh.resize(n + 2), pw.resize(n + 2);
		pw[0] = 1;
		rep(i, 1, n + 2) pw[i] = pw[i - 1] * base;
		hsh[0] = rhsh[n + 1] = 0;
		repn(i, 1, n) hsh[i] = hsh[i - 1] * base + s[i - 1] - 'A' + 1;
		pern(i, 1, n) rhsh[i] = rhsh[i + 1] * base + s[i - 1] - 'A' + 1;
	}
	ull get_hsh(int l, int r) {
		ull res;
		if (l <= r) res = hsh[r] - (hsh[l - 1] * pw[r - l + 1]);
		else swap(l, r), res = rhsh[l] - (rhsh[r + 1] * pw[r - l + 1]);
		return res;
	}
	bool check_palindrome(int l, int r) {
		if (l > r) return 1;
		return get_hsh(l, r) == get_hsh(r, l);
	}
	bool check_same(int l1, int r1, int l2, int r2) {
		return get_hsh(l1, r1) == get_hsh(l2, r2);
	}
}A;
int T, n;
string s;
int main() {
	IO;
	cin >> T;
	while (T--) {
		cin >> s;
		A.init(s);
		n = s.size();
		string ans = "";
		repn(i, 1, n) {
			repn(j, i, n) {
				int len = j - i + 1;
				if (len <= ans.size()) continue;
				int flag = 0;
				repn(k, j + 1, n) {
					if (k + len - 1 > n) break;
					if (A.check_same(i, j, k, k + len - 1)) {
						flag = 1;
						break;
					}
				}
				if (flag) ans = s.substr(i - 1, len);
			}
		}
		cout << ans << "\n";
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 3296kb

input:

5
TATCGATCGAGTTGT
TCCGCGAGCGAGTCTCTCCATT
GTTTCATCATACGAGGCCCCATACGCGCTGG
AGATGGGATCCTTATG
GCCCTTAGGCATGGGATGTCGTTTCTTG

output:

ATCG
GCGA
CATACG
GAT
CTT

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 3396kb

input:

50
TTGACAACTTCAGGTTGGCACTCCTTCATTTGGATTTCGGAATAATAGTTTTCTGCTCTGCC
ATCCTATTCGGGGATAGGAGAGATGGGTTGCCGCTATAAAAGCATTTGAACTCCATTTCACTCCGTTGGCTAGGGGTCGCACTG
CCGTAATATAAAGACTCGGAATTCCAATAGCTGCTATTTGCGAGTATGTGACTGAAAACACACCTATAAATATTAGCTGCGTACAAGCTA
ATGGCTGCATGCAGGGTCGACTAGACACACTTTGTCT
TTGAGGATGTCGACGTGTCT...

output:

CTTCA
CATTT
TAGCTGC
TGCA
ACGTG
GCGCCGG
CTCTT
AGTAT
AGAG
ACAG
TAT
TGAC
CTTG
CGTC
TACTGG
GCCGGT
GAA
CAGTA
GCGT
GGTT
CCCT
GAG
TAGAC
GGTGC
GCAGT
TGAG
ATCAA
CCACACA
GAGTC
ATGTA
ATGGTA
TATA
TATGAA
TTCC
CATACG
TACCA
TTAG
GGAATGT
CAGG
GCT
AAG
CTGT
GGAT
TCTTC
AAAAC
ATG
GATAA
TTA
ACATAT
CAAT

result:

ok 50 lines