Submission #243497

#TimeUsernameProblemLanguageResultExecution timeMemory
243497VEGAnnZoltan (COCI16_zoltan)C++14
42 / 140
1100 ms12284 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[N][N][2], 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[a[0]][a[0]][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[men][mex][tp] = {0, 0}; f[a[i]][a[i]][tp] = {1, po}; for (int men = mn; men <= mx; men++) for (int mex = men; mex <= mx; mex++){ if (f[men][mex][tp ^ 1][0] == 0) continue; upd(f[men][mex][tp], f[men][mex][tp ^ 1]); upd(f[men][mex][tp], f[men][mex][tp ^ 1]); cur = f[men][mex][tp ^ 1]; cur[0]++; if (a[i] < men) upd(f[a[i]][mex][tp], cur); if (a[i] > mex) upd(f[men][a[i]][tp], cur); } } int tp = ((n - 1) & 1); for (int i = mn; i <= mx; i++) for (int j = i; j <= mx; j++) upd(ans, f[i][j][tp]); cout << ans[0] << " " << ans[1]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...