CSES - Harjoituskisa 14.1.2018 - Results
Submission details
Task:Alitaulukot
Sender:Yytsi
Submission time:2018-01-17 17:59:20 +0200
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED15
#2ACCEPTED85
Test results
testverdicttimegroup
#1ACCEPTED0.05 s1details
#2ACCEPTED0.06 s2details

Code

/*
	Here's a more beautiful way to solve this problem, than my last one =)
	
	Example for
	n = 4, L = [1, 2, 3, 4]
	
	Here are all formable sums. Summing those up give the result.
	
	1
	1 2
	1 2 3
	1 2 3 4
	
	2
	2 3
	2 3 4
	
	3
	3 4
	
	4
	
	
*/







#include <iostream>

using namespace std;

typedef long long ll;
ll n;
ll s[100001];
ll part[101010];

int main(int argc, char** argv) {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n; cin.ignore();
	
	for (int i = 1; i <= n; i++) {
		ll e; cin >> e;
		s[i] = e;
	}
	
	ll r = 0LL;
	for (ll i = n; i > 0; i--) {
		ll multi = n - i + 1; 		// How many times to multiply this number.
		ll accum = part[i + 1]; 	// Add what we've accumulated so far.
		ll curr = multi * s[i]; 	// Multiply by the current number.
		part[i] = curr + accum;		// Set the new accumulator.
		r += part[i];				// Add the accumulated sum to the result sum.
		r %= 1000000007LL;			// Modulo the result sum.
	}
	
	cout << r;
	
	return 0;
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
100
72 66 50 11 3 15 68 45 79 11 9...

correct output
9437440

user output
9437440

Test 2

Group: 2

Verdict: ACCEPTED

input
100000
483398076 227177515 705421329 ...

correct output
179178131

user output
179178131