QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#410258#7518. GCD of Pattern MatchingSortingWA 1ms3616kbC++201.6kb2024-05-13 20:03:472024-05-13 20:03:48

Judging History

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

  • [2024-05-13 20:03:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3616kb
  • [2024-05-13 20:03:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair < int , int > pii ;
typedef vector < int > vi ;
#define fi first
#define se second
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

ull base ;
string a ;

map < char , ull > w ;
map < char , int > hh ;
bool used[ 36 ] ;

void solve ( ) {
    cin >> base >> a ;
    ull ans = 0 ;
    ull coef = 1 ;
    int n = a.size ( ) ;
    w.clear ( ) ;
    for ( int i = n - 1 ; i >= 0 ; -- i ) {
        w[ a[ i ] ] += coef ;
        coef *= base ;
    }
    if ( base == 2 ) {
        cout << w[ a[ 0 ] ] << "\n" ;
        return ;
    }
    for ( int i = 0 ; i < n ; ++ i ) {
        if ( hh.find ( a[ i ] ) != hh.end ( ) ) { continue ; }
        for ( int j = 0 ; j < base ; ++ j ) {
            if ( j == 0 && i == 0 ) { continue ; }
            if ( used[ j ] == true ) { continue ; }
            hh[ a[ i ] ] = j ;
            used[ j ] = true ;
            break ;
        }
    }
    for ( auto [ c , sm ] : w ) {
        ans += sm * hh[ c ] ;
    }    
    if ( (int)w.size ( ) < base ) { w[ '#' ] = 0 ; }
    for ( auto [ c1 , v1 ] : w ) {
        for ( auto [ c2 , v2 ] : w ) {
            if ( c1 == c2 ) { continue ; }
            if ( v1 > v2 ) { 
                ans = __gcd ( ans , v1 - v2 ) ;
            }
        }
    }
    cout << ans << "\n" ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t = 1 ; cin >> t ;
    while ( t -- ) { solve ( ) ; }
    return 0 ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3576kb

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: 1ms
memory: 3576kb

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: -100
Wrong Answer
time: 0ms
memory: 3616kb

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
4
1
13
111
1229782938247303441

result:

wrong answer 8th numbers differ - expected: '2', found: '4'