QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#149632#6130. Plants vs. ZombiespootyRE 1ms3488kbC++201.8kb2023-08-25 00:27:552023-08-25 00:27:58

Judging History

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

  • [2023-08-25 00:27:58]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3488kb
  • [2023-08-25 00:27:55]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPL(i,j, n) for (int i = (j); i < (n); i++)
#define int long long
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int MAXX = 1e6;


int solve() {
    int n,m;cin>>n>>m;
    if (m < n) return 0;
    vi arr(n);
    REP(i, n) {
        cin>>arr[i];
    }
    int mx = 1e18;
    int mn = 1e9;
    for (auto x: arr) {
        mn = min(x, mn);
    }
    while (mn < mx) {
        int md = (mn + mx + 1)/2;
        vi farr(n);
        REP(i, n) {
            farr[i] = md/arr[i];
            if (md%arr[i] != 0) {
                farr[i]++;
            }
        }
        bool can = true;
        int needed = 0;
        REP(i, n) { 
            needed += farr[i];
            if (needed > m) {
                can = false;
                mx = md-1;
                break;
            }
        }
        if (!can){
            continue;
        }
        int defneed = needed;
        needed--;
        REPL(i, 1, n) {
            int v = min(farr[i], farr[i-1]);
            farr[i-1] -= v;
            farr[i] -= v;
            if (farr[i-1] > 0) {
                needed += farr[i-1];
                if (needed > m) {
                    can - false;break;
                    mx = md-1;
                }
            }
        }
        if (!can) {
            continue;
        }
        needed += farr[n-1];
        int gg = max(defneed, needed -1);
        if (gg > m) {
            mx = md - 1;
        } else {
            mn = md;
        }
    }
    return mn;
    
}
signed main() {
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t; cin >> t;
    while (t--) {
        cout<<solve()<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3488kb

input:

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

output:

6
4

result:

ok 2 number(s): "6 4"

Test #2:

score: -100
Runtime Error

input:

116
4 0
3 2 6 6
4 1
3 2 6 6
10 19
10 2 8 4 2 4 9 3 3 3
4 8
3 9 3 6
2 19
2 10
11 15
3 1 1 4 3 7 10 8 6 7 10
10 14
8 7 1 1 10 9 2 8 10 7
2 13
2 3
10 10
8 1 6 6 9 4 7 1 8 8
7 14
6 7 4 5 3 1 3
11 6
8 1 10 9 7 2 6 6 1 3 9
4 10
6 1 3 8
7 7
10 6 2 10 4 7 2
5 11
9 10 5 9 2
9 1
2 4 8 6 2 8 8 1 6
4 5
7 2 9 8
...

output:


result: