QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#708533 | #7518. GCD of Pattern Matching | Deltax | WA | 0ms | 3944kb | C++14 | 1.3kb | 2024-11-03 23:15:03 | 2024-11-03 23:15:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mkp make_pair
#define pb push_back
typedef pair <int, int> pii;
typedef unsigned long long ull;
inline int read() {
int x = 0, f = 0;
char c = getchar();
while (!isdigit(c)) {if (c == '-') f = 1; c = getchar();}
while (isdigit(c)) x = (x << 1) + (x << 3) + (c & 15), c = getchar();
return f? -x : x;
}
ull sum[30];
template <class T>
T gcd(T a, T b) {return b? gcd(b, a % b) : a;}
template <class T>
inline T sub(T x, T y) {return x > y? x - y : y - x;}
int main() {
int T = read();
while (T--) {
int m, p;
m = read();
static char str[20];
scanf("%s", str + 1);
p = strlen(str + 1);
ull t = 1;
for (int i = 1; i <= p; ++i) {
sum[str[i] - 'a'] += t;
t = t * m;
}
ull ss = 0;
int cnt = 0;
for (int i = 0; i < 26; ++i)
if (sum[i]) ss += sum[i] * cnt, ++cnt;
ull d = 0;
/*
if (cnt < m) {
for (int i = 0; i < 26; ++i)
if (sum[i]) d = gcd(d, sum[i]);
}
else {*/
ull pre = 0;
for (int i = 0; i < 26; ++i) {
if (sum[i]) {
if (pre) d = gcd(d, sub(sum[i], pre));
pre = sum[i];
}
}
d = gcd(d, ss);
// }
for (int i = 0; i < 26; ++i) sum[i] = 0;
printf("%llu\n", d);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3856kb
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: -100
Wrong Answer
time: 0ms
memory: 3944kb
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:
1 1 3 2 5 3 7 4 9 5 11 6 13 7 15 0 1 3 3 5 15 3 1 3 15 5 3 3 1 15
result:
wrong answer 1st numbers differ - expected: '2', found: '1'