QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#85097#5690. 背包zlxFTHWA 324ms42416kbC++141.1kb2023-03-06 22:44:312023-03-06 22:44:36

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-06 22:44:36]
  • 评测
  • 测评结果:WA
  • 用时:324ms
  • 内存:42416kb
  • [2023-03-06 22:44:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

const int N = 55;
const int M = 5e6 + 5;
const double eps = 1e-8;

int dcmp(double x) {
  return x < -eps ? -1 : x > eps;
}

LL v[N], c[N];
LL f[M];

void solve() {
  int n, q;
  cin >> n >> q;

  double mx = 0;
  int id = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> v[i] >> c[i];
    double w = double(c[i]) / v[i];
    if (dcmp(w - mx) > 0) mx = w, id = i;
  }

  memset(f, -1, sizeof f);
  f[0] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = v[i]; j <= M - 5; ++j) {
      if (f[j - v[i]] == -1) continue;
      f[j] = max(f[j - v[i]] + c[i], f[j]);
    }
  }

  for (int i = 1; i <= q; ++i) {
    LL V;
    cin >> V;
    LL ti = V / v[id];
    LL ans = -1;
    while (ti >= 0 && V - v[id] * ti <= M - 5) {
      if (f[V - v[id] * ti] != -1) {
        ans = max(ans, c[id] * ti + f[V - v[id] * ti]);
        break;
      }
      --ti;
    }
    cout << ans << "\n";
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) {
    solve();
  } 
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 302ms
memory: 42328kb

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:

811136115447000000
130312175752000000
831238227959000000
711780431949000000
567014385469000000
176643060888000000
532602712803000000
228620751332000000
434289249665000000
964750609099000000
271686175594000000
300113128686000000
853267533241000000
291269801555000000
450299770506000000
440721497066000...

result:

ok 100000 lines

Test #2:

score: 0
Accepted
time: 324ms
memory: 42416kb

input:

50 100000
97830 451823
37513 797833
61527 952574
98951 460952
9982 483106
39784 511945
98493 933482
90672 304557
73232 677587
81302 710167
50101 771645
1815 118770
32519 644183
79650 108103
13496 441661
46853 653992
17707 729081
40996 885010
30757 661427
36297 776622
63656 551419
58205 301706
50404 ...

output:

87402683733488322
48821086339507431
54200141913056370
27277013968053122
47783263639132800
39456586132249193
80866789029835593
63984560456175570
47041442747001970
31332172417359200
89341569089851001
43185914896957361
66381017294811522
71170240573169731
47735901033133922
27793564332294224
352626562721...

result:

ok 100000 lines

Test #3:

score: -100
Wrong Answer
time: 279ms
memory: 42400kb

input:

50 100000
57263 689683
56297 264033
6254 774315
33923 212780
6212 547205
8250 668658
86884 679323
90655 998890
96634 362315
95661 541177
40681 728365
29251 318945
67206 418049
2303 471641
95083 531168
30415 507838
70429 863453
5068 974889
6841 89223
8041 645338
12274 135629
86594 169052
89426 798614...

output:

833769177988112
572090677551067
464406011426906
818311238036803
1003262593101894
1336412154649384
329762173320102
1424282613223876
283137801198865
513200208898777
1637543755241494
1500903213554974
759864122863173
1502802350468135
1231863031805930
446937204389139
830422276738924
896894387150280
19729...

result:

wrong answer 7th lines differ - expected: '329762174052437', found: '329762173320102'