Submission #1034918

#TimeUsernameProblemLanguageResultExecution timeMemory
1034918otariusCollecting Stamps 3 (JOI20_ho_t3)C++17
100 / 100
57 ms66652 KiB
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()

// #define int long long
// #define int unsigned long long

// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>

void open_file(string filename) {
    freopen((filename + ".in").c_str(), "r", stdin);
    freopen((filename + ".out").c_str(), "w", stdout);
}

// const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll inf = 1e9;
const ll biginf = 1e18;
const int maxN = 205;

int n, l, tim, x[maxN], t[maxN], dp[maxN][maxN][maxN][2];
void solve() {
    cin >> n >> l;
    for (int i = 1; i <= n; i++) cin >> x[i];
    for (int i = 1; i <= n; i++) cin >> t[i];
    for (int i = 0; i <= n + 1; i++) {
        for (int j = 0; j <= n + 1; j++) {
            for (int k = 0; k <= n; k++) {
                dp[i][j][k][0] = dp[i][j][k][1] = inf;
            }
        }
    } x[n + 1] = l; dp[0][n + 1][0][0] = dp[0][n + 1][0][1] = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = n + 1; j > i; j--) {
            for (int k = 0; k <= n; k++) {
                tim = dp[i][j][k][0] + x[i + 1] - x[i];
                if (tim <= t[i + 1]) dp[i + 1][j][k + 1][0] = min(dp[i + 1][j][k + 1][0], tim);
                else dp[i + 1][j][k][0] = min(dp[i + 1][j][k][0], tim);
                tim = dp[i][j][k][1] + x[i + 1] - x[j] + l;
                if (tim <= t[i + 1]) dp[i + 1][j][k + 1][0] = min(dp[i + 1][j][k + 1][0], tim);
                else dp[i + 1][j][k][0] = min(dp[i + 1][j][k][0], tim);
                tim = dp[i][j][k][0] + x[i] - x[j - 1] + l;
                if (tim <= t[j - 1]) dp[i][j - 1][k + 1][1] = min(dp[i][j - 1][k + 1][1], tim);
                else dp[i][j - 1][k][1] = min(dp[i][j - 1][k][1], tim);
                tim = dp[i][j][k][1] + x[j] - x[j - 1];
                if (tim <= t[j - 1]) dp[i][j - 1][k + 1][1] = min(dp[i][j - 1][k + 1][1], tim);
                else dp[i][j - 1][k][1] = min(dp[i][j - 1][k][1], tim);
            }
        }
    } int ans = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = n + 1; j > i; j--) {
            for (int k = 0; k <= n; k++) {
                if (dp[i][j][k][0] != inf) ans = max(ans, k);
                if (dp[i][j][k][1] != inf) ans = max(ans, k);
            }
        }
    } cout << ans;
}
int32_t main() { 
    // ios_base::sync_with_stdio(false);
    // cin.tie(nullptr); cout.tie(nullptr);
    
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Compilation message (stderr)

ho_t3.cpp: In function 'void open_file(std::string)':
ho_t3.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     freopen((filename + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((filename + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...