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>
using namespace std;
#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;
void usaco()
{
freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
// freopen("problem.out", "w", stdout);
}
int main() {
// usaco();
int n, l;
scd(n);
scd(l);
vector<pair<lli, lli>> vec(n+1);
frange(i, n) {
sclld(vec[i+1].f);
}
frange(i, n) {
sclld(vec[i+1].s);
}
vector<vector<pair<lli, lli>>> dp(n+1, vector<pair<lli, lli>>(n+1, mp(1e18, 1e18)));
dp[0][0].f = 0;
dp[0][0].s = l;
forr(i, 1, n+1) {
dp[i][0].f = vec[i].f;
dp[i][0].s = l - vec[i].f;
}
forr(j, 1, n+1) {
forr(i, 1, n+1) {
forr(k, 0, i) {
if(dp[k][j-1].f + vec[i].f - vec[k].f <= vec[i].s)
dp[i][j].f = min(dp[i][j].f, dp[k][j-1].f + vec[i].f - vec[k].f);
if(dp[k][j-1].f + vec[k].f + (l - vec[i].f) <= vec[i].s)
dp[i][j].s = min(dp[i][j].s, dp[k][j-1].f + vec[k].f + (l - vec[i].f));
}
forr(k, i+1, n+2) {
if(k == n+1) k = 0;
if(dp[k][j-1].s + vec[k].f - vec[i].f <= vec[i].s)
dp[i][j].s = min(dp[i][j].s, dp[k][j-1].s + vec[k].f - vec[i].f);
if(dp[k][j-1].s + (l - vec[k].f) + vec[i].f <= vec[i].s)
dp[i][j].f = min(dp[i][j].f, dp[k][j-1].s + (l - vec[k].f) + vec[i].f);
if(k == 0) k = n+1;
}
}
}
for(int j=n; j>=0; j--) {
forr(i, 1, n+1) {
if(dp[i][j].f < 1e18 || dp[i][j].s < 1e18) {
printf("%d\n", j);
return 0;
}
}
}
}
Compilation message (stderr)
ho_t3.cpp: In function 'void usaco()':
ho_t3.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
ho_t3.cpp:37:5: note: in expansion of macro 'scd'
37 | scd(n);
| ^~~
ho_t3.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
ho_t3.cpp:38:5: note: in expansion of macro 'scd'
38 | scd(l);
| ^~~
ho_t3.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
6 | #define sclld(t) scanf("%lld", &t)
| ~~~~~^~~~~~~~~~~~
ho_t3.cpp:41:9: note: in expansion of macro 'sclld'
41 | sclld(vec[i+1].f);
| ^~~~~
ho_t3.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
6 | #define sclld(t) scanf("%lld", &t)
| ~~~~~^~~~~~~~~~~~
ho_t3.cpp:44:9: note: in expansion of macro 'sclld'
44 | sclld(vec[i+1].s);
| ^~~~~
# | 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... |