Submission #48782295
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
// bool in_mass(int x, int y, int w, int h)
// { return x >= 0 && y >= 0 && x < w && y < h; }
// const int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1};
// const int dy[8] = {-1, 1, 0, 0, -1, 1, 1, -1};
int main() {
int n, k;
cin >> n >> k;
vector<int> sc(n, 2);
for(int i = 0; i < k; i++) {
int tmp;
cin >> tmp;
sc[tmp - 1] -= 1;
}
vector<long long> nv;
for(int i = 0; i < n; i++) {
for(int j = 0; j < sc[i]; j++) {
nv.push_back(i);
}
}
long long min_sum = LLONG_MAX;
do {
long long sum = 0;
for(int i = 0; i < (long long)(nv.size() / 2); i++) {
sum += abs(nv[i * 2] - nv[i * 2 + 1]);
}
min_sum = min(min_sum, sum);
} while(next_permutation(nv.begin(), nv.end()));
cout << min_sum << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Socks 2 |
| User | nnth_y |
| Language | C++ 20 (gcc 12.2) |
| Score | 0 |
| Code Size | 938 Byte |
| Status | TLE |
| Exec Time | 2210 ms |
| Memory | 8280 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 350 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 02_consec_00.txt, 02_consec_01.txt, 02_consec_02.txt, 03_segreg_00.txt, 03_segreg_01.txt, 03_segreg_02.txt, 03_segreg_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3596 KiB |
| 00_sample_01.txt | AC | 1 ms | 3528 KiB |
| 00_sample_02.txt | AC | 29 ms | 3460 KiB |
| 01_random_00.txt | TLE | 2207 ms | 8080 KiB |
| 01_random_01.txt | TLE | 2207 ms | 8020 KiB |
| 01_random_02.txt | TLE | 2210 ms | 8044 KiB |
| 01_random_03.txt | TLE | 2207 ms | 8176 KiB |
| 01_random_04.txt | TLE | 2207 ms | 8140 KiB |
| 01_random_05.txt | TLE | 2207 ms | 8028 KiB |
| 01_random_06.txt | TLE | 2207 ms | 8280 KiB |
| 01_random_07.txt | TLE | 2208 ms | 8040 KiB |
| 01_random_08.txt | TLE | 2207 ms | 8180 KiB |
| 01_random_09.txt | TLE | 2207 ms | 8204 KiB |
| 01_random_10.txt | TLE | 2207 ms | 8084 KiB |
| 01_random_11.txt | TLE | 2207 ms | 8108 KiB |
| 01_random_12.txt | TLE | 2207 ms | 6084 KiB |
| 01_random_13.txt | TLE | 2207 ms | 5976 KiB |
| 01_random_14.txt | TLE | 2210 ms | 5988 KiB |
| 01_random_15.txt | TLE | 2207 ms | 6108 KiB |
| 01_random_16.txt | TLE | 2207 ms | 6016 KiB |
| 01_random_17.txt | TLE | 2207 ms | 5944 KiB |
| 02_consec_00.txt | TLE | 2207 ms | 8032 KiB |
| 02_consec_01.txt | TLE | 2208 ms | 8120 KiB |
| 02_consec_02.txt | TLE | 2207 ms | 8048 KiB |
| 03_segreg_00.txt | TLE | 2207 ms | 8124 KiB |
| 03_segreg_01.txt | TLE | 2207 ms | 8272 KiB |
| 03_segreg_02.txt | TLE | 2207 ms | 8120 KiB |
| 03_segreg_03.txt | TLE | 2207 ms | 8108 KiB |