結果
| 問題 |
No.852 連続部分文字列
|
| コンテスト | |
| ユーザー |
tarattata1
|
| 提出日時 | 2019-07-26 22:23:14 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 3,153 ms |
| コード長 | 1,236 bytes |
| コンパイル時間 | 818 ms |
| コンパイル使用メモリ | 81,100 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-02 07:43:55 |
| 合計ジャッジ時間 | 2,978 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:29:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | scanf("%s", str);
| ~~~~~^~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;
char str[1000005];
int main(int argc, char* argv[])
{
scanf("%s", str);
map<char,int> z;
map<char,double> val;
int len=strlen(str);
int i;
for(i=0; i<len; i++) {
auto it = z.find(str[i]);
int tmp=0;
if(it!=z.end()) {
tmp=it->second+1;
}
if(i-tmp>0) {
val[str[i]] += (double)(i-tmp)*(i-tmp+1)/2;
}
z[str[i]]=i;
}
double ans=0;
auto it=z.begin();
for(; it!=z.end(); ++it) {
int tmp=it->second+1;
if(len-tmp>0) {
val[it->first] += (double)(len-tmp)*(len-tmp+1)/2;
}
ans += ((double)len*(len+1)/2-val[it->first]);
}
printf("%.10lf\n", ans / ((double)len*(len+1)/2) );
return 0;
}
tarattata1