結果

問題 No.603 hel__world (2)
ユーザー tailstails
提出日時 2017-12-11 10:00:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 516 ms / 3,000 ms
コード長 1,104 bytes
コンパイル時間 1,712 ms
コンパイル使用メモリ 173,288 KB
実行使用メモリ 38,668 KB
最終ジャッジ日時 2023-08-20 17:30:48
合計ジャッジ時間 11,286 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 200 ms
13,932 KB
testcase_01 AC 200 ms
13,648 KB
testcase_02 AC 200 ms
13,744 KB
testcase_03 AC 200 ms
13,812 KB
testcase_04 AC 200 ms
13,668 KB
testcase_05 AC 202 ms
13,640 KB
testcase_06 AC 209 ms
13,572 KB
testcase_07 AC 201 ms
13,572 KB
testcase_08 AC 203 ms
13,564 KB
testcase_09 AC 200 ms
13,624 KB
testcase_10 AC 201 ms
13,816 KB
testcase_11 AC 319 ms
15,904 KB
testcase_12 AC 320 ms
15,776 KB
testcase_13 AC 322 ms
15,836 KB
testcase_14 AC 202 ms
13,740 KB
testcase_15 AC 201 ms
13,564 KB
testcase_16 AC 200 ms
13,652 KB
testcase_17 AC 200 ms
13,760 KB
testcase_18 AC 203 ms
13,616 KB
testcase_19 AC 199 ms
13,572 KB
testcase_20 AC 259 ms
14,676 KB
testcase_21 AC 257 ms
14,704 KB
testcase_22 AC 207 ms
13,572 KB
testcase_23 AC 202 ms
13,572 KB
testcase_24 AC 215 ms
13,624 KB
testcase_25 AC 453 ms
15,764 KB
testcase_26 AC 455 ms
15,912 KB
testcase_27 AC 452 ms
15,904 KB
testcase_28 AC 516 ms
38,668 KB
testcase_29 AC 264 ms
14,592 KB
testcase_30 AC 232 ms
14,104 KB
testcase_31 AC 203 ms
13,676 KB
testcase_32 AC 259 ms
14,648 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:22:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   22 | main(){
      | ^~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define long long long

#define M 1000003

char T[M];
long S[26],x[M],y[M];
int inv[M],fac[M];
long r=1;
int mc;

void m(long t){
	while(t){
		r=r*fac[t%M]%M;
		t/=M;
		mc+=t;
	}
}

main(){
	fac[0]=1;
	for(int i=1;i<M;++i){
		fac[i]=1ll*fac[i-1]*i%M;
		long e,s=M,t=i,u=1,v=0;
		while(s){
			e=t/s;
			t-=e*s;
			u-=e*v;
			swap(t,s);
			swap(u,v);
		}
		inv[i]=(u+M)%M;
	}
	for(int c=0;c<26;++c)cin>>S[c];
	cin>>T;
	for(int c=0;c<26;++c){
		priority_queue<pair<double,int>> q;
		int n=0,s=0,t=-1;
		for(int i=0;!i||T[i-1];++i){
			if(T[i]==c+'a'){
				if(t<0)t=i;
			}else{
				if(t>=0){
					int xl=i-t;
					x[n]=xl;
					++n;
					s+=xl;
					if(s>S[c])r=0;
					t=-1;
				}
			}
		}
		if(s) {
			long d=S[c]/s;
			for(int j=0;j<n;++j){
				y[j]=x[j]*d;
				q.push(make_pair(1.*~y[j]/x[j],j));
			}
			for(S[c]%=s;S[c]--;){
				int j=q.top().second;q.pop();
				++y[j];
				q.push(make_pair(1.*~y[j]/x[j],j));
			}
			for(int j=0;j<n;++j){
				m(y[j]);
				r=inv[r];mc=-mc;
				m(y[j]-x[j]);
				m(x[j]);
				r=inv[r];mc=-mc;
			}
		}
	}
	cout<<!mc*r;
}
0