QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#423439 | #7518. GCD of Pattern Matching | pandapythoner | WA | 0ms | 3656kb | C++17 | 1.4kb | 2024-05-28 02:29:46 | 2024-05-28 02:29:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const ll inf = 1e18;
mt19937 rnd(234);
const ll mod = 1e9 + 7;
typedef complex<flt> base;
const flt pi = atan2(1, 0) * 2;
int32_t main() {
if (1) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int t;
cin >> t;
for (int itr = 0; itr < t; itr += 1) {
int m;
string s;
cin >> m >> s;
reverse(all(s));
string f = s;
sort(all(f));
f.resize(unique(all(f)) - f.begin());
assert((int)f.size() <= m);
int n = (int)s.size();
vector<int> a(n);
for (int i = 0; i < n; i += 1) {
a[i] = lower_bound(all(f), s[i]) - f.begin();
}
vector<int> p(m);
for (int i = 0; i < m; i += 1) {
p[i] = i;
}
unsigned ll rs = 0;
for (ll r = 0; r < 50; r += 1) {
shuffle(all(p), rnd);
if (p[a[0]] == 0) {
continue;
}
unsigned ll x = 0;
for (int i = 0; i < n; i += 1) {
x = x * m + p[a[i]];
}
rs = gcd(rs, x);
}
cout << rs << "\n";
}
return 0;
}
/*
1
16 abcdefghijklmnop
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
input:
5 10 ccpcccpc 10 cpcpcp 10 cpc 4 cpccpc 4 dhcp
output:
10001 10101 1 65 3
result:
ok 5 number(s): "10001 10101 1 65 3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
30 2 ab 3 abc 4 abcd 5 abcde 6 abcdef 7 abcdefg 8 abcdefgh 9 abcdefghi 10 abcdefghij 11 abcdefghijk 12 abcdefghijkl 13 abcdefghijklm 14 abcdefghijklmn 15 abcdefghijklmno 16 abcdefghijklmnop 16 a 16 ab 16 abc 16 abcd 16 abcde 16 abcdef 16 abcdefg 16 abcdefgh 16 abcdefghi 16 abcdefghij 16 abcdefghijk ...
output:
2 1 3 2 5 3 7 4 9 5 11 6 13 7 15 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
result:
ok 30 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
12 10 abccbaabc 10 abcdeedcba 10 abccbaabccba 3 abccbaabccba 4 abcddcba 4 abcddcbaabcddcba 5 online 5 onlie 6 online 3 ccc 10 ccc 16 aaaaaaaaaaaaaaaa
output:
3 11 11000011 2920 15 983055 1 2 1 13 111 1229782938247303441
result:
ok 12 numbers
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3560kb
input:
21 13 abcccbbaccca 11 abcdcdeebdcdca 15 abcdcdeebdcdca 11 abcdcdeebdcacd 15 abcdcdeebdcacd 12 abcdcdeebbae 14 abcbadcbabcd 14 abcbaccbacbb 14 aaaaaabaabbab 10 aaaaabaababbb 9 aaaaabaababb 14 aaaaabaabbaba 10 aaaaabbaabaab 11 aaaaabbabbaabb 14 aaaababbbbbaba 12 aaaabbababbb 12 aaabaabbabab 13 aabaaab...
output:
915 4 4 4 4 5 38221 183 157 79 5740 157 79 516 24326193 1015 665 785 1064 11 1015
result:
wrong answer 1st numbers differ - expected: '183', found: '915'