QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#346561 | #4774. Please, go first | PetroTarnavskyi# | AC ✓ | 9ms | 3836kb | C++20 | 790b | 2024-03-08 17:50:29 | 2024-03-08 17:50:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
void solve()
{
int n;
cin >> n;
string s;
cin >> s;
map<char, int> last, cnt;
LL ans = 0;
FOR(i, 0, n)
{
last[s[i]] = i;
ans -= cnt[s[i]];
cnt[s[i]]++;
}
FOR(i, 0, n)
ans += last[s[i]] - i;
cout << 5 * ans << "\n";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
input:
2 6 AABABB 10 Ab9AAb2bC2
output:
15 45
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 9ms
memory: 3836kb
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