QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#723486 | #6769. Monster Hunter | moyujiang | WA | 6ms | 5208kb | C++14 | 2.9kb | 2024-11-07 22:31:03 | 2024-11-07 22:31:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int64_t a[200005], n, m;
int64_t cnt[5][200005];
array<int64_t, 100005> h, h2;
array<int64_t, 5> b, b2;
void solve(){
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = n + 1; i <= 2 * n; i++) a[i] = a[i - n];
for(int i = 2; i <= 2 * n; i++) a[i] += a[i - 1];
for(int i = 1; i <= 2 * n; i++){
cnt[1][i] = a[i] - a[i - 1] == 1;
cnt[2][i] = a[i] - a[i - 1] == 2;
cnt[3][i] = a[i] - a[i - 1] == 3;
cnt[1][i] += cnt[1][i - 1];
cnt[2][i] += cnt[2][i - 1];
cnt[3][i] += cnt[3][i - 1];
}
cin >> m;
int64_t s = 0;
for(int i = 1; i <= m; i++) cin >> h[i], s += h[i];
int64_t L = 1, R = s + 1;
while(L < R){
int64_t mid = (L + R) / 2;
int64_t dmg = mid / n * a[n] + a[mid % n];
// printf("L = %lld, R = %lld, mid = %lld, dmg = %lld, s = %lld\n", L, R, mid, dmg, s);
if(dmg >= s) R = mid;
else L = mid + 1;
}
int64_t ans = L, cur = L % n;
// printf("ans = %lld\n", ans);
b = {};
b[1] = L / n * cnt[1][n] + cnt[1][L % n];
b[2] = L / n * cnt[2][n] + cnt[2][L % n];
b[3] = L / n * cnt[3][n] + cnt[3][L % n];
sort(&h[1], &h[m + 1]);
h2 = h, b2 = b;
while(1){
// cout << b[1] << ' ' << b[2] << ' ' << b[3] << endl;
bool ok = 1;
for(int i = 1; i <= m; i++){
int need3 = h[i] / 3;
if(need3 <= b[3]) b[3] -= need3;
else need3 = b[3];
h[i] -= need3 * 3;
int need2 = h[i] / 2;
if(need2 <= b[2]) b[2] -= need2;
else need2 = b[2];
h[i] -= need2 * 2;
int need1 = h[i];
if(need1 <= b[1]) b[1] -= need1;
else need1 = b[1];
h[i] -= need1;
if(h[i] > 0){
need2 = (h[i] + 1) / 2;
if(need2 <= b[2]) b[2] -= need2;
else need2 = b[2];
h[i] -= need2 * 2;
}
if(h[i] > 0){
need3 = (h[i] + 2) / 3;
if(need3 <= b[3]) b[3] -= need3;
else need3 = b[3];
h[i] -= need3 * 3;
}
if(h[i] > 0){ ok = 0; break; }
}
if(ok) break;
h = h2;
ans++;
b2[a[cur + 1] - a[cur]]++;
b = b2;
}
cout << ans;
cout << '\n';
}
int main(){
cin.tie(0);
int T;
cin >> T;
while(T--) solve();
return 0;
}
/*
要想次数最少,攻击时伤害值尽可能刚好等于怪物的血量。
依次释放技能攻击第1、2、3、……个怪物,
攻击第i(i>1)个怪物进行某次攻击时,
若前面的怪物有伤害溢出,且本次伤害值为1或2,
就可以考虑交换一次伤害以减少伤害溢出
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5208kb
input:
2 2 3 2 3 2 4 2 5 1 2 3 2 1 2 3 3
output:
4 3
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 6ms
memory: 5204kb
input:
100 21 1 3 3 3 2 3 3 2 2 1 3 2 1 3 2 1 1 1 3 3 3 3 3 3 1 19 1 3 1 1 3 3 1 3 2 3 2 2 3 3 1 1 2 2 2 10 2 2 3 1 5 2 2 5 5 3 8 1 3 3 1 3 2 3 1 3 1 2 1 27 1 1 1 2 1 3 1 2 2 3 3 3 1 1 1 1 2 1 2 2 2 2 3 2 1 3 2 4 5 1 2 2 23 2 1 3 2 3 2 2 3 1 2 1 3 1 2 3 1 3 1 2 2 2 1 1 10 4 3 5 4 5 4 1 4 3 4 8 1 2 1 3 2 3 ...
output:
3 15 3 7 19 12 3 8 7 20 5 10 6 10 3 10 16 1 5 6 10 14 13 8 8 5 13 15 5 10 16 14 10 1 11 4 3 16 5 4 7 8 7 5 13 10 10 10 14 3 9 8 19 16 8 25 11 21 2 3 14 12 4 12 17 22 11 3 14 15 2 9 12 7 3 9 4 9 11 2 2 5 5 3 2 2 4 6 7 10 3 14 2 1 5 4 8 13 14 16
result:
wrong answer 35th lines differ - expected: '10', found: '11'