結果

問題 No.852 連続部分文字列
ユーザー kotatsugamekotatsugame
提出日時 2019-07-27 20:52:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,973 ms / 3,153 ms
コード長 648 bytes
コンパイル時間 575 ms
コンパイル使用メモリ 71,452 KB
実行使用メモリ 110,836 KB
最終ジャッジ日時 2023-09-15 06:42:50
合計ジャッジ時間 30,959 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
54,700 KB
testcase_01 AC 11 ms
54,700 KB
testcase_02 AC 11 ms
54,740 KB
testcase_03 AC 11 ms
54,748 KB
testcase_04 AC 12 ms
54,716 KB
testcase_05 AC 12 ms
54,660 KB
testcase_06 AC 12 ms
54,820 KB
testcase_07 AC 12 ms
54,884 KB
testcase_08 AC 12 ms
54,728 KB
testcase_09 AC 12 ms
54,760 KB
testcase_10 AC 11 ms
54,716 KB
testcase_11 AC 12 ms
54,856 KB
testcase_12 AC 12 ms
54,876 KB
testcase_13 AC 54 ms
54,836 KB
testcase_14 AC 29 ms
54,808 KB
testcase_15 AC 79 ms
55,056 KB
testcase_16 AC 52 ms
54,932 KB
testcase_17 AC 69 ms
54,844 KB
testcase_18 AC 82 ms
54,996 KB
testcase_19 AC 15 ms
54,748 KB
testcase_20 AC 42 ms
54,780 KB
testcase_21 AC 85 ms
55,100 KB
testcase_22 AC 33 ms
54,812 KB
testcase_23 AC 61 ms
54,788 KB
testcase_24 AC 38 ms
54,920 KB
testcase_25 AC 58 ms
54,880 KB
testcase_26 AC 81 ms
55,040 KB
testcase_27 AC 52 ms
54,840 KB
testcase_28 AC 66 ms
54,900 KB
testcase_29 AC 85 ms
54,948 KB
testcase_30 AC 24 ms
54,760 KB
testcase_31 AC 87 ms
54,928 KB
testcase_32 AC 89 ms
54,924 KB
testcase_33 AC 2,500 ms
110,740 KB
testcase_34 AC 2,543 ms
110,788 KB
testcase_35 AC 2,524 ms
110,836 KB
testcase_36 AC 2,491 ms
110,704 KB
testcase_37 AC 2,490 ms
110,704 KB
testcase_38 AC 2,496 ms
110,744 KB
testcase_39 AC 2,519 ms
110,692 KB
testcase_40 AC 2,492 ms
110,776 KB
testcase_41 AC 2,481 ms
110,788 KB
testcase_42 AC 2,973 ms
110,740 KB
testcase_43 AC 1,746 ms
110,804 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    7 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<iomanip>
using namespace std;
string s;
int prv[26][1<<20],now[26];
double ans;
main()
{
	cin>>s;
	for(int i=0;i<26;i++)now[i]=-1;
	for(int i=0;i<s.size();i++)
	{
		for(int j=0;j<26;j++)prv[j][i]=now[j];
		int cnt=1<<s[i]-'a';
		int p=i;
		while(p>=0)
		{
			if(__builtin_popcount(cnt)==26)
			{
				ans+=26*(p+1);
				break;
			}
			int id=-1;
			for(int j=0;j<26;j++)
			{
				if(cnt>>j&1)continue;
				if(id<0||prv[id][p]<prv[j][p])id=j;
			}
			ans+=__builtin_popcount(cnt)*(p-prv[id][p]);
			p=prv[id][p];
			if(id>=0)
			{
				cnt|=1<<id;
			}
		}
		now[s[i]-'a']=i;
	}
	cout<<ans*2/s.size()/(s.size()+1)<<endl;
}
0