Submission #70982113
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using LL = long long;
#define int long long
using pii = pair<int, int>;
#define fi first
#define se second
using mat = array<int, 4>;
constexpr int MAXN = 1 << 22, N = 5e5, mod = 998244353;
int n, X, Y, a[MAXN];
signed main() {
IOS;
cin >> n >> X >> Y;
for (int i = 1; i <= n; ++i) cin >> a[i];
int d = Y - X;
for (int i = 2; i <= n; ++i) {
if (a[i] * X % d != a[1] * X % d) {
cout << "-1\n";
return 0;
}
}
int L = 0, R = 1e18;
for (int i = 1; i <= n; ++i) L = max(L, a[i] * X), R = min(R, a[i] * Y);
if (L > R) {
cout << "-1\n";
return 0;
}
int ans = L + (a[1] * X % d - L % d + d) % d + (R - L - (a[1] * X % d - L % d + d) % d) / d * d;
cout << (LL)(((__int128)n * ans - (__int128)X * accumulate(a + 1, a + 1 + n, 0LL)) / d) << "\n";
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Candy Tribulation |
| User | EnderLwz |
| Language | C++23 (GCC 15.2.0) |
| Score | 350 |
| Code Size | 937 Byte |
| Status | AC |
| Exec Time | 9 ms |
| Memory | 5304 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 350 / 350 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt |
| All | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-01.txt | AC | 1 ms | 3640 KiB |
| 00-sample-02.txt | AC | 1 ms | 3640 KiB |
| 00-sample-03.txt | AC | 1 ms | 3576 KiB |
| 01-01.txt | AC | 5 ms | 4404 KiB |
| 01-02.txt | AC | 2 ms | 3816 KiB |
| 01-03.txt | AC | 5 ms | 4660 KiB |
| 01-04.txt | AC | 6 ms | 4732 KiB |
| 01-05.txt | AC | 6 ms | 5228 KiB |
| 01-06.txt | AC | 9 ms | 5288 KiB |
| 01-07.txt | AC | 9 ms | 5264 KiB |
| 01-08.txt | AC | 9 ms | 5156 KiB |
| 01-09.txt | AC | 9 ms | 5192 KiB |
| 01-10.txt | AC | 9 ms | 5188 KiB |
| 01-11.txt | AC | 9 ms | 5304 KiB |
| 01-12.txt | AC | 9 ms | 5284 KiB |
| 01-13.txt | AC | 6 ms | 4808 KiB |
| 01-14.txt | AC | 9 ms | 5272 KiB |
| 01-15.txt | AC | 9 ms | 5240 KiB |
| 01-16.txt | AC | 8 ms | 5064 KiB |
| 01-17.txt | AC | 9 ms | 5188 KiB |
| 01-18.txt | AC | 9 ms | 5216 KiB |
| 01-19.txt | AC | 8 ms | 4932 KiB |
| 01-20.txt | AC | 9 ms | 5284 KiB |
| 01-21.txt | AC | 9 ms | 5248 KiB |
| 01-22.txt | AC | 8 ms | 5064 KiB |
| 01-23.txt | AC | 9 ms | 5272 KiB |
| 01-24.txt | AC | 9 ms | 5196 KiB |
| 01-25.txt | AC | 7 ms | 4804 KiB |
| 01-26.txt | AC | 5 ms | 4476 KiB |
| 01-27.txt | AC | 7 ms | 4836 KiB |
| 01-28.txt | AC | 7 ms | 4676 KiB |
| 01-29.txt | AC | 8 ms | 5188 KiB |
| 01-30.txt | AC | 9 ms | 5208 KiB |
| 01-31.txt | AC | 6 ms | 4664 KiB |
| 01-32.txt | AC | 9 ms | 5288 KiB |
| 01-33.txt | AC | 9 ms | 5244 KiB |
| 01-34.txt | AC | 7 ms | 4856 KiB |
| 01-35.txt | AC | 9 ms | 5244 KiB |
| 01-36.txt | AC | 9 ms | 5092 KiB |
| 01-37.txt | AC | 5 ms | 4424 KiB |
| 01-38.txt | AC | 9 ms | 5272 KiB |
| 01-39.txt | AC | 9 ms | 5192 KiB |
| 01-40.txt | AC | 7 ms | 4716 KiB |
| 01-41.txt | AC | 6 ms | 4900 KiB |
| 01-42.txt | AC | 5 ms | 4648 KiB |
| 01-43.txt | AC | 9 ms | 5092 KiB |