QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#53861#2929. Concert Rehearsalabdelrahman001WA 2ms3648kbC++2.4kb2022-10-06 06:11:142022-10-06 06:11:17

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-06 06:11:17]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3648kb
  • [2022-10-06 06:11:14]
  • 提交

answer

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int N = 2e5 + 5;
int n, p, k, a[N], pos[N];
ll sum[N];
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> p >> k;
    for(int i = 1;i <= n;i++) {
        cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
    }
    for(int i = 1;i <= n;i++) {
        int rem = p % sum[n];
        if(sum[n] - sum[i - 1] >= rem) {
            pos[i] = i;
            int low = i, high = n, mid;
            while(low <= high) {
                mid = low + high >> 1;
                if(sum[mid] - sum[i - 1] <= rem)
                    pos[i] = mid, low = mid + 1;
                else
                    high = mid - 1;
            }
        } else {
            pos[i] = n;
            rem -= sum[n] - sum[i - 1];
            int low = 1, high = i - 1, mid;
            while(low <= high) {
                mid = low + high >> 1;
                if(sum[mid] <= rem)
                    pos[i] = mid, low = mid + 1;
                else
                    high = mid - 1;
            }
        }
    }
    int lst = 0;
    set<int> st;
    vector<int> v;
    for(int i = 1;i <= k + 1;i++) {
        int nxt = lst + 1;
        if(nxt == n + 1)
            nxt = 1;
        if(st.count(nxt)) {
            lst = nxt;
            break;
        }
        v.push_back(nxt);
        st.insert(nxt);
        lst = pos[nxt];
    }
    ll cnt = (p / sum[n]) * k * n;
    if(p % sum[n] == 0)
        return cout << cnt / n, 0;
    int rem = 0;
    for(int i = 0;i < v.size();i++) {
        if(v[i] == lst) {
            ll cycLen = v.size() - i;
            cnt += ((k - i) / cycLen) * n;
            rem = (k - i) % cycLen;
            break;
        }
        if(i + 1 < v.size()) {
            if(v[i + 1] < v[i])
                cnt += n - v[i] + v[i + 1];
            else
                cnt += v[i + 1] - v[i];
        }
    }
    lst--;
    while(rem--) {
        int nxt = lst + 1;
        if(nxt == n + 1)
            nxt = 1;
        if(pos[nxt] < nxt)
            cnt += n - nxt + pos[nxt];
        else
            cnt += pos[nxt] - nxt + 1;
        lst = pos[nxt];
    }
    cout << cnt / n;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3548kb

input:

3 20 10
6
9
5

output:

10

result:

ok single line: '10'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

5 11 2
5
5
5
5
5

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3648kb

input:

7 11 3
1
2
3
4
5
6
7

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3552kb

input:

4 8 9
2
7
2
3

output:

4

result:

ok single line: '4'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3640kb

input:

1 3 7
2

output:

14

result:

wrong answer 1st lines differ - expected: '7', found: '14'