QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#423442#7518. GCD of Pattern MatchingpandapythonerTL 943ms3856kbC++171.4kb2024-05-28 02:35:202024-05-28 02:35:21

Judging History

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

  • [2024-05-28 02:35:21]
  • 评测
  • 测评结果:TL
  • 用时:943ms
  • 内存:3856kb
  • [2024-05-28 02:35:20]
  • 提交

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;
        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 < 1e5; 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: 24ms
memory: 3844kb

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: 246ms
memory: 3856kb

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: 64ms
memory: 3556kb

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: 0
Accepted
time: 201ms
memory: 3620kb

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:

183
4
4
4
4
1
38221
183
1
1
820
1
1
12
24326193
145
133
157
1064
1
145

result:

ok 21 numbers

Test #5:

score: 0
Accepted
time: 197ms
memory: 3844kb

input:

21
13 acccabbcccba
11 acdcdbeedcdcba
15 acdcdbeedcdcba
11 dcacdbeedcdcba
15 dcacdbeedcdcba
12 eabbeedcdcba
14 dcbabcdabcba
14 bbcabccabcba
14 babbaabaaaaaa
10 bbbabaabaaaaa
9 bbabaabaaaaa
14 ababbaabaaaaa
10 baabaabbaaaaa
11 bbaabbabbaaaaa
14 ababbbbbabaaaa
12 bbbababbaaaa
12 bababbaabaaa
13 bbababa...

output:

915
4
4
4
4
5
38221
183
157
79
5740
157
79
516
24326193
1015
665
785
1064
11
1015

result:

ok 21 numbers

Test #6:

score: 0
Accepted
time: 917ms
memory: 3856kb

input:

96
15 abbbcaacccba
16 cabacaabbccba
16 bcbbaaccabcba
16 bbccaacbabcba
16 bcbabbccaacba
16 abcacbcaccbba
16 accabcbabcbba
15 ccaaabccbbba
15 bbaaabbbbbba
16 abababbbbba
11 abbaabaabbbbba
16 ababbaaabbbbba
16 abbbaaaabbbbba
11 bababaababbbba
11 bababaabbbba
12 aababaabbbba
15 bbaaabbbba
16 aaaabbaaabb...

output:

416
157
157
157
157
157
157
416
416
89
516
1921
731
86
117
1015
176
731
187
665
2011170
516
785
2989355
40543655
63
67
731
731
86
1921
176
1357265
416
1015
416
416
176
785
731
1357265
516
86
63
1015
117
86
516
731
67
665
187
1921
86
516
516
86
665
63
785
187
2011170
1921
89
117
665
2989355
40543655
...

result:

ok 96 numbers

Test #7:

score: 0
Accepted
time: 943ms
memory: 3560kb

input:

96
15 abcccaacbbba
16 abccbbaacabac
16 abcbaccaabbcb
16 abcbabcaaccbb
16 abcaaccbbabcb
16 abbccacbcacba
16 abbcbabcbacca
15 abbbccbaaacc
15 abbbbbbaaabb
16 abbbbbababa
11 abbbbbaabaabba
16 abbbbbaaabbaba
16 abbbbbaaaabbba
11 abbbbabaababab
11 abbbbaababab
12 abbbbaababaa
15 abbbbaaabb
16 abbbbaaabba...

output:

32
1
1
1
1
1
1
32
32
1
12
17
17
2
3
145
16
17
17
133
402234
12
157
2989355
40543655
3
1
17
17
2
17
16
271453
32
145
32
32
16
157
17
271453
12
2
3
145
3
2
12
17
1
133
17
17
2
12
12
2
133
3
157
17
402234
17
1
3
133
2989355
40543655
1
3
145
1
3
157
1
17
3
133
1
2989355
40543655
157
1
3
3
1
157
145
1
3
...

result:

ok 96 numbers

Test #8:

score: -100
Time Limit Exceeded

input:

100000
15 abbbcaacccba
16 cabacaabbccba
16 bcbbaaccabcba
16 bbccaacbabcba
16 bcbabbccaacba
16 abcacbcaccbba
16 accabcbabcbba
15 ccaaabccbbba
15 bbaaabbbbbba
16 abababbbbba
11 abbaabaabbbbba
16 ababbaaabbbbba
16 abbbaaaabbbbba
11 bababaababbbba
11 bababaabbbba
12 aababaabbbba
15 bbaaabbbba
16 aaaabba...

output:


result: