結果

問題 No.852 連続部分文字列
ユーザー kuuso1kuuso1
提出日時 2019-07-26 22:23:38
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,994 bytes
コンパイル時間 2,320 ms
コンパイル使用メモリ 106,960 KB
実行使用メモリ 48,256 KB
最終ジャッジ日時 2023-09-15 02:04:33
合計ジャッジ時間 13,825 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
48,256 KB
testcase_01 AC 62 ms
20,452 KB
testcase_02 AC 61 ms
22,556 KB
testcase_03 AC 62 ms
24,484 KB
testcase_04 AC 61 ms
20,500 KB
testcase_05 AC 63 ms
22,592 KB
testcase_06 AC 63 ms
22,504 KB
testcase_07 AC 62 ms
20,504 KB
testcase_08 AC 62 ms
22,500 KB
testcase_09 AC 63 ms
22,492 KB
testcase_10 AC 63 ms
20,544 KB
testcase_11 AC 62 ms
24,604 KB
testcase_12 AC 63 ms
22,656 KB
testcase_13 AC 222 ms
22,524 KB
testcase_14 AC 133 ms
22,628 KB
testcase_15 AC 326 ms
22,508 KB
testcase_16 AC 219 ms
22,616 KB
testcase_17 AC 284 ms
24,560 KB
testcase_18 AC 343 ms
20,528 KB
testcase_19 AC 83 ms
22,560 KB
testcase_20 AC 188 ms
24,644 KB
testcase_21 AC 355 ms
22,656 KB
testcase_22 AC 152 ms
22,508 KB
testcase_23 AC 260 ms
24,616 KB
testcase_24 AC 170 ms
24,532 KB
testcase_25 AC 248 ms
22,508 KB
testcase_26 AC 340 ms
22,504 KB
testcase_27 AC 228 ms
22,500 KB
testcase_28 AC 284 ms
24,612 KB
testcase_29 AC 351 ms
22,428 KB
testcase_30 AC 116 ms
22,500 KB
testcase_31 AC 360 ms
22,512 KB
testcase_32 AC 371 ms
20,604 KB
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 len=1;len<=26;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;
			double ret0 = (double) len * cnt / tot;
		
			ret += ret0;
		}
		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