QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#390869 | #4774. Please, go first | I_Love_Sonechka# | AC ✓ | 6ms | 3860kb | C++17 | 872b | 2024-04-16 00:21:44 | 2024-04-16 00:21:46 |
Judging History
answer
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
// c++ short types
#define Int long long
#define vt vector
void solver() {
int n; cin >> n;
string s; cin >> s;
auto calc = [](string s) {
vt<int> data(256, 0), cnt(256, 0);
for(int i = 0; i < (int)s.size(); ++i) {
data[s[i]] = i;
cnt[s[i]]++;
}
int res = 0;
for(int i = 0; i < 256; ++i) {
res += cnt[i] * data[i];
}
return res;
};
vt<int> data(256, 0);
for(int i = 0; i < (int)s.size(); ++i) {
data[s[i]] = i;
}
int res = calc(s);
stable_sort(s.begin(), s.end(), [&](char i, char j) -> bool {
return data[i] < data[j];
});
res -= calc(s);
cout << res * 5 << "\n";
}
int main()
{
ios::sync_with_stdio(false); cin.tie(nullptr);
int tt = 1;
cin >> tt;
for(int t = 0; t < tt; ++t) {
solver();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3860kb
input:
2 6 AABABB 10 Ab9AAb2bC2
output:
15 45
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 6ms
memory: 3720kb
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