Submission #243447

#TimeUsernameProblemLanguageResultExecution timeMemory
243447VEGAnnZoltan (COCI16_zoltan)C++14
42 / 140
1098 ms16252 KiB
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("fast-math") #pragma GCC optimize("no-stack-protector") #define all(x) x.begin(),x.end() #define sz(x) ((int)x.size()) #define i2 array<int,2> #define PB push_back using namespace std; const int N = 2010; const int oo = 2e9; const int md = int(1e9) + 7; i2 f[2][N][N], ans, cur; vector<int> vc; int n, a[N]; void SUM(int &x, int y){ x += y; if (x >= md) x -= md; } void upd(i2 &cr, i2 nw){ if (nw[0] > cr[0]) cr = nw; else if (nw[0] == cr[0]){ SUM(cr[1], nw[1]); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef _LOCAL freopen("in.txt","r",stdin); #endif // _LOCAL cin >> n; assert(n <= 1000); for (int i = 0; i < n; i++) { cin >> a[i]; vc.PB(a[i]); } sort(all(vc)); vc.resize(unique(all(vc)) - vc.begin()); for (int i = 0; i < n; i++) a[i] = lower_bound(all(vc), a[i]) - vc.begin(); f[0][a[0]][a[0]] = {1, 1}; int mn = a[0], mx = a[0]; int po = 1; for (int i = 1; i < n; i++){ int tp = (i & 1); SUM(po, po); mn = min(mn, a[i]); mx = max(mx, a[i]); for (int men = mn; men <= mx; men++) for (int mex = men; mex <= mx; mex++) f[tp][men][mex] = {0, 0}; f[tp][a[i]][a[i]] = {1, po}; for (int men = mn; men <= mx; men++) for (int mex = men; mex <= mx; mex++){ if (f[tp ^ 1][men][mex][0] == 0) continue; upd(f[tp][men][mex], f[tp ^ 1][men][mex]); upd(f[tp][men][mex], f[tp ^ 1][men][mex]); cur = f[tp ^ 1][men][mex]; cur[0]++; if (a[i] < men) upd(f[tp][a[i]][mex], cur); if (a[i] > mex) upd(f[tp][men][a[i]], cur); } } int tp = ((n - 1) & 1); for (int i = mn; i <= mx; i++) for (int j = i; j <= mx; j++) upd(ans, f[tp][i][j]); cout << ans[0] << " " << ans[1]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...