結果
| 問題 |
No.603 hel__world (2)
|
| コンテスト | |
| ユーザー |
kmjp
|
| 提出日時 | 2017-12-03 21:37:00 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,092 bytes |
| コンパイル時間 | 1,745 ms |
| コンパイル使用メモリ | 174,520 KB |
| 実行使用メモリ | 12,964 KB |
| 最終ジャッジ日時 | 2024-11-28 14:42:33 |
| 合計ジャッジ時間 | 4,461 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 RE * 11 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
ll S[30];
string T;
int L;
vector<int> V[26];
int num[26];
ll mo=1000003;
struct comp {
bool operator()(const pair<pair<ll,ll>,pair<ll,ll>> a, const pair<pair<ll,ll>,pair<ll,ll>> b) const {
return a.first.first*b.first.second < a.first.second*b.first.first;
}
};
__int128 hoge(ll s,vector<int> p) {
if(p.empty()) return 1;
sort(ALL(p));
__int128 ss=s;
if(s>10000000) {
if(p.size()==1) {
if(p[0]==1) return s%mo;
if(p[0]==2) return ss*(ss-1)/2%mo;
}
if(p.size()==2 && p[0]==1 && p[1]==1) return (ss/2)*(ss-ss/2)%mo;
return 1LL<<62;
}
__int128 pat=1;
priority_queue<pair<pair<ll,ll>,pair<ll,ll>>,vector<pair<pair<ll,ll>,pair<ll,ll>>>,comp> Q;
FORR(r,p) s-=r, Q.push(make_pair(make_pair(r+1,1),make_pair(r,r)));
while(s--) {
auto r=Q.top();
Q.pop();
pat=pat * r.first.first / r.first.second;
if(pat>=1LL<<62) return pat;
r.second.first++;
Q.push(make_pair(make_pair(r.second.first+1,r.second.first+1-r.second.second),r.second));
}
return pat%mo;
}
void solve() {
int i,j,k,l,r,x,y; string s;
FOR(i,26) cin>>S[i];
cin>>T;
L=T.size();
V[T[0]-'a'].push_back(1);
FOR(i,L-1) {
if(T[i]==T[i+1]) V[T[i+1]-'a'].back()++;
else V[T[i+1]-'a'].push_back(1);
}
FOR(i,L) num[T[i]-'a']++;
__int128 ret=1;
FOR(i,26) if(num[i]>S[i]) return _P("0\n");
FOR(i,26) {
__int128 pat=hoge(S[i],V[i]);
assert(pat<1LL<<62);
(ret*=pat)%=mo;
}
cout<<(ll)ret<<endl;
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
kmjp