結果

問題 No.852 連続部分文字列
ユーザー kuuso1kuuso1
提出日時 2019-07-26 23:47:53
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 950 ms / 3,153 ms
コード長 1,923 bytes
コンパイル時間 3,262 ms
コンパイル使用メモリ 104,504 KB
実行使用メモリ 28,028 KB
最終ジャッジ日時 2023-09-15 05:09:45
合計ジャッジ時間 17,135 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
22,564 KB
testcase_01 AC 57 ms
22,616 KB
testcase_02 AC 58 ms
22,472 KB
testcase_03 AC 57 ms
22,476 KB
testcase_04 AC 58 ms
24,628 KB
testcase_05 AC 58 ms
24,568 KB
testcase_06 AC 59 ms
22,676 KB
testcase_07 AC 58 ms
24,612 KB
testcase_08 AC 58 ms
22,512 KB
testcase_09 AC 58 ms
22,628 KB
testcase_10 AC 57 ms
22,564 KB
testcase_11 AC 57 ms
20,464 KB
testcase_12 AC 58 ms
22,560 KB
testcase_13 AC 73 ms
22,472 KB
testcase_14 AC 67 ms
22,576 KB
testcase_15 AC 84 ms
24,548 KB
testcase_16 AC 74 ms
24,492 KB
testcase_17 AC 80 ms
22,492 KB
testcase_18 AC 85 ms
22,396 KB
testcase_19 AC 59 ms
24,504 KB
testcase_20 AC 70 ms
22,552 KB
testcase_21 AC 86 ms
22,420 KB
testcase_22 AC 68 ms
22,520 KB
testcase_23 AC 78 ms
22,396 KB
testcase_24 AC 70 ms
22,556 KB
testcase_25 AC 77 ms
24,480 KB
testcase_26 AC 85 ms
22,516 KB
testcase_27 AC 74 ms
22,484 KB
testcase_28 AC 80 ms
24,680 KB
testcase_29 AC 86 ms
24,732 KB
testcase_30 AC 63 ms
22,576 KB
testcase_31 AC 88 ms
22,440 KB
testcase_32 AC 89 ms
24,548 KB
testcase_33 AC 950 ms
25,832 KB
testcase_34 AC 943 ms
25,960 KB
testcase_35 AC 945 ms
25,896 KB
testcase_36 AC 946 ms
27,928 KB
testcase_37 AC 944 ms
27,848 KB
testcase_38 AC 944 ms
27,944 KB
testcase_39 AC 945 ms
25,816 KB
testcase_40 AC 944 ms
26,044 KB
testcase_41 AC 944 ms
25,824 KB
testcase_42 AC 659 ms
27,916 KB
testcase_43 AC 813 ms
28,028 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 int[256];
		int l = 0, lcnt = 0;
		var dr = new int[256];
		int r = 0, rcnt = 0;
		double cnt = 0;
		for(int i=0;i<N;i++){
			if(l < i) l = i;
			while(l < N){
				if(dl[S[l]] > 0){
					dl[S[l]]++;
					l++;
					continue;
				}
				if(lcnt < len - 1){
					dl[S[l]] = 1;
					l++;
					lcnt++;
					continue;
				}
				break;
			}
			while(r < N){
				if(dr[S[r]] > 0){
					dr[S[r]]++;
					r++;
					continue;
				}
				if(rcnt < len){
					dr[S[r]] = 1;
					r++;
					rcnt++;
					continue;
				}
				break;
			}
			if(rcnt == len){
				cnt += r - l;
			}
			if(dl[S[i]] > 0){
				dl[S[i]]--;
				if(dl[S[i]] == 0) lcnt--;
			}
			if(dr[S[i]] > 0){
				dr[S[i]]--;
				if(dr[S[i]] == 0) rcnt--;
			}
		}
		//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