답안 #856513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
856513 2023-10-03T18:50:52 Z ArminAzimi Zoltan (COCI16_zoltan) C++14
0 / 140
3 ms 604 KB
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<pair <int, int>, null_type,less<pair <int, int>>, rb_tree_tag,tree_order_statistics_node_update> 

const int MAXN = 1e3 + 10, MAXM = 1e2 + 10, MOD = 1000000000 + 7, MOD1 = 1e9 + 9, SQ = 350;
const long long INF = 1e9 + 11;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int a[MAXN], dp[MAXN][2], cnt[MAXN][2], p2[MAXN];

void solve() {
    int n;
    cin >> n;

    if (n > 1000)
        return;

    p2[0] = 1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        p2[i + 1] = 2ll * p2[i] % MOD;
    }

    
    for (int i = n - 1; i >= 0; i--) {
        int mx = 0;
        int cnt1 = 1;
        for (int j = i + 1; j < n; j++) {
            if (a[i] < a[j]) {
                if (mx < dp[j][0]) {
                    mx = dp[j][0];
                    cnt1 = cnt[j][0];
                }
                else if (mx == dp[j][0]) {
                    cnt1 = (cnt1 + cnt[j][0]) % MOD;
                }
            }
        }

        dp[i][0] = mx + 1;
        cnt[i][0] = cnt1;
        
        mx = 0;
        cnt1 = 0;
        for (int j = i + 1; j < n; j++) {
            if (a[i] > a[j]) {
                if (mx < dp[j][1]) {
                    mx = dp[j][1];
                    cnt1 = cnt[j][1];
                }
                else if (mx == dp[j][1]) {
                    cnt1 = (cnt1 + cnt[j][1]) % MOD;
                }
            }
        }

        dp[i][1] = mx + 1;
        cnt[i][1] = cnt1;
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, dp[i][0] + dp[i][1] - 1);
    }

    int ans1 = 0;
    for (int i = 0; i < n; i++) {
        if (dp[i][0] + dp[i][1] - 1 == ans) {
            int tmp = 1ll * cnt[i][0] * cnt[i][1] % MOD;
            tmp = 1ll * tmp * p2[n - ans] % MOD;

            ans1 = (ans1 + tmp) % MOD;
        }
    }

    cout << ans << " " << ans1 << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int q = 1;
    // cin >> q;
    
    while (q--) {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Incorrect 3 ms 348 KB Output isn't correct
8 Incorrect 3 ms 348 KB Output isn't correct
9 Incorrect 3 ms 344 KB Output isn't correct
10 Incorrect 3 ms 348 KB Output isn't correct
11 Incorrect 0 ms 348 KB Output isn't correct
12 Incorrect 0 ms 344 KB Output isn't correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 Incorrect 0 ms 348 KB Output isn't correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Incorrect 0 ms 604 KB Output isn't correct
17 Incorrect 0 ms 348 KB Output isn't correct
18 Incorrect 0 ms 348 KB Output isn't correct
19 Incorrect 0 ms 348 KB Output isn't correct
20 Incorrect 0 ms 348 KB Output isn't correct