QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#53325#2929. Concert Rehearsalthomas_harmeyerTL 3ms3724kbC++2.1kb2022-10-04 22:29:332022-10-04 22:29:35

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:29:35]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:3724kb
  • [2022-10-04 22:29:33]
  • 提交

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;

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

    for (int left = 0; left < n; left++) {
      while (sum + a[right % n] <= p) {
        sum += a[right % n];
        right++;
      }
      to.emplace_back(right % n, right - left);
      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;
  }();

  // no loop
  if (k < (int)cum.size() - 1) {
    return cum[k].second / n;
  }
//   cout << "cum" << endl;
//   for (auto i : cum) cout << i.first << " " << i.second << endl;
//   cout << "to" << endl;
//   for (auto& [i, j] : to) cout << i << " " << j << endl;

  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;
  // <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: 3ms
memory: 3540kb

input:

3 20 10
6
9
5

output:

10

result:

ok single line: '10'

Test #2:

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

input:

5 11 2
5
5
5
5
5

output:

0

result:

ok single line: '0'

Test #3:

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

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: 0
Accepted
time: 2ms
memory: 3724kb

input:

1 3 7
2

output:

7

result:

ok single line: '7'

Test #6:

score: -100
Time Limit Exceeded

input:

1 1000000000 1000000000
1

output:


result: