QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#661985 | #5137. Tower | Yurily# | WA | 10ms | 3948kb | C++20 | 2.1kb | 2024-10-20 19:46:46 | 2024-10-20 19:46:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAX=505*32;
struct node{
int cnt,v;
};
struct edge{
int v,w;
};
node a[MAX];
int p[MAX],tot,ans,n,m;
vector<edge> g[MAX];
map<int,int> id;
int dis[MAX];
bool vis[MAX];
priority_queue<pair<int,int> > q;
int f[MAX];
void dij(int s){
memset(dis,0x3f,sizeof(dis));
memset(vis,0,sizeof(vis));
dis[s]=0;
q.push(make_pair(0,s));
while(!q.empty()){
int u=q.top().second;q.pop();
if(vis[u])
continue;
vis[u]=1;
for(auto i=g[u].begin();i!=g[u].end();++i){
int v=(*i).v,w=(*i).w;
if(dis[v]>dis[u]+w){
dis[v]=dis[u]+w;
q.push(make_pair(-dis[v],v));
}
}
}
}
bool cmp(node x,node y){
return x.v<y.v;
}
bool cmp2(int x,int y){
return x>y;
}
// ¿ì¶Á
int read(){
int x = 0, f = 1;
char c = getchar();
while(c < '0' || c > '9'){
if(c == '-'){
f = -1;
}
c = getchar();
}
while(c >= '0' && c <= '9'){
x = x*10+c-'0';
c = getchar();
}
return x*f;
}
void solve(){
ans=1e9;
tot=0;
id.clear();
n=read(),m=read();
for(int i=1;i<=n;++i){
p[i]=read();
}
for(int i=1;i<=n;++i){
int cur=p[i];
if(!id[cur]){
a[++tot].v=cur;
a[tot].cnt=1;
id[cur]=tot;
}
else{
a[id[cur]].cnt++;
}
while(cur){
cur>>=1;
if(cur){
if(!id[cur]){
a[++tot].v=cur;
id[cur]=tot;
}
}
}
}
sort(a+1,a+1+tot,cmp);
for(int i=1;i<=tot;++i){
g[i].clear();
}
for(int i=1;i<=tot;++i){
for(int j=1;j<=tot;++j){
if(a[i].v/2==a[j].v){
edge tmp;
tmp.v=i,tmp.w=1;
g[j].push_back(tmp);
break;
}
}
if(i<tot){
edge tmp;
tmp.v=i,tmp.w=a[i+1].v-a[i].v;
g[i+1].push_back(tmp);
}
if(i>1){
edge tmp;
tmp.v=i,tmp.w=a[i].v-a[i-1].v;
g[i-1].push_back(tmp);
}
}
for(int i=1;i<=tot;++i){
dij(i);
int cnt=0;
for(int j=1;j<=tot;++j){
for(int k=1;k<=a[j].cnt;++k){
f[++cnt]=dis[j];
}
}
sort(f+1,f+1+cnt,cmp2);
int res=0;
for(int j=m+1;j<=cnt;++j){
res+=f[j];
}
ans=min(ans,res);
}
printf("%d\n",ans);
}
int main(){
int T;
cin>>T;
while(T--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3948kb
input:
3 2 0 2 6 5 0 1 2 3 4 5 5 3 1 2 3 4 5
output:
2 4 1
result:
ok 3 number(s): "2 4 1"
Test #2:
score: -100
Wrong Answer
time: 10ms
memory: 3928kb
input:
10 272 118 11 14 49 94 71 62 46 45 74 22 15 36 7 37 27 35 96 85 75 78 76 64 23 59 17 35 71 28 96 82 5 66 2 48 57 31 88 10 61 73 79 23 19 52 39 76 48 98 5 39 48 51 90 90 60 27 47 24 24 56 48 27 39 21 38 18 20 9 62 83 47 15 51 22 73 74 7 80 64 60 86 74 59 7 84 38 99 31 42 60 52 41 63 88 59 90 77 40 68...
output:
454 229 870 584 1022 1344 1616 904 1191 652
result:
wrong answer 2nd numbers differ - expected: '3', found: '229'