結果
問題 | No.2419 MMA文字列2 |
ユーザー |
|
提出日時 | 2023-07-22 17:51:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 83 ms / 2,000 ms |
コード長 | 1,619 bytes |
コンパイル時間 | 7,859 ms |
コンパイル使用メモリ | 415,000 KB |
最終ジャッジ日時 | 2025-02-15 18:04:54 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
// clang-format off#include <bits/stdc++.h>#include <iterator>#include <atcoder/all>#include <boost/multiprecision/cpp_int.hpp>#include <boost/multiprecision/integer.hpp>typedef long long int ll;#define FOR(i,a,b) for(ll i=(a);i<(b);i++)#define REP(i,n) for(ll i=0;i<signed(n);i++)#define EREP(i,n) for(ll i=1;i<=signed(n);i++)#define ALL(x) std::begin(x), std::end(x)using namespace std;using namespace atcoder;using boost::multiprecision::cpp_int;namespace mp = boost::multiprecision;//#define EVEL 1#ifdef EVEL#define DEB(X) cout << #X <<":" <<X<<" " ;#define TF(f) f ? cout<<"true " : cout<<"false ";#define END cout<<"\n";#else#define DEB(X) {}#define TF(f) {}#define END {}#endifconst ll INF = 9e18;typedef std::pair<ll, ll> P;struct edge { ll to, cost; };#define VMAX 100000template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }template <class T> T vgcd(T m, T n) {return std::gcd(m, n);}template <class T, class... Args> T vgcd(T a, Args... args) {return vgcd(a, vgcd(args...));}// clang-format onint dx[]={1,-1,0,0};int dy[]={0,0,1,-1};int main(void) {ll ans = 0;ll N;string S;cin>>S;N=S.size();reverse(ALL(S));vector<vector<ll>> A(N+1,vector<ll>(26));REP(i,N){A[i+1][S[i]-'A']++;}REP(i,N){REP(j,26){A[i+1][j]+=A[i][j];}}REP(i,N-2){REP(j,26){if(j+'A'==S[i])continue;ans+=(A[N][j] - A[i][j]) * (A[N][j] - A[i][j]-1)/2;}}cout<<ans<<endl;}