QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#53330#2929. Concert Rehearsalthomas_harmeyerWA 2ms3676kbC++2.4kb2022-10-04 22:56:012022-10-04 22:56:03

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-04 22:56:03]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3676kb
  • [2022-10-04 22:56:01]
  • 提交

answer

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define repo(i, b) for (int i = 0; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, long long> pii;
typedef vector<int> vi;

ll solve() {
  // input
  int n;  // num of players
  int p;  // day length
  int k;  // num of days
  cin >> n >> p >> k;
  vi a(n);  // players

  for (auto& i : a) cin >> i;

  vi cuma = [&]() -> vi {
    vi cum;
    cum.push_back(0);
    int repeat = 2;
    while (repeat--) {
      for (int i : a) {
        cum.push_back(cum[sz(cum) - 1] + i);
      }
    }
    return cum;
  }();

  // [starting] = <where you end up, number of players>
  vector<pii> to = [&]() {
    vector<pii> to;
    ll sum = a[0];

    for (int left = 0; left < n; left++) {
      ll lo = 0, diff = (1LL) << 34LL;
      while (diff > 0) {
        auto check = [&](ll x) {
          ll ans = (x / n) * cuma[n];
          ans += cuma[left + (x % n)] - cuma[left];
          return ans <= p;
        };
        if (check(lo + diff)) {
          lo += diff;
        }
        diff /= 2;
      }

      to.emplace_back(lo % n, lo);
      sum -= a[left];
    }
    return to;
  }();

  pii loop;
  // [after i days] = <next index to play, number of students to play total>
  vector<pii> cum = [&]() {
    vector<pii> cum;
    vector<int> vist(n, -1);
    pii cur(0, 0);

    cum.push_back(cur);
    while (vist[cur.first] == -1) {
      vist[cur.first] = (int)cum.size() - 1;
      cur.second += to[cur.first].second;
      cur.first = to[cur.first].first;

      cum.push_back(cur);
    }
    loop = make_pair(vist[cur.first], cum.size() - 1);
    return cum;
  }();

  auto ans = [&]() {
    // no loop
    if (k < (int)cum.size() - 1) {
      return cum[k].second / n;
    }
    ll ans = cum[cum.size() - 1].second;
    k -= (int)cum.size() - 1;
    ll loopVal = cum[loop.second].second - cum[loop.first].second;
    ll loopSize = loop.second - loop.first;
    ans += loopVal * (k / loopSize);
    ans += cum[loop.first + (k % loopSize)].second - cum[loop.first].second;
    return ans / n;
  }();

  return ans;
  // <size of loop, num of students in loop>
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  cout << solve();
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3556kb

input:

3 20 10
6
9
5

output:

10

result:

ok single line: '10'

Test #2:

score: 0
Accepted
time: 2ms
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: 3676kb

input:

7 11 3
1
2
3
4
5
6
7

output:

1

result:

ok single line: '1'

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 3648kb

input:

4 8 9
2
7
2
3

output:

2

result:

wrong answer 1st lines differ - expected: '4', found: '2'