QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#187401#6130. Plants vs. Zombiesmicrowave173WA 1ms4196kbC++141.6kb2023-09-24 16:57:302023-09-24 16:57:30

Judging History

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

  • [2023-09-24 16:57:30]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4196kb
  • [2023-09-24 16:57:30]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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'