QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#269656 | #5690. 背包 | myusername# | WA | 11ms | 10224kb | C++14 | 1.2kb | 2023-11-29 20:59:20 | 2023-11-29 20:59:21 |
Judging History
answer
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef pair<LL,int> PLI;
const int N=1e5+9,M=5e6+9;
const LL INF=0x3f3f3f3f3f3f3f3fLL;
int n,Q,v[55],c[55];
int h[N],e[M],ne[M],idx=1; LL val[M];
LL d[N]; bool vis[N];
void add(int a,int b,LL c){
e[idx]=b,val[idx]=c,ne[idx]=h[a],h[a]=idx++;
}
void Dijkstra(){
memset(d,0x3f,sizeof(d));
priority_queue<PLI,vector<PLI>,greater<PLI>> q;
q.push({d[0]=0,0});
while(!q.empty()){
PLI P=q.top(); q.pop();
int u=P.second;
if(vis[u]) continue;
vis[u]=1;
for(int i=h[u];i;i=ne[i]){
int v=e[i];
if(d[u]+val[i]<d[v]){
d[v]=d[u]+val[i];
q.push({d[v],v});
}
}
}
}
int main(){
scanf("%d%d",&n,&Q);
int id=1;
for(int i=1;i<=n;i++){
scanf("%d%d",&v[i],&c[i]);
if((LL)c[i]*v[id]>(LL)c[id]*v[i]) id=i;
}
for(int i=0;i<v[id];i++)
for(int j=1;j<=n;j++) if(j!=id)
add(i,(i+v[j])%v[id],c[j]-(LL)c[id]*((i+v[j])/v[id]));
Dijkstra();
while(Q--){
LL V; scanf("%lld",&V);
int r=V%v[id];
if(d[r]==INF) puts("-1");
else printf("%lld\n",d[r]+(V-r)/v[id]*c[id]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 11ms
memory: 10224kb
input:
50 100000 51305 277520 85830 111973 14837 979296 64100 235055 72474 557263 36773 232129 62774 398759 70740 834677 25120 999531 81191 28056 90133 884467 16462 693203 27057 616092 34713 932782 89420 663734 16437 298828 91123 516501 24430 267003 85485 535000 54839 145786 28114 187135 43791 474768 71273...
output:
811133782249885384 130309842554885384 831235894761885384 711778098751885384 567012052271885384 176640727690885384 532600379605885384 228618418134885384 434286916467885384 964748275901885384 271683842396885384 300110795488885384 853265200043885384 291267468357885384 450297437308885384 440719163868885...
result:
wrong answer 1st lines differ - expected: '811136115447000000', found: '811133782249885384'