Submission #74294560
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
int main(){
ll n, k;
cin >> n >> k;
ll mx = 0;
vector<ll> a(n);
rep(i,n){
cin >> a[i];
mx = max(mx, a[i]);
}
for(auto &x : a){
if(mx == x) continue;
ll r = (mx - x) / k;
x += r * k;
}
sort(a.begin(), a.end());
a.erase(unique(a.begin(), a.end()), a.end());
n = a.size();
ll ans = a[n - 1] - a[0];
rep(i,n - 1){
a[i] += k;
ans = min(ans, a[i] - a[i + 1]);
}
cout << ans << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Minimize Range |
| User | jon0920 |
| Language | C++23 (GCC 15.2.0) |
| Score | 400 |
| Code Size | 662 Byte |
| Status | AC |
| Exec Time | 58 ms |
| Memory | 4928 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_01.txt, 00_sample_02.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, 02_01.txt, 02_02.txt, 02_03.txt, 02_04.txt, 02_05.txt, 02_06.txt, 02_07.txt, 02_08.txt, 02_09.txt, 02_10.txt, 02_11.txt, 02_12.txt, 03_01.txt, 03_02.txt, 03_03.txt, 03_04.txt, 03_05.txt, 03_06.txt, 03_07.txt, 03_08.txt, 03_09.txt, 03_10.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_01.txt | AC | 1 ms | 3536 KiB |
| 00_sample_02.txt | AC | 1 ms | 3520 KiB |
| 01_01.txt | AC | 30 ms | 4080 KiB |
| 01_02.txt | AC | 32 ms | 4020 KiB |
| 01_03.txt | AC | 48 ms | 4536 KiB |
| 01_04.txt | AC | 27 ms | 3892 KiB |
| 01_05.txt | AC | 18 ms | 3744 KiB |
| 01_06.txt | AC | 14 ms | 3644 KiB |
| 01_07.txt | AC | 7 ms | 3696 KiB |
| 01_08.txt | AC | 10 ms | 3692 KiB |
| 01_09.txt | AC | 39 ms | 4408 KiB |
| 01_10.txt | AC | 8 ms | 3564 KiB |
| 01_11.txt | AC | 17 ms | 3772 KiB |
| 01_12.txt | AC | 28 ms | 4008 KiB |
| 01_13.txt | AC | 11 ms | 3640 KiB |
| 01_14.txt | AC | 23 ms | 3896 KiB |
| 01_15.txt | AC | 15 ms | 3644 KiB |
| 01_16.txt | AC | 2 ms | 3408 KiB |
| 01_17.txt | AC | 41 ms | 4524 KiB |
| 01_18.txt | AC | 38 ms | 4280 KiB |
| 01_19.txt | AC | 53 ms | 4660 KiB |
| 01_20.txt | AC | 38 ms | 4204 KiB |
| 02_01.txt | AC | 1 ms | 3576 KiB |
| 02_02.txt | AC | 1 ms | 3544 KiB |
| 02_03.txt | AC | 1 ms | 3440 KiB |
| 02_04.txt | AC | 1 ms | 3500 KiB |
| 02_05.txt | AC | 1 ms | 3536 KiB |
| 02_06.txt | AC | 1 ms | 3424 KiB |
| 02_07.txt | AC | 18 ms | 4796 KiB |
| 02_08.txt | AC | 51 ms | 4844 KiB |
| 02_09.txt | AC | 48 ms | 4792 KiB |
| 02_10.txt | AC | 18 ms | 4848 KiB |
| 02_11.txt | AC | 51 ms | 4792 KiB |
| 02_12.txt | AC | 58 ms | 4928 KiB |
| 03_01.txt | AC | 58 ms | 4796 KiB |
| 03_02.txt | AC | 58 ms | 4716 KiB |
| 03_03.txt | AC | 58 ms | 4840 KiB |
| 03_04.txt | AC | 58 ms | 4840 KiB |
| 03_05.txt | AC | 58 ms | 4920 KiB |
| 03_06.txt | AC | 58 ms | 4768 KiB |
| 03_07.txt | AC | 57 ms | 4784 KiB |
| 03_08.txt | AC | 57 ms | 4792 KiB |
| 03_09.txt | AC | 58 ms | 4928 KiB |
| 03_10.txt | AC | 58 ms | 4784 KiB |