結果

問題 No.852 連続部分文字列
ユーザー kuuso1kuuso1
提出日時 2019-07-26 23:26:06
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,348 bytes
コンパイル時間 2,482 ms
コンパイル使用メモリ 111,512 KB
実行使用メモリ 36,128 KB
最終ジャッジ日時 2023-09-15 04:52:54
合計ジャッジ時間 15,074 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
30,844 KB
testcase_01 AC 87 ms
26,332 KB
testcase_02 AC 86 ms
24,384 KB
testcase_03 AC 86 ms
22,336 KB
testcase_04 AC 87 ms
24,320 KB
testcase_05 AC 86 ms
26,448 KB
testcase_06 AC 86 ms
24,500 KB
testcase_07 AC 85 ms
26,320 KB
testcase_08 AC 85 ms
24,208 KB
testcase_09 AC 85 ms
26,428 KB
testcase_10 AC 87 ms
24,424 KB
testcase_11 AC 86 ms
22,472 KB
testcase_12 AC 85 ms
24,376 KB
testcase_13 AC 241 ms
24,684 KB
testcase_14 AC 154 ms
24,732 KB
testcase_15 AC 347 ms
25,912 KB
testcase_16 AC 243 ms
24,644 KB
testcase_17 AC 306 ms
26,732 KB
testcase_18 AC 364 ms
24,620 KB
testcase_19 AC 109 ms
24,432 KB
testcase_20 AC 208 ms
24,584 KB
testcase_21 AC 372 ms
24,748 KB
testcase_22 AC 177 ms
26,644 KB
testcase_23 AC 282 ms
24,764 KB
testcase_24 AC 195 ms
25,872 KB
testcase_25 AC 270 ms
24,836 KB
testcase_26 AC 363 ms
24,756 KB
testcase_27 AC 248 ms
23,504 KB
testcase_28 AC 305 ms
24,800 KB
testcase_29 AC 373 ms
26,652 KB
testcase_30 AC 138 ms
26,580 KB
testcase_31 AC 384 ms
24,712 KB
testcase_32 AC 395 ms
26,772 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;
using System.Diagnostics;
using System.Threading.Tasks;
class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		N = S.Length;
		//double ret = 0;
		//var sw = new Stopwatch();
		//sw.Start();
		//var t0 = sw.ElapsedMilliseconds;
		var ret = new long[26];
		Parallel.For(1,27,len => {
			ret[len - 1] += calc(len);
			//Console.WriteLine("i:{0}, {1} [ms]",i, sw.ElapsedMilliseconds - t0);
		});
		//Console.WriteLine("{0} [ms]",sw.ElapsedMilliseconds - t0);
		double tot = (double) N * (double) (N + 1) / 2.0;
		Console.WriteLine((double) ret.Sum() / tot);
		//Console.WriteLine(ret);
	}
	
	long calc(int len){
		var dl = new Dictionary<char, int>();
		int l = 0;
		var dr = new Dictionary<char, int>();
		int r = 0;
		long 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);
		
		return (long) len * cnt;
		
	}
	
	
	
	
	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