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 <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
typedef long double ld;
using namespace std;
const int maxm = 55;
const int maxi = maxm * maxm * maxm;
//const int maxi = 10;
const int inf = 1e9 + 5;
int pf[2][maxi * 2];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int m;
ll l;
cin >> m >> l;
m++;
vector<ll> ok(2 * m + 1, 0ll);
for (int i = -m + 1; i < m; i++)
{
cin >> ok[m + i];
}
fill(pf[0], pf[0] + maxi * 2, -inf);
fill(pf[1], pf[1] + maxi * 2, -inf);
pf[0][maxi] = 0;
int cur = 0;
for (int i = -m; i <= m; i++)
{
fill(pf[cur ^ 1], pf[cur ^ 1] + maxi * 2, -inf);
for (int j = -maxi; j < maxi; j++) if (pf[cur][maxi + j] != -inf)
{
int cnt = 0;
for (int d = j; cnt <= ok[m + i] && -maxi < d && d < maxi; d += i, cnt++)
{
pf[cur ^ 1][maxi + d] = max(pf[cur ^ 1][maxi + d], pf[cur][maxi + j] + cnt);
}
}
cur ^= 1;
}
if (abs(l) >= maxi || pf[cur][maxi + l] == -inf)
{
cout << "impossible\n";
}
else
{
cout << pf[cur][maxi + l] << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |