Submission #49747617
Source Code Expand
#include <iostream>
#include <cstdio>
using namespace std;
#define int long long
const int N = 200010, M = 200010;
int n, m;
int a[N], X[M];
signed main() {
scanf("%lld%lld", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%lld", &X[i]);
}
int ans = 0;
for (int i = 1; i < m; i++) {
int u = X[i], v = X[i + 1];
if(u > v) swap(u, v);
int road1 = v - u, road2 = (n - v) + u;
if(road1 < road2) {
a[u] += road2 - road1; a[v] -= road2 - road1;
} else {
a[v] += road1 - road2; a[1] += road1 - road2; a[u] -= road1 - road2;
}
ans += min(road1, road2);
}
for (int i = 1; i <= n; i++) a[i] += a[i - 1];
int minn = 1e18;
for (int i = 1; i <= n; i++) minn = min(minn, a[i]);
ans += minn;
cout << ans;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Island Tour |
| User | Running_a_way |
| Language | C++ 20 (gcc 12.2) |
| Score | 425 |
| Code Size | 877 Byte |
| Status | AC |
| Exec Time | 19 ms |
| Memory | 7044 KiB |
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:11:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | scanf("%lld%lld", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:13:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
13 | scanf("%lld", &X[i]);
| ~~~~~^~~~~~~~~~~~~~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 425 / 425 | ||||
| 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, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3704 KiB |
| 00_sample_01.txt | AC | 1 ms | 3648 KiB |
| 00_sample_02.txt | AC | 2 ms | 4992 KiB |
| 01_random_00.txt | AC | 3 ms | 5328 KiB |
| 01_random_01.txt | AC | 17 ms | 5984 KiB |
| 01_random_02.txt | AC | 19 ms | 6816 KiB |
| 01_random_03.txt | AC | 13 ms | 5028 KiB |
| 01_random_04.txt | AC | 15 ms | 6484 KiB |
| 01_random_05.txt | AC | 19 ms | 6632 KiB |
| 01_random_06.txt | AC | 19 ms | 6832 KiB |
| 01_random_07.txt | AC | 14 ms | 5384 KiB |
| 01_random_08.txt | AC | 19 ms | 6752 KiB |
| 01_random_09.txt | AC | 19 ms | 6756 KiB |
| 01_random_10.txt | AC | 19 ms | 6780 KiB |
| 01_random_11.txt | AC | 8 ms | 4612 KiB |
| 01_random_12.txt | AC | 14 ms | 6412 KiB |
| 01_random_13.txt | AC | 16 ms | 5380 KiB |
| 01_random_14.txt | AC | 19 ms | 6820 KiB |
| 01_random_15.txt | AC | 9 ms | 6016 KiB |
| 02_random2_00.txt | AC | 12 ms | 6080 KiB |
| 02_random2_01.txt | AC | 2 ms | 5316 KiB |
| 02_random2_02.txt | AC | 14 ms | 5332 KiB |
| 02_random2_03.txt | AC | 16 ms | 7044 KiB |
| 02_random2_04.txt | AC | 5 ms | 4104 KiB |
| 02_random2_05.txt | AC | 11 ms | 6268 KiB |
| 02_random2_06.txt | AC | 15 ms | 6056 KiB |
| 02_random2_07.txt | AC | 16 ms | 6940 KiB |
| 03_handmade_00.txt | AC | 14 ms | 6864 KiB |
| 03_handmade_01.txt | AC | 14 ms | 6860 KiB |
| 03_handmade_02.txt | AC | 1 ms | 3672 KiB |