CSES - COCI 2007/2008 #2 - Results
Submission details
Task:Kemija
Sender:henrikaalto
Submission time:2019-07-30 00:20:12 +0300
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#2ACCEPTED0.01 sdetails
#3ACCEPTED0.01 sdetails
#4ACCEPTED0.01 sdetails
#5ACCEPTED0.01 sdetails
#6ACCEPTED0.01 sdetails
#7ACCEPTED0.01 sdetails
#8ACCEPTED0.01 sdetails
#90.01 sdetails
#100.01 sdetails

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, s;
    cin >> n;
    vector<int> 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<int> dd(n);
    for (int i = 0; i < n; ++i) {
        dd[i] = v[ind(i+2)] - v[ind(i+1)];
    }
    vector<int> lol(n);
    if (n % 3) {
        for (int 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 (int 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];
        }
        
        int 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);
        
        int x = max(1, -mi[0] + 1);
        int y = max(1, -mi[1] + 1);
        int 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:

input
5002
257175927
192486676
334121373
435149455
...

correct output
146582420
29055198
16849058
288217117
130083280
...

user output
-12267829
-129795051
-142001191
129366868
-28766969
...
Truncated

Test 10

Verdict:

input
9999
352949139
551279904
517124120
806539504
...

correct output
239036611
37116744
275126549
204880827
326532128
...

user output
239036611
37116744
-208105596
204880827
326532128
...
Truncated