結果
| 問題 |
No.775 tatyamと素数大富豪(hard)
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2018-12-22 11:54:52 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,944 bytes |
| コンパイル時間 | 1,328 ms |
| コンパイル使用メモリ | 112,208 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-14 01:38:42 |
| 合計ジャッジ時間 | 3,494 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 9 WA * 1 |
ソースコード
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<string, int> Ps;
const ll INF=1e9;
bool comp(string x, string y){
if(x[0]!=y[0]) return x[0]>y[0];
Ps xp, yp;
if(x.size()==1) xp=Ps(x+x, 1);
else xp=Ps(x, 2);
if(y.size()==1) yp=Ps(y+y, 1);
else yp=Ps(y, 2);
return xp>yp;
}
int k;
string b[100];
int ct[10];
ll comb[201][201];
set<string> st;
void zentan(int p){
st.clear();
int c=0;
sort(b, b+p, comp);
while(c<300*k){
string s;
for(int i=0; i<p; i++) s+=b[i];
if(st.size()<k){
st.insert(s);
}else{
auto itr=st.begin();
if((*itr)<s) st.insert(s);
}
c++;
if(!next_permutation(b, b+p, comp)) break;
}
}
int main()
{
int n;
cin>>n>>k;
string a[100];
for(int i=0; i<n; i++){
cin>>a[i];
}
sort(a, a+n, comp);
if(k==1){
for(int i=0; i<n; i++) cout<<a[i];
cout<<endl;
return 0;
}
comb[0][0]=1;
for(int i=1; i<=200; i++){
comb[i][0]=comb[i][i]=1;
for(int j=1; j<i; j++){
comb[i][j]=min(comb[i-1][j-1]+comb[i-1][j], INF);
}
}
for(int i=0; i<n; i++){
for(int j=0; j<a[n-1-i].size(); j++) ct[a[n-1-i][j]-'0']++;
ll ct0=1; int s=0;
for(int j=0; j<10; j++) s+=ct[j];
for(int j=0; j<10; j++){
ct0*=comb[s][ct[j]];
ct0=min(ct0, INF);
s-=ct[j];
}
if(i==n-1 || ct0>=k){
for(int j=n-1-i; j<n; j++){
b[j-(n-1-i)]=a[j];
}
zentan(i+1);
if(st.size()>=k){
auto itr=st.end(); itr--;
string s;
for(int l=0; l<n-1-i; l++) s+=a[l];
int ck=0;
for(; ; itr--){
cout<<s+(*itr)<<endl;
ck++;
if(ck==k) break;
if(itr==st.begin()) break;
}
return 0;
}
}
}
return 0;
}
chocorusk