Submission #70438373


Source Code Expand

#include <bits/stdc++.h>
#define lb(x) (x&-x)
#define L(i,j,k) for(int i=(j);i<=(k);++i)
#define R(i,j,k) for(int i=(j);i>=(k);--i)
#define int long long

namespace luoyh {
using namespace std;
using i64 = long long;

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
void chmin(int &x, int c) { x = min(x, c); }
void chmax(int &x, int c) { x = max(x, c); }

const int maxn = 5e5 + 10, mod = 998244353;
int N, M, C, pcnt, A[maxn]; pii p[maxn];
int x[maxn], pos[maxn], v[maxn];

void solve() {
  cin >> N >> M >> C;
  L (i, 1, N) cin >> A[i];
  sort (A + 1, A + 1 + N);
  for (int i = 1; i <= N; ){
  	int j = i;
  	while (j <= N && A[i] == A[j]) j++;
  	p[pcnt++] = {A[i], j - i}, i = j;
  }
  if (pcnt == 1) return cout << N * M << '\n', void();
  L (i, 0, pcnt - 1) {
  	int pre = p[(i - 1 + pcnt) % pcnt].first, now = p[i].first;
  	x[i] = (now > pre ? now - pre : now - pre + M);
  }
  int S = 0, cur = -1;
  L (i, 0, pcnt - 1) {
  	while (S < C) cur++, S += p[cur % pcnt].second;
  	v[i] = S, S -= p[i % pcnt].second;
  }
  int res = 0; L (i, 0, pcnt - 1) res += v[i] * x[i];
  cout << res << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;
  while (T--)solve();
  return 0;
}
} signed main() {
  return luoyh::main();
}

Submission Info

Submission Time
Task D - On AtCoder Conference
User qazabcdef1111
Language C++ 20 (gcc 12.2)
Score 425
Code Size 1350 Byte
Status AC
Exec Time 76 ms
Memory 23056 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 2
AC × 32
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3476 KiB
example_01.txt AC 1 ms 3456 KiB
hand_00.txt AC 37 ms 7512 KiB
hand_01.txt AC 36 ms 7380 KiB
hand_02.txt AC 75 ms 23056 KiB
hand_03.txt AC 20 ms 7364 KiB
hand_04.txt AC 1 ms 3476 KiB
hand_05.txt AC 1 ms 3436 KiB
random_00.txt AC 35 ms 7392 KiB
random_01.txt AC 34 ms 7392 KiB
random_02.txt AC 38 ms 7320 KiB
random_03.txt AC 52 ms 8196 KiB
random_04.txt AC 54 ms 8712 KiB
random_05.txt AC 53 ms 8320 KiB
random_06.txt AC 65 ms 16340 KiB
random_07.txt AC 66 ms 16056 KiB
random_08.txt AC 66 ms 15408 KiB
random_09.txt AC 42 ms 7316 KiB
random_10.txt AC 38 ms 7440 KiB
random_11.txt AC 40 ms 7424 KiB
random_12.txt AC 40 ms 7308 KiB
random_13.txt AC 49 ms 7508 KiB
random_14.txt AC 48 ms 7364 KiB
random_15.txt AC 40 ms 7432 KiB
random_16.txt AC 55 ms 7484 KiB
random_17.txt AC 57 ms 7564 KiB
random_18.txt AC 43 ms 8568 KiB
random_19.txt AC 62 ms 8448 KiB
random_20.txt AC 61 ms 8296 KiB
random_21.txt AC 61 ms 16220 KiB
random_22.txt AC 74 ms 15252 KiB
random_23.txt AC 76 ms 21672 KiB