Submission #67547482
Source Code Expand
/*
Original Python code:
import sys
import numpy as np
n, m = map(int, input().split())
if n == m:
print(0)
sys.exit()
l = sorted(list(map(int, input().split())))
d = np.zeros(n, dtype=int)
for i in range(n):
if i == 0:
d[i] = 0
else:
d[i] = l[i] - l[i-1]
dp = np.full(m, -1, dtype=int)
dp[0] = 0
for i in d:
if i == 0:
continue
new_dp = np.full(m, dp[0] + i+1, dtype=int)
for j in range(m):
if dp[j] == -1:
break
new_dp[j] = min(new_dp[j], dp[j] + i)
if(j+1 < m):
new_dp[j+1] = min(new_dp[j+1], dp[j])
dp = new_dp
print(dp[-1])
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
if (n == m) {
cout << 0 << endl;
return 0;
}
vector<int> l(n);
for (int i = 0; i < n; i++) {
cin >> l[i];
}
sort(l.begin(), l.end());
vector<int> d(n);
for (int i = 0; i < n; i++) {
if (i == 0) {
d[i] = 0;
} else {
d[i] = l[i] - l[i-1];
}
}
vector<int> dp(m, -1);
dp[0] = 0;
// Python's "for i in d:" iterates over values, not indices
for (int idx = 0; idx < n; idx++) {
int i = d[idx]; // i is the value from array d
if (i == 0) {
continue;
}
vector<int> new_dp(m, dp[0] + i + 1);
for (int j = 0; j < m; j++) {
if (dp[j] == -1) {
break;
}
new_dp[j] = min(new_dp[j], dp[j] + i);
if (j + 1 < m) {
new_dp[j+1] = min(new_dp[j+1], dp[j]);
}
}
dp = new_dp;
}
cout << dp[m-1] << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Transmission Mission |
| User | chachamusics |
| Language | C++ 20 (gcc 12.2) |
| Score | 0 |
| Code Size | 1884 Byte |
| Status | WA |
| Exec Time | 12 ms |
| Memory | 10212 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 400 | ||||||
| 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 |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-01.txt | AC | 1 ms | 3488 KiB |
| 00-sample-02.txt | AC | 1 ms | 3480 KiB |
| 00-sample-03.txt | AC | 1 ms | 3476 KiB |
| 01-01.txt | AC | 1 ms | 3664 KiB |
| 01-02.txt | AC | 1 ms | 3528 KiB |
| 01-03.txt | AC | 1 ms | 3532 KiB |
| 01-04.txt | WA | 1 ms | 3524 KiB |
| 01-05.txt | WA | 1 ms | 3600 KiB |
| 01-06.txt | WA | 1 ms | 3480 KiB |
| 01-07.txt | WA | 11 ms | 9028 KiB |
| 01-08.txt | WA | 11 ms | 8924 KiB |
| 01-09.txt | WA | 10 ms | 8160 KiB |
| 01-10.txt | WA | 8 ms | 7528 KiB |
| 01-11.txt | WA | 11 ms | 10212 KiB |
| 01-12.txt | WA | 6 ms | 6780 KiB |
| 01-13.txt | WA | 11 ms | 8936 KiB |
| 01-14.txt | WA | 7 ms | 5464 KiB |
| 01-15.txt | WA | 12 ms | 10208 KiB |