結果

問題 No.852 連続部分文字列
ユーザー kuuso1
提出日時 2019-07-26 22:20:52
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,992 bytes
コンパイル時間 1,106 ms
コンパイル使用メモリ 117,768 KB
実行使用メモリ 35,304 KB
最終ジャッジ日時 2024-07-02 07:42:40
合計ジャッジ時間 10,968 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 TLE * 1 -- * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		N = S.Length;
		double ret = 0;
		for(int i=1;i<=26;i++){
			ret += calc(i);
		}
		Console.WriteLine(ret);
	}
	
	double calc(int len){
		var dl = new Dictionary<char, int>();
		int l = 0;
		var dr = new Dictionary<char, int>();
		int r = 0;
		double cnt = 0;
		for(int i=0;i<N;i++){
			if(l < i) l = i;
			if(r < i) r = i;
			while(l < N){
				if(dl.ContainsKey(S[l])){
					dl[S[l]]++;
					l++;
					continue;
				}
				if(dl.Count < len - 1){
					dl.Add(S[l], 1);
					l++;
					continue;
				}
				break;
			}
			while(r < N){
				if(dr.ContainsKey(S[r])){
					dr[S[r]]++;
					r++;
					continue;
				}
				if(dr.Count < len){
					dr.Add(S[r], 1);
					r++;
					continue;
				}
				break;
			}
			if(dr.Count == len){
				cnt += r - l;
			}
			if(dl.ContainsKey(S[i])){
				dl[S[i]]--;
				if(dl[S[i]] == 0) dl.Remove(S[i]);
			}
			if(dr.ContainsKey(S[i])){
				dr[S[i]]--;
				if(dr[S[i]] == 0) dr.Remove(S[i]);
			}
		}
		//Console.WriteLine("len:{0}, cnt:{1}",len, cnt);
		
		double tot = (double) N * (double) (N + 1) / 2.0;
		return (double) len * cnt / tot;
		
	}
	
	
	
	
	int N;
	String S;
	public Sol(){
		S = rs();
		
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0