Submission #74313020
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using pii = pair<int,int>;
vector<pii> dir = {
{1, 0}, {-1, 0}, {0, 1}, {0, -1}
};
void solveA () {
int n;
cin >> n;
for (int i = n; i >= 1; i --) {
if (i != 1) cout << i << ",";
else cout << i;
}
cout << endl;
}
void solveB () {
int n;
cin >> n;
auto maze = vector(n + 1, vector<int> (n + 1, -1));
for (int i = 1; i < n; i ++) {
for (int j = i + 1; j <= n; j ++) {
cin >> maze[i][j];
}
}
// debug(maze);
for (int i = 1; i <= n; i ++) {
for (int j = i + 1; j <= n; j ++) {
for (int k = j + 1; k <= n; k ++) {
if (maze[i][j] + maze[j][k] < maze[i][k]) {
// debug(i);
// debug(j);
// debug(k);
cout << "Yes" << endl;
return;
}
}
}
}
cout << "No" << endl;
}
void solveC () {
int h, w;
cin >> h >> w;
int cnt = 0;
auto maze = vector(h + 1, vector<char> (w + 1));
auto vis = vector(h + 1, vector<int> (w + 1));
for (int i = 1; i <= h; i ++) {
for (int j = 1; j <= w; j ++ ){
cin >> maze[i][j];
}
}
// debug(maze);
// debug(vis);
auto bfs = [&] (int xi, int yi) -> int {
queue<pii> que;
que.push({xi, yi});
vis[xi][yi] = 1;
bool ok = false;
while (!que.empty()) {
auto [x, y] = que.front();
que.pop();
for (auto&[dx, dy] : dir) {
int nx = x + dx, ny = y + dy;
if (nx < 1 || nx > h || ny < 1 || ny > w) {
ok = true;
continue;
}
if (vis[nx][ny]) continue;
if (maze[nx][ny] != '.') continue;
que.push({nx, ny});
vis[nx][ny] = 1;
}
}
if (!ok) return 1;
return 0;
};
for (int i = 1; i <= h; i ++) {
for (int j = 1; j <= w; j ++) {
if (maze[i][j] == '.' && !vis[i][j]) {
cnt += bfs(i, j);
}
}
}
// debug(vis);
cout << cnt << endl;
}
void solveD () {
int n, k;
cin >> n >> k;
vector<i64> b(n);
for (int i = 0; i < n; i++) {
i64 x;
cin >> x;
b[i] = x % k;
}
sort(b.begin(), b.end());
for (int i = 0; i < n; i++) {
b.push_back(b[i] + k);
}
i64 ans = LLONG_MAX;
for (int i = 0; i < n; i++) {
ans = min(ans, b[i + n - 1] - b[i]);
}
cout << ans << endl;
}
int main () {
cin.tie(0)->sync_with_stdio(0);
solveD();
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Minimize Range |
| User | PureMilk |
| Language | C++23 (GCC 15.2.0) |
| Score | 400 |
| Code Size | 2420 Byte |
| Status | AC |
| Exec Time | 20 ms |
| Memory | 6552 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 | 3620 KiB |
| 00_sample_02.txt | AC | 1 ms | 3500 KiB |
| 01_01.txt | AC | 10 ms | 4952 KiB |
| 01_02.txt | AC | 11 ms | 4992 KiB |
| 01_03.txt | AC | 17 ms | 5892 KiB |
| 01_04.txt | AC | 10 ms | 4724 KiB |
| 01_05.txt | AC | 7 ms | 4368 KiB |
| 01_06.txt | AC | 5 ms | 4028 KiB |
| 01_07.txt | AC | 3 ms | 3644 KiB |
| 01_08.txt | AC | 4 ms | 3776 KiB |
| 01_09.txt | AC | 14 ms | 5456 KiB |
| 01_10.txt | AC | 3 ms | 3712 KiB |
| 01_11.txt | AC | 6 ms | 4228 KiB |
| 01_12.txt | AC | 10 ms | 4696 KiB |
| 01_13.txt | AC | 4 ms | 3816 KiB |
| 01_14.txt | AC | 8 ms | 4556 KiB |
| 01_15.txt | AC | 6 ms | 4152 KiB |
| 01_16.txt | AC | 1 ms | 3748 KiB |
| 01_17.txt | AC | 15 ms | 5504 KiB |
| 01_18.txt | AC | 13 ms | 5364 KiB |
| 01_19.txt | AC | 19 ms | 6304 KiB |
| 01_20.txt | AC | 14 ms | 5516 KiB |
| 02_01.txt | AC | 1 ms | 3620 KiB |
| 02_02.txt | AC | 1 ms | 3552 KiB |
| 02_03.txt | AC | 1 ms | 3636 KiB |
| 02_04.txt | AC | 1 ms | 3408 KiB |
| 02_05.txt | AC | 1 ms | 3416 KiB |
| 02_06.txt | AC | 1 ms | 3620 KiB |
| 02_07.txt | AC | 7 ms | 6496 KiB |
| 02_08.txt | AC | 11 ms | 6548 KiB |
| 02_09.txt | AC | 10 ms | 6476 KiB |
| 02_10.txt | AC | 7 ms | 6332 KiB |
| 02_11.txt | AC | 11 ms | 6480 KiB |
| 02_12.txt | AC | 20 ms | 6500 KiB |
| 03_01.txt | AC | 20 ms | 6500 KiB |
| 03_02.txt | AC | 20 ms | 6400 KiB |
| 03_03.txt | AC | 20 ms | 6476 KiB |
| 03_04.txt | AC | 20 ms | 6480 KiB |
| 03_05.txt | AC | 20 ms | 6496 KiB |
| 03_06.txt | AC | 20 ms | 6476 KiB |
| 03_07.txt | AC | 20 ms | 6492 KiB |
| 03_08.txt | AC | 20 ms | 6552 KiB |
| 03_09.txt | AC | 20 ms | 6548 KiB |
| 03_10.txt | AC | 20 ms | 6484 KiB |