CSES - Putka Open 2020 – 2/5 - Results
Submission details
Task:Torni
Sender:Metabolix
Submission time:2020-09-25 18:48:07 +0300
Language:C++ (C++11)
Status:READY
Result:15
Feedback
groupverdictscore
#1ACCEPTED15
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#20.01 s2, 3details
#3--3details

Code

#include <iostream>
#include <algorithm>
#include <vector>

const int MOD = 1000000007;
const int MAX = 1000009;

int tapoja2(int n);
int tapoja12(int n);

int tapoja1(int n) {
	static int _t[MAX]; if (_t[n]) return _t[n];
	long summa = 0;
	summa += 1;
	for (int i = 1; i < n; ++i) {
		summa += tapoja1(n - i);
		summa %= MOD;
	}
	return _t[n] = summa;
}

int tapoja(int n) {
	static int _t[MAX]; if (_t[n]) return _t[n];
	long summa = 0;
	summa += tapoja2(n);
	summa += tapoja12(n);
	return _t[n] = summa;
}

int tapoja2(int n) {
	static int _t[MAX]; if (_t[n]) return _t[n];
	long summa = 0;

	// Täytetään 2xn-palalla loppuun.
	summa += 1;
	summa %= MOD;
	// Täytetään 2xi-palalla ja rekursio.
	for (int i = 1; i < n; ++i) {
		summa += tapoja(n - i);
		summa %= MOD;
	}
	return _t[n] = summa;
}

int tapoja12(int n) {
	static int _t[MAX]; if (_t[n]) return _t[n];
	long summa = 0;
	// Täytetään 1x*-paloilla korkeuteen i ja rekursio 2x*-paloihin.
	for (int i = 1; i < n; ++i) {
		long t1 = tapoja1(i);
		long tt1 = (t1 * t1) % MOD;
		summa += tt1 * tapoja2(n - i);
		summa %= MOD;
	}
	// Täytetään 1x*-paloilla ja rekursio 2x*-paloihin.
	long t1 = tapoja1(n);
	summa += t1 * t1;
	summa %= MOD;
	return _t[n] = summa;
}

int main() {
	int t;
	std::cin >> t;
	for (int i = 0; i < t; ++i) {
		int n;
		std::cin >> n;
		std::cout << tapoja(n) << std::endl;
	}
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
10
1
2
3
4
...

correct output
2
8
34
148
650
...

user output
2
8
34
148
650
...

Test 2

Group: 2, 3

Verdict:

input
100
1
2
3
4
...

correct output
2
8
34
148
650
...

user output
2
8
34
148
650
...
Truncated

Test 3

Group: 3

Verdict:

input
100
996306
650655
896240
821967
...

correct output
87350005
606189151
122595036
193572715
227926807
...

user output
(empty)