QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#763202 | #9558. The Devil | as_lyr | WA | 2ms | 6752kb | C++14 | 1.8kb | 2024-11-19 18:52:51 | 2024-11-19 18:52:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 vl;
const int N=130;
const ll base=233327,inbase=960030343680757052,mod=(ll)1e18+3;
int n,m=128;
ll pw[N];
vector <int> e[N*N<<1];
char s[N];
ll hsh[N];
set <ll> st[N][N<<1];
map <ll,char> lst;
map <ll,int> mp;
ll to[N*N<<1];
int nw;
int at[N*N<<1];
bool vis[N*N<<1];
bool dfs(int x){
for(int y:e[x]){
if(vis[y])
continue;
vis[y]=1;
if(at[y]==0||dfs(at[y])){
at[x]=y;
at[y]=x;
return 1;
}
}
return 0;
}
int main(){
scanf("%d",&n);
nw=n;
pw[0]=1;
for(int i=1;i<=m;i++)
pw[i]=(vl)pw[i-1]*base%mod;
for(int T=1;T<=n;T++){
for(int i=0;i<=m;i++)
for(int j=0;j<=2*m;j++)
st[i][j].clear();
st[0][0].insert(0);
int cnt=0;
do{
cnt++;
scanf("%s",s+1);
int len=strlen(s+1);
for(int i=1;i<=len;i++)
hsh[i]=((vl)hsh[i-1]*base+s[i])%mod;
int ct=0;
for(int i=1;ct<m&&i<=2*m;i++){
for(int j=1;ct<m&&j<=len&&j<=i;j++){
for(ll x:st[cnt-1][i-j]){
ll res=((vl)x*pw[j]+hsh[j])%mod;
if(lst.find(res)==lst.end())
lst[res]=s[j];
if(st[cnt][i].find(res)==st[cnt][i].end()){
st[cnt][i].insert(res);
if(++ct==m)
break;
}
}
}
}
}while(getchar()==' ');
for(int i=0;i<=2*m;i++){
for(ll x:st[cnt][i]){
if(mp.find(x)==mp.end()){
mp[x]=++nw;
to[nw]=x;
}
e[T].push_back(mp[x]);
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=nw;j++)
vis[j]=0;
if(dfs(i)==0){
puts("no solution");
return 0;
}
}
for(int i=1;i<=n;i++){
ll x=to[at[i]];
string pr;
while(x){
pr+=lst[x];
x-=lst[x];
if(x<0)
x+=mod;
x=(vl)x*inbase%mod;
}
reverse(pr.begin(),pr.end());
cout<<pr<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6112kb
input:
5 automated teller machine active teller machine active trouble maker always telling misinformation American Teller Machinery
output:
atma atem actm atm ATM
result:
ok len=18
Test #2:
score: 0
Accepted
time: 2ms
memory: 6232kb
input:
5 Forest Conservation Committee Forum Fuming Corruption Collusion Federation Fulsome Cash Concealment Foundation Funky Crony Capitalism Facilitator Funny Cocky Cocky Funny
output:
FCCoF FCCFe FCCFo FCCFa FCCF
result:
ok len=24
Test #3:
score: 0
Accepted
time: 2ms
memory: 6332kb
input:
3 A AA AA A A A A
output:
no solution
result:
ok len=-1
Test #4:
score: 0
Accepted
time: 0ms
memory: 6368kb
input:
2 QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnmertyuiop Q W E R T Y U I O P A S D F G H J K L Z X C V B N M q w e r t y u i o p a s d f g h j k l z x c v b n m j k l z x c v b n m
output:
Q QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnmjklzxcvbnm
result:
ok len=63
Test #5:
score: -100
Wrong Answer
time: 2ms
memory: 6752kb
input:
10 aaa aaa aaa aaa aaa aaa aab aaa aaa aaa aaa aaa aaa aab aaa aaa aaa aaa aab aab aaa aaa aaa aaa a a a a a a ab ab a a a a a a ab ab b a a a a a a aw a a a a a az az a a a a az a a a a a
output:
aaaaaaaaa aaaaaaa aaabaaaaa aaabaaaa aaaaaa aaaaaaaa aabaaaaaa awaaaaa aazaaaa azaaaaa
result:
wrong answer len=77 > ans=76