제출 #1346169

#제출 시각아이디문제언어결과실행 시간메모리
1346169JahonaliXZoltan (COCI16_zoltan)C++20
42 / 140
360 ms2004 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long
constexpr int mod = 1e9 + 7, inf = 1e17;

int32_t main() {
#ifdef JahonaliX
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, ans = 0, cn = 0;
    cin >> n;
    vector<int> b(n);
    for (int &i : b) cin >> i;
    assert(n <= 30);
    for (int mask = 0; mask < (1 << n); mask += 2) {
        vector<int> a, c;
        for (int i = 0; i < n; ++i) {
            if (mask >> i & 1) c.emplace_back(b[i]);
            else a.emplace_back(b[i]);
        }
        reverse(a.begin(), a.end());
        for (int i : c) a.emplace_back(i);
        vector<int> dp(n, 1), cnt(n, 1);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < i; ++j) {
                if (a[j] < a[i]) {
                    if (dp[i] <= dp[j]) dp[i] = dp[j] + 1, cnt[i] = cnt[j];
                    else if (dp[i] == dp[j] + 1) cnt[i] += cnt[j], cnt[i] %= mod;
                }
            }
        }
        for (int i = 0; i < n; ++i) {
            if (ans < dp[i]) ans = dp[i], cn = cnt[i];
            else if (ans == dp[i]) cn += cnt[i], cn %= mod;
        }
    }
    cout << ans << ' ' << cn;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...