QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#650121 | #4774. Please, go first | SGColin# | AC ✓ | 2ms | 4008kb | C++20 | 1.3kb | 2024-10-18 13:11:42 | 2024-10-18 13:11:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline int rd() {
int x = 0;
bool f = 0;
char c = getchar();
for (; !isdigit(c); c = getchar()) f |= (c == '-');
for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return f ? -x : x;
}
#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
const int N = 25000+10;
int n,a[N],cnt[100],lst[100];
char s[N];
int cmp(int a,int b){return a>b;}
inline void work() {
memset(cnt,0,sizeof(cnt));
n=rd();
scanf("%s",s+1);
for(int i=1;i<=n;++i) {
if(s[i]>='0'&&s[i]<='9')
a[i]=s[i]-'0';
else if(s[i]>='a'&&s[i]<='z')
a[i]=s[i]-'a'+10;
else if(s[i]>='A'&&s[i]<='Z')
a[i]=s[i]-'A'+36;
cnt[a[i]]++;
lst[a[i]]=i;
}
sort(cnt,cnt+62,cmp);
int ans=0,sum=0;
for(int i=0;i<62;++i) {
if(cnt[i]==0) break;
sum+=cnt[i];
ans+=(sum-1)*cnt[i];
}
int init=0;
for(int i=1;i<=n;i++) init+=lst[a[i]]-1;
printf("%lld\n",1ll*(init-ans)*5);
}
int main() {
per(t, rd(), 1) work();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3820kb
input:
2 6 AABABB 10 Ab9AAb2bC2
output:
15 45
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 4008kb
input:
30 6 AABABB 10 Ab9AAb2bC2 1 R 2 ba 3 0b0 3 666 11 BACADAEAFAG 33 ooolll444PPyygg99YYIIrrol4Pyg9YIr 50 EJTdfKePfCTUZpcYkQQROhJCaaNBTFAYMRJBclQPnhjUfUCXkR 75 BCCACCBBAACACCBABCAAAACACCACBAACCAACCBAACABBBAACABCBCACCAABCBCCBACBCBAABACA 112 FPHAJBKFKLLAIHENPDOIMLEFEDKFOLJDLAEEBOJMKEMCLAPLDNDAIHFMLPCJKLNF...
output:
15 45 0 0 5 0 50 1650 2255 8780 23365 42580 127740 290425 670250 1568755 3610180 8108515 19000400 34665300 100509020 226220730 510057265 1099335630 0 781179700 1529224115 1338910680 1510221160 1533484180
result:
ok 30 lines