记录编号 |
212483 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[NOIP吧] 这也叫破译? |
最终得分 |
100 |
用户昵称 |
Riolu |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.418 s |
提交时间 |
2015-12-06 17:30:02 |
内存使用 |
1.07 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int qz[27]={0,4,2,5, 6, 1, 4, 5, 6, 7, 2, 3, 4, 8, 9, 3, 1, 2, 6, 8, 9, 2, 6, 3, 2, 5, 7};
string c[50001];
int data[50001]={0},len[50001];
int heap[50001]={0};
int size=0;
int comp(int a,int b){
if(data[a]<data[b]) return 1;
if(data[a]>data[b]) return 0;
if(len[a]<len[b]) return 1;
if(len[a]>len[b]) return 0;
if(c[a]<c[b]) return 1;
if(c[a]<c[b]) return 0;
return 0;
}
void up(int n){
++size;
int i,j;
j=size>>1;
i=size;
while(i!=1){
if(data[n]<data[heap[j]]) break;
if(data[n]==data[heap[j]] && len[n]<len[heap[j]]) break;
if(data[n]==data[heap[j]] && len[n]==len[heap[j]] && c[n]<c[heap[j]]) break;
heap[i]=heap[j];
i=j;j=i>>1;
}
heap[i]=n;
}
void down(){
cout<<c[heap[1]]<<" "<<data[heap[1]]<<endl;
int key=heap[size--];
int now= 1;
int next= now<<1;
while(next<=size){
if(next+1<=size&& comp(heap[next],heap[next+1])) next++;
if(comp(heap[next],key)) break;
heap[now] =heap[next];
now=next;
next= now<<1;
}
heap[now]=key;
}
int main()
{
freopen("crack.in","r",stdin);
freopen("crack.out","w",stdout);
int n,m,i,j;
cin>>n>>m;
for(i=1;i<=n;i++)
{
cin>>c[i];
len[i]=c[i].size();
for(j=0;j<len[i];j++)
data[i]+=qz[c[i][j]-'a'+1];
up(i);
}
for(i=1;i<=m;i++) down();
}