Submission #98514

#TimeUsernameProblemLanguageResultExecution timeMemory
98514thiago4532Zoltan (COCI16_zoltan)C++17
21 / 140
1078 ms9984 KiB
#include <bits/stdc++.h> // #define int int64_t #define int int64_t using namespace std; const int maxn = 1010; int v[maxn], dp[maxn], dp2[maxn], i; deque<int> dq; int ct=0, n; int qtd[maxn]; void backtracking(int i, deque<int> const& d){ if(i == n){ for(int i=0;i<n;i++) v[i] = d[i]; memset(dp, 0, sizeof dp); memset(dp2, 0, sizeof dp2); dp[0] = 1; dp2[0] = 1; for(int i = 1; i < n; i++){ dp[i] = dp2[i] = 1; for(int j = 0; j < i; j++) if(v[j] < v[i]) dp[i] = max(dp[i], dp[j] + 1); if(dp[i] == 1) continue; dp2[i] = 0; for(int j = 0; j < i; j++) if(v[j] < v[i] && dp[j] + 1 == dp[i]) dp2[i] += dp2[j]; } int a = 0, b = 0; for(int i=0;i<n;i++){ if(dp[i] > a){ a = dp[i]; } } for(int i=0;i<n;i++){ if(dp[i] == a) b += dp2[i]; } qtd[a] += b; return; } deque<int> d1 = d, d2 = d; d1.push_back(v[i]); d2.push_front(v[i]); backtracking(i+1, d1); backtracking(i+1, d2); } int lis(){ vector<int> pilha; for(int i=0; i<n; i++){ vector<int>::iterator it = lower_bound(pilha.begin(), pilha.end(), v[i]); if(it==pilha.end()) pilha.push_back(v[i]); else *it = v[i]; } return pilha.size(); } int32_t main(){ cin >> n; int aux; cin >> aux; dq.push_back(aux); for(int i=2;i<=n;i++){ int x; cin >> x; if(x <= dq[0]) dq.push_front(x); else dq.push_back(x); } for(int i=0;i<n;i++) v[i] = dq[i]; backtracking(1, deque<int>({v[0]})); for(int i=n;i>=1;i--){ if(qtd[i] > 0){ cout << i << " " << (qtd[i]%(int)(1e9 + 7)) << "\n"; return 0; } } /* //for(int i=0;i<n;i++) // cin >> v[i]; dp[0] = 1; dp2[0] = 1; for(int i = 1; i < n; i++){ dp[i] = dp2[i] = 1; for(int j = 0; j < i; j++) if(v[j] < v[i]) dp[i] = max(dp[i], dp[j] + 1); if(dp[i] == 1) continue; dp2[i] = 0; for(int j = 0; j < i; j++) if(v[j] < v[i] && dp[j] + 1 == dp[i]) dp2[i] += dp2[j]; } int a = 0, b = 0; for(int i=0;i<n;i++){ if(dp[i] > a){ a = dp[i]; } } for(int i=0;i<n;i++){ if(dp[i] == a) b += dp2[i]; } cout << a << " " << b*ct << "\n"; //cout << "Count: " << ct << "\n";*/ return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...