# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
736641 | Olympia | Zoltan (COCI16_zoltan) | C++17 | 580 ms | 7132 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <map>
#include <deque>
using namespace std;
const int MX = 20;
int64_t lis_length[MX];
int64_t lis_number[MX];
const int MOD = 1e9 + 7;
pair<int,int> lis (vector<int> v) {
lis_length[0] = 1, lis_number[0] = 1;
for (int i = 1; i < v.size(); i++) {
lis_length[i] = 1, lis_number[i] = 1;
for (int j = 0; j < i; j++) {
if (v[j] < v[i]) {
if (lis_length[j] + 1 > lis_length[i]) {
lis_length[i] = lis_length[j] + 1;
lis_number[i] = lis_number[j];
} else if (lis_length[j] + 1 == lis_length[i]) {
lis_number[i] += lis_number[j];
lis_number[i] %= MOD;
}
}
}
}
int64_t mx = 0, cnt = 0;
for (int i = 0; i < v.size(); i++) {
if (lis_length[i] > mx) {
mx = lis_length[i];
cnt = lis_number[i];
} else if (lis_length[i] == mx) {
cnt += lis_number[i];
}
}
return make_pair(mx, cnt);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
int64_t mx = 0, cnt = 0;
for (int i = 0; i < (1 << n); i += 2) {
deque<int> d;
for (int j = 0; j < n; j++) {
if (i & (1 << j)) {
d.push_back(v[j]);
} else {
d.push_front(v[j]);
}
}
vector<int> vec;
for (int i: d) {
vec.push_back(i);
}
auto p = lis(vec);
if (p.first == mx) {
cnt += p.second;
cnt %= MOD;
} else if (p.first > mx) {
mx = p.first, cnt = p.second;
}
}
cout << mx << " " << cnt << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |