# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
582683 | 2022-06-24T09:10:52 Z | 박상훈(#8369) | Fibonacci representations (CEOI18_fib) | C++17 | 4000 ms | 856 KB |
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int MOD = 1e9+7; __int128 fib[200]; ll pw(ll a, ll e){ if (!e) return 1; ll ret = pw(a, e/2); if (e&1) return ret*ret%MOD*a%MOD; return ret*ret%MOD; } ll INV(ll x){ return pw(x, MOD - 2); } vector<int> convert(__int128 x){ vector<int> ret; for (int i=120;i>=1;i--) if (x>=fib[i]){ ret.push_back(i); x -= fib[i]; } ret.push_back(0); reverse(ret.begin(), ret.end()); return ret; } bool update(vector<int> &a){ sort(a.begin(), a.end()); for (int i=1;i+1<(int)a.size();i++){ int tmp = a[i]; if (a[i]==a[i+1]){ a.erase(a.begin()+i+1); a.erase(a.begin()+i); if (tmp==1){ a.push_back(2); } else if (tmp==2){ a.push_back(3); a.push_back(1); } else{ a.push_back(tmp+1); a.push_back(tmp-2); } return 1; } else if (a[i]+1==a[i+1]){ a.erase(a.begin()+i+1); a.erase(a.begin()+i); a.push_back(tmp+2); return 1; } } return 0; } int main(){ int n; scanf("%d", &n); fib[0] = fib[1] = 1; for (int i=2;i<=120;i++) fib[i] = fib[i-1] + fib[i-2]; vector<int> a = {0}; for (int i=1;i<=n;i++){ int x; scanf("%d", &x); a.push_back(x); while(update(a)); sort(a.begin(), a.end()); vector<ll> dp1(a.size()), dp2(a.size()); dp1[0] = dp2[0] = 1; for (int i=1;i<(int)a.size();i++){ dp1[i] = dp1[i-1] * ((a[i] - a[i-1] + 1) / 2) % MOD; if (a[i]%2==a[i-1]%2) dp1[i] = (dp1[i] + dp1[i-1] - dp2[i-1] + MOD) % MOD; dp2[i] = dp1[i-1]; } printf("%lld\n", dp1.back()); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 0 ms | 220 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 1 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 212 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Execution timed out | 4045 ms | 856 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 0 ms | 220 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 1 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 212 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | Correct | 1 ms | 340 KB | Output is correct |
25 | Execution timed out | 4045 ms | 856 KB | Time limit exceeded |
26 | Halted | 0 ms | 0 KB | - |