제출 #593433

#제출 시각아이디문제언어결과실행 시간메모리
593433nguyen31hoang08minh2003Zoltan (COCI16_zoltan)C++14
7 / 140
80 ms65536 KiB
/* +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ |\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/| |/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\| | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | |/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \| +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ |\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /| | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | |\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/| |/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\| +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ |\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/| |/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\| | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | |/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \| +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ |\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /| | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | |\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/| |/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\| +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ */ #include <bits/stdc++.h> #define fore(i, a, b) for (int i = (a), i##_last = (b); i < i##_last; ++i) #define fort(i, a, b) for (int i = (a), i##_last = (b); i <= i##_last; ++i) #define ford(i, a, b) for (int i = (a), i##_last = (b); i >= i##_last; --i) #define fi first #define se second #define pb push_back #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; using ll = long long; using ld = long double; template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;}; template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;}; typedef unsigned long long ull; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vii> vvii; const int maxN = 2e5 + 5, MOD = 1e9 + 7; int n, a[maxN]; void subtask1() { const int N = n + 5; vector<vector<vector<vvi> > > dp(N, vector<vector<vvi> >(N, vector<vvi>(N, vvi(N, vi(2, -1))))), cnt = dp; const function<int(int, int, int, int, bool)> DP = [&](const int x, const int y, const int l, const int r, const bool z) -> int { if (x > n) return y; if (dp[x][y][l][r][z] < 0) { dp[x][y][l][r][z] = DP(x + 1, y, l, r, z); if (z) { if (a[r] < a[x]) maxi(dp[x][y][l][r][z], DP(x + 1, y + 1, l, x, z)); if (a[x] < a[l]) maxi(dp[x][y][l][r][z], DP(x + 1, y + 1, x, r, z)); } else maxi(dp[x][y][l][r][z], DP(x + 1, y + 1, x, x, true)); } return dp[x][y][l][r][z]; }; const function<int(int, int, int, int, bool)> Count = [&](const int x, const int y, const int l, const int r, const bool z) -> int { if (x > n) return y == 0; if (cnt[x][y][l][r][z] < 0) { cnt[x][y][l][r][z] = (Count(x + 1, y, l, r, z) << (x > 1)) % MOD; if (z) { if (a[r] < a[x]) (cnt[x][y][l][r][z] += Count(x + 1, y - 1, l, x, z)) %= MOD; if (a[x] < a[l]) (cnt[x][y][l][r][z] += Count(x + 1, y - 1, x, r, z)) %= MOD; } else (cnt[x][y][l][r][z] += (Count(x + 1, y - 1, x, x, true) << (x > 1)) % MOD) %= MOD; } return cnt[x][y][l][r][z]; }; cout << DP(1, 0, 0, 0, false) << ' ' << Count(1, DP(1, 0, 0, 0, false), 0, 0, false) << '\n'; } void input() { cin >> n; fort(i, 1, n) cin >> a[i]; } int main() { #ifdef LOCAL freopen("input.INP", "r", stdin); #endif // LOCAL cin.tie(0) -> sync_with_stdio(0); cout.tie(0); input(); subtask1(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...