QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#187401 | #6130. Plants vs. Zombies | microwave173 | WA | 1ms | 4196kb | C++14 | 1.6kb | 2023-09-24 16:57:30 | 2023-09-24 16:57:30 |
Judging History
answer
#include<iostream>
using namespace std;
int n, t;
long long m;
int a[100005];
void init(){
}
bool check(long long int x){
int p = 0;
long long int stp = 0;
long long int val[100005];
for(int i = 0;i < n;i++){
val[i] = 0;
}
while(1){
if(stp > m){ //大了
return false;
}
if(p >= n){ //小了或等于
return true;
}
long long int d = x - val[p];
if(d < 0) d = 0;
int water_tim = d / a[p];
if(d % a[p] > 0) water_tim++;
val[p] += water_tim * a[p];
val[p + 1] += (water_tim - 1) * a[p + 1];
if(2 * water_tim - 1 < 1){
stp += 1;
}
else{
stp += 2 * water_tim - 1;
}
p++;
//cout << d << ' ' << stp << endl;
}
}
void solve(){
long long int l = 0;
long long int r = 10000;
long long int mid;
while(r - l > 1){
//cout << l << ' ' << r << endl;
mid = (l + r)/2;
bool flag = check(mid);
if(flag == false){
r = mid - 1;
}
else{
l = mid;
}
}
//cout << l << ' ' << r << endl;
bool flag_l = check(l);
bool flag_r = check(r);
if(flag_l && flag_r){
cout << r << endl;
}
else if(flag_l && !flag_r){
cout << l << endl;
}
}
int main(){
cin >> t;
while(t--){
cin >> n >> m;
for(int i = 0;i < n;i++){
cin >> a[i];
}
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 4196kb
input:
2 4 8 3 2 6 6 3 9 10 10 1
output:
4 4
result:
wrong answer 1st numbers differ - expected: '6', found: '4'