//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
// #include <bits/extc++.h>
using namespace std;
#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define KeepUnique(v) (v).erase( unique(all(v)), v.end() )
#define MEMSET(a, val) memset(a, val, sizeof (a))
#define PB push_back
#define endl '\n'
typedef long long ll;
inline int myrand(int l, int r) {
int ret = rand(); ret <<= 15; ret ^= rand();
if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
return ret;
}
template <typename F, typename S>
ostream& operator << (ostream& os, const pair< F, S>& p) {
return os<<"(" <<p.first<<", "<<p.second<<")"; }
typedef pair<int, int> ii;
template<typename T> using min_pq =
std::priority_queue<T, vector<T>, greater<T> >;
//int dx[] = {-1, +0, +1, +0};
//int dy[] = {+0, +1, +0, -1};
#define less klsdjflk
const int maxn = 1005;
const int mod = 1000007;
int n;
vector<int> v;
int dp[maxn][maxn][2];
int get(int p, int mex, int less) {
if(p == n) return less;
int &ret = dp[p][mex][less];
if(ret != -1) return ret;
ret = 0;
if(!less) {
for(int i = 1; i < mex; i++) {
if(i < v[p]) {
ret += get(p + 1, mex, 1);
// if(ret >= mod) ret -= mod;
}
else if(i == v[i]) {
ret += get(p + 1, mex, 0);
// if(ret >= mod) ret -= mod;;
}
}
if(mex < v[p]) {
ret += get(p + 1, mex + 1, 1);
// if(ret >= mod) ret -= mod;
} else if(mex == v[p]) {
ret += get(p + 1, mex + 1, 0);
// if(ret >= mod) ret -= mod;
}
} else {
for(int i = 1; i < mex; i++) {
ret += get(p + 1, mex, less);
// if(ret >= mod) ret -= mod;
}
ret += get(p + 1, mex + 1, less);
// if(ret >= mod) ret -= mod;
}
ret %= mod;
return ret;
}
int solve(int p, int mex, int tog, int &res) {
if(p == n) {
res++;
if(res == mod) res = 0;
return tog;
}
int &ret = dp[p][mex][tog];
if(ret != -1) {
res += ret;
if(res >= mod) res -= mod;
return tog;
}
ret = 0;
for(int i = 1; i < mex; i++) {
if(solve(p + 1, mex, tog and v[p] == i, ret)) {
res += ret;
if(res >= mod) ret -= mod;
return 1;
}
}
int tmp = solve(p + 1, mex + 1, tog and mex == v[p], ret);
res += ret;
if(res >= mod) res -= mod;
return tmp;
}
int32_t main () {
// freopen("in", "r", stdin);
cin >> n;
v.resize(n);
for(int &b : v) cin >> b;
memset(dp, -1, sizeof dp);
int ans = 0;
solve(0, 1, 1, ans);
cout << ans << endl;
}
Compilation message
teams.cpp: In function 'int myrand(int, int)':
teams.cpp:18:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
^~
teams.cpp:18:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
8184 KB |
Output is correct |
2 |
Correct |
11 ms |
8420 KB |
Output is correct |
3 |
Correct |
10 ms |
8464 KB |
Output is correct |
4 |
Correct |
10 ms |
8464 KB |
Output is correct |
5 |
Correct |
11 ms |
8464 KB |
Output is correct |
6 |
Correct |
11 ms |
8464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8464 KB |
Output is correct |
2 |
Correct |
10 ms |
8464 KB |
Output is correct |
3 |
Correct |
8 ms |
8464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
8464 KB |
Output is correct |
2 |
Correct |
10 ms |
8464 KB |
Output is correct |
3 |
Correct |
9 ms |
8464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
8464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
8464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
180 ms |
8572 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1075 ms |
8604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1056 ms |
8604 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1070 ms |
8604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
8604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |