Task: | Torni |
Sender: | Metabolix |
Submission time: | 2020-09-25 18:51:30 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 56 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 15 |
#2 | ACCEPTED | 41 |
#3 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.01 s | 2, 3 | details |
#3 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
#include <iostream>#include <algorithm>#include <vector>const int MOD = 1000000007;const int MAX = 1000009;long tapoja2(int n);long tapoja12(int n);long 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;}long tapoja(int n) {static int _t[MAX]; if (_t[n]) return _t[n];long summa = 0;summa += tapoja2(n);summa += tapoja12(n);summa %= MOD;return _t[n] = summa;}long 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;}long 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 loppuun.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: ACCEPTED
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: TIME LIMIT EXCEEDED
input |
---|
100 996306 650655 896240 821967 ... |
correct output |
---|
87350005 606189151 122595036 193572715 227926807 ... |
user output |
---|
(empty) |