QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116039#4774. Please, go firstmomoyuu#AC ✓1ms3632kbC++17887b2023-06-28 00:43:272023-06-28 00:43:28

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-28 00:43:28]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3632kb
  • [2023-06-28 00:43:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int calc(char c){
    if('a'<=c&&c<='z') return c - 'a';
    else if('A'<=c&&c<='Z') return c - 'A' + 26;
    else return c - '0' + 52;
}


void solve(){
    int n;
    cin>>n;
    ll ans = 0;
    string s;
    cin>>s;
    vector<vector<int>> idx(100);
    vector<int> cnt(100,0);
    for(int i = 0;i<n;i++){
        int now = calc(s[i]);
        idx[now].push_back(i);
        cnt[now]++;
    }
    int ni = 0;
    for(int i = 0;i<n;i++){
        int now = calc(s[i]);
        cnt[now]--;
        if(cnt[now]==0){
            int can = i - ni - idx[now].size()+1;
            ans += idx[now].size() * can;
            ni += idx[now].size();
        }
    }
    ans *= 5;
    cout<<ans<<endl;

}

int main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

详细

Test #1:

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

input:

2
6
AABABB
10
Ab9AAb2bC2

output:

15
45

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 3632kb

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