結果
| 問題 |
No.852 連続部分文字列
|
| コンテスト | |
| ユーザー |
hipopo
|
| 提出日時 | 2020-04-13 19:59:14 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 128 ms / 3,153 ms |
| コード長 | 2,361 bytes |
| コンパイル時間 | 1,488 ms |
| コンパイル使用メモリ | 137,696 KB |
| 最終ジャッジ日時 | 2025-01-09 18:12:18 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
ソースコード
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>
istream& operator >>(istream &is, vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
return is;
}
template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
cout << '(' << p.first << ", " << p.second << ')';
return os;
}
template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }
template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }
template<typename T>
vector<pair<T, int>> rle(const vector<T> &v) {
vector<pair<T, int>> res;
for (int i = 0; i < (int)v.size();) {
int j = i;
while (j < (int)v.size() && v.at(i) == v.at(j)) j++;
res.emplace_back(v.at(i), j - i);
i = j;
}
return res;
}
int main() {
string s;
cin >> s;
ll n = s.size();
ll all = (n + 1) * n / 2;
ll cnt = 0;
for (char c = 'a'; c <= 'z'; c++) {
vector<char> t(n);
bool ok = false;
rep(i, n) {
if (s[i] != c) t[i] = '?';
else {
t[i] = c;
ok = true;
}
}
if (!ok) continue;
auto res = rle(t);
ll cnt_none = 0;
for (auto p: res) if (p.first != c) cnt_none += ll(p.second + 1) * p.second / 2;
cnt += all - cnt_none;
}
double ans = double(cnt) / all;
printf("%.10lf\n", ans);
}
hipopo