# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
243444 | VEGAnn | Zoltan (COCI16_zoltan) | C++14 | 1098 ms | 16248 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#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;
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;
// cerr << f[tp][men][mex][0] << " " << f[tp][men][mex][1] << '\n';
// cerr << f[tp ^ 1][men][mex][0] << " " << f[tp ^ 1][men][mex][1] << '\n';
upd(f[tp][men][mex], f[tp ^ 1][men][mex]);
upd(f[tp][men][mex], f[tp ^ 1][men][mex]);
// cerr << f[tp][men][mex][0] << " " << f[tp][men][mex][1] << '\n';
if (a[i] < men) {
i2 cur = f[tp ^ 1][men][mex];
cur[0]++;
upd(f[tp][a[i]][mex], cur);
}
if (a[i] > mex) {
i2 cur = f[tp ^ 1][men][mex];
cur[0]++;
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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |