結果
| 問題 |
No.2419 MMA文字列2
|
| コンテスト | |
| ユーザー |
u-sho
|
| 提出日時 | 2023-08-12 15:16:36 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 73 ms / 2,000 ms |
| コード長 | 1,105 bytes |
| コンパイル時間 | 2,270 ms |
| コンパイル使用メモリ | 198,900 KB |
| 最終ジャッジ日時 | 2025-02-16 06:01:16 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
/* nC2 */
[[nodiscard]] uint64_t comb2(uint64_t n) {
//--------Valid Error------------------
if (n < 2ULL) return 0ULL;
//-------------------------------------
uint64_t retVal;
if (n%2) retVal = n*((n-1ULL)/2ULL);
else retVal = (n/2ULL)*(n-1ULL);
return retVal;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
string S;
cin >> S;
vector<vector<uint>> cco(1, vector<uint>(26, 0));
for (const auto &Si: S){
cco.push_back(cco.back()); // 間に合わなかったらwavelet treeにする
cco.back().at(Si-'A') += 1;
}
// 末尾から、これを3文字目としてMMA文字列を作る個数を数える。
uint64_t ans = 0;
for(uint i = cco.size()-2; i>=2; i--){
const uint Si = S[i]-'A';
for(uint c = 0; c<26; c++){
if (Si == c) continue;
ans += comb2(cco[i][c]);
// if (comb2(cco[i][c])) cout << i << ',' << c << ':' << ans << S[i]<<Si << '\n';
}
}
cout << ans << '\n';
return 0;
}
u-sho