/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Wrong Answer 3ms 324.0 KiB
#3 Wrong Answer 9ms 332.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
    int t;
    cin >> t;
    while (t--) {  
        int n, k, cost = 0;
        cin >> n >> k;
        vector<int> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];
        int i = 0, j = n - 1;
        while (i < n - 1) {
            while (j > i) { 
                int gcd = __gcd(a[i], a[j]);
                if (a[i] / gcd < k) {
                    cost += a[i] / gcd;
                    i = j;  
                    j = n - 1; 
                    break;
                }
                j--;
            }
            if (j == i) break;
        }
        if (k == 1) {
            cout << n - 1 << endl;  
        } else {
            cout << cost << endl;
        }
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1099 Which way to go
Contest
Brain Booster #6
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 17:34:28
Judged At
2024-11-11 02:46:01
Judged By
Score
5
Total Time
9ms
Peak Memory
332.0 KiB