結果

問題 No.2419 MMA文字列2
ユーザー k82bk82b
提出日時 2023-08-12 14:00:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 4,991 bytes
コンパイル時間 4,690 ms
コンパイル使用メモリ 271,248 KB
実行使用メモリ 29,952 KB
最終ジャッジ日時 2024-11-19 17:01:45
合計ジャッジ時間 6,231 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 2 ms
5,248 KB
testcase_06 AC 2 ms
5,248 KB
testcase_07 AC 2 ms
5,248 KB
testcase_08 AC 2 ms
5,248 KB
testcase_09 AC 2 ms
5,248 KB
testcase_10 AC 2 ms
5,248 KB
testcase_11 AC 2 ms
5,248 KB
testcase_12 AC 11 ms
9,216 KB
testcase_13 AC 3 ms
5,248 KB
testcase_14 AC 21 ms
14,720 KB
testcase_15 AC 13 ms
10,368 KB
testcase_16 AC 21 ms
15,232 KB
testcase_17 AC 7 ms
6,784 KB
testcase_18 AC 23 ms
15,872 KB
testcase_19 AC 23 ms
16,384 KB
testcase_20 AC 8 ms
7,296 KB
testcase_21 AC 6 ms
6,272 KB
testcase_22 AC 38 ms
29,952 KB
testcase_23 AC 38 ms
29,952 KB
testcase_24 AC 38 ms
29,952 KB
testcase_25 AC 39 ms
29,952 KB
testcase_26 AC 6 ms
6,400 KB
testcase_27 AC 38 ms
29,952 KB
testcase_28 AC 42 ms
29,952 KB
testcase_29 AC 43 ms
29,952 KB
testcase_30 AC 43 ms
29,952 KB
testcase_31 AC 43 ms
29,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>

using namespace std;
using namespace atcoder;

#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)

#define sz(x) (int)x.size()
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define fi first
#define se second

#define overload4(a, b, c, d, name, ...) name
#define REP0(n) for(ll _abcde12345 = 0; _abcde12345 < (ll)(n); ++_abcde12345)
#define REP1(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define REP2(i, a, b) for(ll i = (a); i < (ll)(b); ++i)
#define REP3(i, a, b, c) for(ll i = (a); i < (ll)(b); i += (c))
#define rep(...) overload4(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define rrep(i, a, b) for(ll i = (a); i >= (ll)(b); --i)

#define each_for(...) for (auto&& __VA_ARGS__)
#define each_const(...) for (const auto& __VA_ARGS__)

#define yesno(bool) if(bool) { cout << "Yes\n"; } else { cout << "No\n"; }
#define ifelse(bool, x, y) if(bool) { cout << (x) << '\n'; } else { cout << (y) << '\n'; }

#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()

#define fix fixed << setprecision(15)

#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))

#define NP(v) next_permutation(all(v))
#define SORT(v) sort(all(v))
#define SORT2(v) sort(rall(v))
#define REV(v) reverse(all(v))
#define UNIQUE(x) SORT(x), x.erase(unique(all(x)), x.end())
#define SUM(v) accumulate(all(v), 0LL)
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define COUNT(v,x) count(all(v),x)

#define Mod 1000000007
#define mod 998244353

#define inf 1001001001
#define infl 1001002003004005006ll

#define fast ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)

#define drop(x) { cout << (x) << endl; return; }

using ll = long long;
using lint = long long;
using i64 = long long;
using ld = long double;
using Mint = modint1000000007;
using mint = modint998244353;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvvi = vector<vvi>;
using vvvl = vector<vvl>;
using vvvvi = vector<vvvi>;
using vvvvl = vector<vvvl>;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vvvvb = vector<vvvb>;

const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };
const int dx8[] = { 0,1,0,-1,1,-1,1,-1 };
const int dy8[] = { 1,0,-1,0,1,1,-1,-1 };

template<class T>ostream &operator<<(ostream &os,const vector<T> &v)
{
	for(int i=0;i<(int)v.size();++i)
	{
		os<<v[i]<<(i+1!=(int)v.size()?" ":"");
	}
	return os;
}

template<class T>ostream &operator<<(ostream& os,const vector<vector<T>> &v)
{
	for(int i=0;i<(int)v.size();++i)
	{
		for(int j=0;j<(int)v[i].size();++j)
		{
			os<<v[i][j]<<(j+1!=(int)v[i].size()?" ":"");
		}
		os<<(i+1!=(int)v.size()?"\n":"");
	}
	return os;
}

template<class T>istream &operator>>(istream &is,vector<T> &v)
{
	for(T &in:v)is>>in;
	return is;
}

template<class T>istream &operator>>(istream &is,vector<vector<T>> &v)
{
	for(vector<T> &v2:v)for(T &in:v2)is>>in;
	return is;
}

template<class T,class S>inline bool chmax(T& a,const S& b){return(a<b?a=b,1:0);}
template<class T,class S>inline bool chmin(T& a,const S& b){return(a>b?a=b,1:0);}

long long POW(long long A,long long B)
{
	long long ret=1;
	while(B>0)
	{
		if(B&1)ret*=A;
		A*=A;
		B>>=1;
	}
	return ret;
}

long long modpow(long long A,long long B,long long MOD)
{
	long long ret=1;
	while(B>0)
	{
		if(B&1)ret=ret*A%MOD;
		A=A*A%MOD;
		B>>=1;
	}
	return ret;
}

bool is_prime(long long X)
{
	for(long long i=2;i*i<=X;++i)if(X%i==0)return false;
	return true;
}

vector<long long>divisor(long long X)
{
	vector<long long>ret;
	for(long long i=1;i*i<=X;++i)if(X%i==0)
	{
		ret.push_back(i);
		if(i!=X/i)ret.push_back(X/i);
	}
	return ret;
}

vector<long long>prime_factor(long long X)
{
	vector<long long>ret;
	for(long long i=2;i*i<=X;++i)
	{
		while(X%i==0)
		{
			X/=i;
			ret.push_back(i);
		}
	}
	if(X>1)ret.push_back(X);
	return ret;
}

vector<long long>sieve(long long X)
{
	vector<long long>ret;
	vector<bool>F(X+1);
	for(long long i=2;i<=X;++i)if(!F[i])
	{
		ret.push_back(i);
		for(long long j=i+i;j<=X;j+=i)F[j]=true;
	}
	return ret;
}

/**********************************************************************************************************/



void solve();

//#define int long long

signed main()
{
	cin.tie(nullptr)->sync_with_stdio(false);
	cout<<fixed<<setprecision(15);

	int T=1;

	//cin>>T;
	
	rep(T)solve();

	return 0;
}

/////////////////////////////////////////////////////////////



void solve()
{
	string S;cin>>S;
	int N=S.size();
	map<char,int>mp;
	vvi csum(N+1,vi(26));
	rep(i,N)
	{
		csum[i+1][S[i]-'A']+=1;
		rep(j,26)csum[i+1][j]+=csum[i][j];
	}
	long ans=0;
	rep(i,N)
	{
		ans+=mp[S[i]]*(N-i-1-(csum[N][S[i]-'A']-csum[i+1][S[i]-'A']));
		mp[S[i]]++;
	}
	cout<<ans<<endl;
}
0