Task: | Kemija |
Sender: | henrikaalto |
Submission time: | 2019-07-30 00:22:39 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 100 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.01 s | details |
#3 | ACCEPTED | 0.01 s | details |
#4 | ACCEPTED | 0.01 s | details |
#5 | ACCEPTED | 0.01 s | details |
#6 | ACCEPTED | 0.01 s | details |
#7 | ACCEPTED | 0.01 s | details |
#8 | ACCEPTED | 0.01 s | details |
#9 | ACCEPTED | 0.01 s | details |
#10 | ACCEPTED | 0.01 s | details |
Code
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(),x.end() #define debug(...) " [" << #__VA_ARGS__ << ": " << (__VA_ARGS__) << "] " const int inf = 1e9; using ii=long long; int main() { int n; ii s; cin >> n; vector<ii> v(n); for (int i = 0; i < n; ++i) { cin >> v[i]; } s = accumulate(all(v), 0l) / 3; #define ind(x) ((x+n)%n) vector<ii> dd(n); for (int i = 0; i < n; ++i) { dd[i] = v[ind(i+2)] - v[ind(i+1)]; } vector<ii> lol(n); if (n % 3) { for (ii i = 0, it = 0, z = 0; i < n; ++i) { lol[it] = z; z += dd[it]; it = ind(it + 3); } ii t = accumulate(all(lol), 0l); // s = r_1 + r_2 + r_3 + r_4 .. r_n // s = (r_1 + lol_1) + (r_2 + lol_2) ... + (r_n + lol_n) // s = n * r_1 + \SUMMA(lol_i) // s = n * r_1 + t // (s - t) / n = r_1 ii y = (s - t) / n; for (int i = 0; i < n; ++i) { cout << y + lol[i] << "\n"; } } else { // x = r_0 // y = r_1 // z = r_2 // v_1 = x + y + z // r_1, r_2, r_3, r_4, r_5, r_6 = a_1, b_1, c_1, a_2, b_2, c_2 // x = a_1 // y = a_2 // z = a_3 // v_{3n+1} = a_{n+1} + b_{n+1} + c_{n+1} // \SUMMA(a_i + b_i + c_i) = s // \SUMMA(a_i) + \SUMMA(b_i) + \SUMMA(c_i) = s // \SUMMA(a_i) = a_1 * (n / 3) + \SUMMA(alol_i) // g = \SUMMA(alol_i) // h = \SUMMA(blol_i) // k = \SUMMA(clol_i) // s = x * n / 3 + g + y * n / 3 + h + z * n / 3 + k // s = (n / 3) * (x + y + z) + (g + h + k) // x + y + z = (s - g - h - k) / (n / 3) for (ii i = 0, it = 0, z[] = {0, 0, 0}; i < n; i += 3) { lol[it] = z[0]; lol[it + 1] = z[1]; lol[it + 2] = z[2]; z[0] += dd[it]; z[1] += dd[it + 1]; z[2] += dd[it + 2]; it = ind(it + 3); } ii t[3] = {0, 0, 0}; for (int i = 0; i < n; i += 3) { t[0] += lol[i]; t[1] += lol[i + 1]; t[2] += lol[i + 2]; } ii mi[] = {inf, inf, inf}; for (int i = 0; i < n; i += 3) { mi[0] = min(mi[0], lol[i]); mi[1] = min(mi[1], lol[i + 1]); mi[2] = min(mi[2], lol[i + 2]); } ii asd = (s - t[0] - t[1] - t[2]) / (n / 3); ii x = max<ii>(1, -mi[0] + 1); ii y = max<ii>(1, -mi[1] + 1); ii z = asd - x - y; for (int i = 0; i < n; i += 3) { cout << x + lol[i] << "\n"; cout << y + lol[i + 1] << "\n"; cout << z + lol[i + 2] << "\n"; } } }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
3
53 53 53 |
correct output |
---|
1
1 51 |
user output |
---|
1 1 51 |
Test 2
Verdict: ACCEPTED
input |
---|
5
8 9 12 9 ... |
correct output |
---|
1
5 3 4 2 |
user output |
---|
1 5 3 4 2 |
Test 3
Verdict: ACCEPTED
input |
---|
7
8 4 8 10 ... |
correct output |
---|
1
2 1 5 4 ... |
user output |
---|
1 2 1 5 4 ... |
Test 4
Verdict: ACCEPTED
input |
---|
9
6 10 11 13 ... |
correct output |
---|
1
3 6 2 5 ... |
user output |
---|
1 3 6 2 5 ... |
Test 5
Verdict: ACCEPTED
input |
---|
11
14 15 15 12 ... |
correct output |
---|
2
9 4 2 6 ... |
user output |
---|
2 9 4 2 6 ... |
Test 6
Verdict: ACCEPTED
input |
---|
43
49 43 27 20 ... |
correct output |
---|
17
20 6 1 13 ... |
user output |
---|
17 20 6 1 13 ... Truncated |
Test 7
Verdict: ACCEPTED
input |
---|
99
61 55 64 67 ... |
correct output |
---|
10
20 25 19 23 ... |
user output |
---|
10 20 25 19 23 ... Truncated |
Test 8
Verdict: ACCEPTED
input |
---|
500
34234 24097 6848 24240 ... |
correct output |
---|
18019
5147 931 770 22539 ... |
user output |
---|
18019 5147 931 770 22539 ... Truncated |
Test 9
Verdict: ACCEPTED
input |
---|
5002
257175927 192486676 334121373 435149455 ... |
correct output |
---|
146582420
29055198 16849058 288217117 130083280 ... |
user output |
---|
146582420 29055198 16849058 288217117 130083280 ... Truncated |
Test 10
Verdict: ACCEPTED
input |
---|
9999
352949139 551279904 517124120 806539504 ... |
correct output |
---|
239036611
37116744 275126549 204880827 326532128 ... |
user output |
---|
239036611 37116744 275126549 204880827 326532128 ... Truncated |