-
1307-C, *1500코드포스 2022. 1. 7. 01:02
Problem - C - Codeforces
codeforces.com
풀이
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647#include <bits/stdc++.h>#define endl "\n"#define ooop(i, n) for(int i = 0; i < n; i++)#define loop(i, n) for(int i = 1; i <= n; i++)#define all(v) (v).begin(), (v).end()using namespace std;typedef long long ll;typedef pair<int, int> pi;typedef pair<ll, ll> pl;ll i_j(int i, int j, map<int, vector<int> >& d){ll ret = 0;for(const auto l: d[i]){ret += d[j].end() - lower_bound(all(d[j]), l);}return ret;}int main(){ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);string s; cin >> s;map<int, vector<int> > d;ooop(i, s.size()) d[s[i]-'a'].emplace_back(i);ll res = 0;for(const auto& [_, v]: d){if(res < v.size()) res = v.size();}if(res == 1) cout << res << endl;else{res = ((res == 2)? 2: res*(res-1)/2);ooop(i, 26){ooop(j, 26){if(i == j) continue;res = max(res, i_j(i, j, d));}}cout << res << endl;}return 0;}cs