QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#187433#6130. Plants vs. Zombiesmicrowave173WA 1ms4204kbC++141.4kb2023-09-24 17:16:382023-09-24 17:16:39

Judging History

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

  • [2023-09-24 17:16:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4204kb
  • [2023-09-24 17:16:38]
  • 提交

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(p >= n){  //小了或等于
            return true;
        }
        long long int d = x - val[p];
        if(d < 0) d = 0;

        if(d == 0){
            stp += 1;
            p++;
            continue;
        }

        long long 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];
        stp += 2 * water_tim - 1;
        if(stp > m){  //大了
            return false;
        }
        p++;
        //cout << d << ' ' << stp << endl;
    }
}

void solve(){
    long long int l = 0;
    long long int r = 1e17;
    long long int mid;
    while(r - l > 1){
        //cout << l << ' ' << r << endl;
        mid = (l + r + 1)/2;
        bool flag = check(mid);
        if(flag == false){
            r = mid - 1;
        }
        else{
            l = mid;
        }
    }
    //cout << l << ' ' << r << endl;
    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: 4204kb

input:

2
4 8
3 2 6 6
3 9
10 10 1

output:

6
3

result:

wrong answer 2nd numbers differ - expected: '4', found: '3'