A

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
using namespace std;

int t, n;

int main() {
ios::sync_with_stdio(0);
cin.tie(0);

cin >> t;
while (t--) {
cin >> n;
if (n & 1) {
cout << 0 << "\n";
} else {
cout << (n / 4) + 1 << "\n";
}
}
return 0;
}

B

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2e5 + 5;

int t, n;
long long a[MAXN];

int main() {
ios::sync_with_stdio(0);
cin.tie(0);

cin >> t;
while (t--) {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];

long long ans = 0;

if (a[1] != -1 && a[n] != -1) {
ans = llabs(a[n] - a[1]);
} else {
ans = 0;
if (a[1] == -1 && a[n] == -1) {
a[1] = 0;
a[n] = 0;
} else if (a[1] == -1) {
a[1] = a[n];
} else {
a[n] = a[1];
}
}

for (int i = 1; i <= n; i++) {
if (a[i] == -1) a[i] = 0;
}

cout << ans << "\n";
for (int i = 1; i <= n; i++) {
if (i > 1) cout << ' ';
cout << a[i];
}
cout << "\n";
}
return 0;
}

Dashboard - Codeforces Round 1071 (Div. 3) - Codeforces

A

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>
using namespace std;

long long k, x;

int main() {
ios::sync_with_stdio(0);
cin.tie(0);

int t;
cin >> t;
while (t--) {
cin >> k >> x;
cout << k * x + 1 << endl;
}
return 0;
}

B

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 200000 + 5;

int t, n;
int a[MAXN];

int main() {
ios::sync_with_stdio(0);
cin.tie(0);

cin >> t;
while (t--) {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];

long long S = 0;
for (int i = 1; i <= n - 1; i++) {
S += llabs((long long)a[i] - a[i + 1]);
}

long long best = 0;

best = max(best, llabs((long long)a[1] - a[2]));
best = max(best, llabs((long long)a[n - 1] - a[n]));

for (int k = 2; k <= n - 1; k++) {
long long left = llabs((long long)a[k - 1] - a[k]);
long long right = llabs((long long)a[k] - a[k + 1]);
long long merged = llabs((long long)a[k - 1] - a[k + 1]);
long long delta = left + right - merged;
best = max(best, delta);
}

cout << (S - best) << "\n";
}
return 0;
}
 

C

题解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 200000 + 5;

int t, n;
long long a[MAXN];

int main() {
ios::sync_with_stdio(0);
cin.tie(0);

cin >> t;
while (t--) {
cin >> n;
long long mn = (1LL << 62);
for (int i = 1; i <= n; i++) {
cin >> a[i];
mn = min(mn, a[i]);
}

long long mindiff = (1LL << 62);
bool ok = true;

for (int i = 1; i <= n; i++) {
if (a[i] == mn) continue;
long long d = a[i] - mn;
mindiff = min(mindiff, d);
if (d <= mn) ok = false;
}

long long ans = mn;
if (ok) ans = mindiff;

cout << ans << "\n";
}
return 0;
}