Submission #855921

# Submission time Handle Problem Language Result Execution time Memory
855921 2023-10-02T09:25:25 Z hariaakas646 Collecting Stamps 3 (JOI20_ho_t3) C++17
0 / 100
1 ms 348 KB
#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 = dp[0][0].s = 0;
    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+1) {
                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);
            }
        }
    }
    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

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
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -