답안 #922790

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
922790 2024-02-06T06:35:07 Z vjudge1 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
405 ms 1040664 KB
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include <x86intrin.h>

#include <bits/stdc++.h>
#include <chrono>
#include <random>

// @author: Vlapos

namespace operators
{
    template <typename T1, typename T2>
    std::istream &operator>>(std::istream &in, std::pair<T1, T2> &x)
    {
        in >> x.first >> x.second;
        return in;
    }

    template <typename T1, typename T2>
    std::ostream &operator<<(std::ostream &out, std::pair<T1, T2> x)
    {
        out << x.first << " " << x.second;
        return out;
    }

    template <typename T1>
    std::istream &operator>>(std::istream &in, std::vector<T1> &x)
    {
        for (auto &i : x)
            in >> i;
        return in;
    }

    template <typename T1>
    std::ostream &operator<<(std::ostream &out, std::vector<T1> &x)
    {
        for (auto &i : x)
            out << i << " ";
        return out;
    }

    template <typename T1>
    std::ostream &operator<<(std::ostream &out, std::set<T1> &x)
    {
        for (auto &i : x)
            out << i << " ";
        return out;
    }
}

// name spaces
using namespace std;
using namespace operators;
// end of name spaces

// defines
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define uint unsigned int
#define all(vc) vc.begin(), vc.end()
// end of defines

// usefull stuff

void boost()
{
    ios_base ::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

inline int getbit(int &x, int &bt) { return (x >> bt) & 1; }

const int dx4[4] = {-1, 0, 0, 1};
const int dy4[4] = {0, -1, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy8[8] = {-1, -0, 1, -1, 1, -1, 0, 1};

const ll INF = (1e18) + 500;
const int BIG = (1e9) * 2 + 100;
const int MOD7 = (1e9) + 7;
const int MOD9 = (1e9) + 9;
const uint MODFFT = 998244353;

#define int ll

const int maxN = 405;
int dp[maxN][maxN][maxN][2];

struct test
{
    void solve(int testcase)
    {
        boost();

        int n, L;
        cin >> n >> L;

        vector<int> x(n), t(n);
        cin >> x >> t;
        x.pb(L);
        t.pb(-1);
        for (int i = 0; i < n; ++i)
        {
            x.pb(L + x[i]);
            t.pb(t[i]);
        }

        for (int i = 0; i < maxN; ++i)
            for (int j = 0; j < maxN; ++j)
                for (int k = 0; k < maxN; ++k)
                    for (int fl = 0; fl < 2; ++fl)
                        dp[i][j][k][fl] = BIG;

        dp[n][n][0][0] = dp[n][n][0][1] = 0;

        int ans = 0;
        int bestRes = 0;
        int N = x.size();
        int r = 0, cord = 0, tocnt = 0;
        for (int len = 0; len < n; ++len)
            for (int l = 0; l <= n; ++l)
            {
                r = l + len;
                for (int cnt = 0; cnt < n; ++cnt)
                    for (int fl = 0; fl < 2; ++fl)
                        if (dp[l][r][cnt][fl] < BIG)
                        {
                            cord = fl ? x[r] : x[l];
                            if (l)
                            {
                                tocnt = cnt + (int)(t[l - 1] >= abs(cord - x[l - 1]) + dp[l][r][cnt][fl]);
                                ans = max(ans, tocnt);
                                dp[l - 1][r][tocnt][0] = min(dp[l - 1][r][tocnt][0], abs(cord - x[l - 1]) + dp[l][r][cnt][fl]);
                            }
                            if (r + 1 < N)
                            {
                                tocnt = cnt + (int)(t[r + 1] >= abs(cord - x[r + 1]) + dp[l][r][cnt][fl]);
                                ans = max(ans, tocnt);
                                dp[l][r + 1][tocnt][1] = min(dp[l][r + 1][tocnt][1], abs(cord - x[r + 1]) + dp[l][r][cnt][fl]);
                            }
                        }
            }

        cout << ans << "\n";
    }
};

main()
{
    boost();
    int q = 1;
    // cin >> q;
    for (int i = 0; i < q; i++)
    {
        test t;
        t.solve(i);
    }
    return 0;
}
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]//
//                                                                                    //
//                               Coded by Der_Vlἀpos                                  //
//                                                                                    //
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]//

Compilation message

ho_t3.cpp: In member function 'void test::solve(long long int)':
ho_t3.cpp:125:13: warning: unused variable 'bestRes' [-Wunused-variable]
  125 |         int bestRes = 0;
      |             ^~~~~~~
ho_t3.cpp: At global scope:
ho_t3.cpp:156:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  156 | main()
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 389 ms 1040344 KB Output is correct
2 Correct 342 ms 1040308 KB Output is correct
3 Correct 331 ms 1040364 KB Output is correct
4 Correct 339 ms 1040348 KB Output is correct
5 Correct 349 ms 1040292 KB Output is correct
6 Correct 340 ms 1040420 KB Output is correct
7 Correct 337 ms 1040208 KB Output is correct
8 Correct 372 ms 1040252 KB Output is correct
9 Correct 332 ms 1040324 KB Output is correct
10 Correct 346 ms 1040372 KB Output is correct
11 Correct 346 ms 1040404 KB Output is correct
12 Correct 337 ms 1040212 KB Output is correct
13 Correct 338 ms 1040360 KB Output is correct
14 Correct 332 ms 1040212 KB Output is correct
15 Correct 334 ms 1040384 KB Output is correct
16 Correct 336 ms 1040204 KB Output is correct
17 Correct 337 ms 1040368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 389 ms 1040344 KB Output is correct
2 Correct 342 ms 1040308 KB Output is correct
3 Correct 331 ms 1040364 KB Output is correct
4 Correct 339 ms 1040348 KB Output is correct
5 Correct 349 ms 1040292 KB Output is correct
6 Correct 340 ms 1040420 KB Output is correct
7 Correct 337 ms 1040208 KB Output is correct
8 Correct 372 ms 1040252 KB Output is correct
9 Correct 332 ms 1040324 KB Output is correct
10 Correct 346 ms 1040372 KB Output is correct
11 Correct 346 ms 1040404 KB Output is correct
12 Correct 337 ms 1040212 KB Output is correct
13 Correct 338 ms 1040360 KB Output is correct
14 Correct 332 ms 1040212 KB Output is correct
15 Correct 334 ms 1040384 KB Output is correct
16 Correct 336 ms 1040204 KB Output is correct
17 Correct 337 ms 1040368 KB Output is correct
18 Correct 339 ms 1040476 KB Output is correct
19 Correct 345 ms 1040484 KB Output is correct
20 Correct 329 ms 1040208 KB Output is correct
21 Correct 331 ms 1040412 KB Output is correct
22 Correct 351 ms 1040292 KB Output is correct
23 Correct 342 ms 1040284 KB Output is correct
24 Correct 332 ms 1040400 KB Output is correct
25 Correct 337 ms 1040372 KB Output is correct
26 Correct 346 ms 1040400 KB Output is correct
27 Correct 337 ms 1040292 KB Output is correct
28 Correct 366 ms 1040208 KB Output is correct
29 Correct 346 ms 1040212 KB Output is correct
30 Correct 353 ms 1040212 KB Output is correct
31 Correct 353 ms 1040208 KB Output is correct
32 Correct 356 ms 1040296 KB Output is correct
33 Correct 372 ms 1040224 KB Output is correct
34 Correct 367 ms 1040260 KB Output is correct
35 Correct 350 ms 1040268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 389 ms 1040344 KB Output is correct
2 Correct 342 ms 1040308 KB Output is correct
3 Correct 331 ms 1040364 KB Output is correct
4 Correct 339 ms 1040348 KB Output is correct
5 Correct 349 ms 1040292 KB Output is correct
6 Correct 340 ms 1040420 KB Output is correct
7 Correct 337 ms 1040208 KB Output is correct
8 Correct 372 ms 1040252 KB Output is correct
9 Correct 332 ms 1040324 KB Output is correct
10 Correct 346 ms 1040372 KB Output is correct
11 Correct 346 ms 1040404 KB Output is correct
12 Correct 337 ms 1040212 KB Output is correct
13 Correct 338 ms 1040360 KB Output is correct
14 Correct 332 ms 1040212 KB Output is correct
15 Correct 334 ms 1040384 KB Output is correct
16 Correct 336 ms 1040204 KB Output is correct
17 Correct 337 ms 1040368 KB Output is correct
18 Correct 375 ms 1040316 KB Output is correct
19 Correct 359 ms 1040256 KB Output is correct
20 Correct 377 ms 1040252 KB Output is correct
21 Correct 357 ms 1040524 KB Output is correct
22 Correct 378 ms 1040240 KB Output is correct
23 Correct 353 ms 1040380 KB Output is correct
24 Correct 368 ms 1040248 KB Output is correct
25 Correct 357 ms 1040468 KB Output is correct
26 Correct 344 ms 1040308 KB Output is correct
27 Correct 356 ms 1040468 KB Output is correct
28 Correct 405 ms 1040188 KB Output is correct
29 Correct 369 ms 1040328 KB Output is correct
30 Correct 344 ms 1040464 KB Output is correct
31 Correct 343 ms 1040348 KB Output is correct
32 Correct 352 ms 1040324 KB Output is correct
33 Correct 342 ms 1040252 KB Output is correct
34 Correct 346 ms 1040528 KB Output is correct
35 Correct 338 ms 1040216 KB Output is correct
36 Correct 343 ms 1040368 KB Output is correct
37 Correct 340 ms 1040376 KB Output is correct
38 Correct 346 ms 1040292 KB Output is correct
39 Correct 336 ms 1040208 KB Output is correct
40 Correct 338 ms 1040208 KB Output is correct
41 Correct 375 ms 1040420 KB Output is correct
42 Correct 367 ms 1040348 KB Output is correct
43 Correct 386 ms 1040424 KB Output is correct
44 Correct 369 ms 1040208 KB Output is correct
45 Correct 380 ms 1040216 KB Output is correct
46 Correct 364 ms 1040448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 389 ms 1040344 KB Output is correct
2 Correct 342 ms 1040308 KB Output is correct
3 Correct 331 ms 1040364 KB Output is correct
4 Correct 339 ms 1040348 KB Output is correct
5 Correct 349 ms 1040292 KB Output is correct
6 Correct 340 ms 1040420 KB Output is correct
7 Correct 337 ms 1040208 KB Output is correct
8 Correct 372 ms 1040252 KB Output is correct
9 Correct 332 ms 1040324 KB Output is correct
10 Correct 346 ms 1040372 KB Output is correct
11 Correct 346 ms 1040404 KB Output is correct
12 Correct 337 ms 1040212 KB Output is correct
13 Correct 338 ms 1040360 KB Output is correct
14 Correct 332 ms 1040212 KB Output is correct
15 Correct 334 ms 1040384 KB Output is correct
16 Correct 336 ms 1040204 KB Output is correct
17 Correct 337 ms 1040368 KB Output is correct
18 Correct 339 ms 1040476 KB Output is correct
19 Correct 345 ms 1040484 KB Output is correct
20 Correct 329 ms 1040208 KB Output is correct
21 Correct 331 ms 1040412 KB Output is correct
22 Correct 351 ms 1040292 KB Output is correct
23 Correct 342 ms 1040284 KB Output is correct
24 Correct 332 ms 1040400 KB Output is correct
25 Correct 337 ms 1040372 KB Output is correct
26 Correct 346 ms 1040400 KB Output is correct
27 Correct 337 ms 1040292 KB Output is correct
28 Correct 366 ms 1040208 KB Output is correct
29 Correct 346 ms 1040212 KB Output is correct
30 Correct 353 ms 1040212 KB Output is correct
31 Correct 353 ms 1040208 KB Output is correct
32 Correct 356 ms 1040296 KB Output is correct
33 Correct 372 ms 1040224 KB Output is correct
34 Correct 367 ms 1040260 KB Output is correct
35 Correct 350 ms 1040268 KB Output is correct
36 Correct 375 ms 1040316 KB Output is correct
37 Correct 359 ms 1040256 KB Output is correct
38 Correct 377 ms 1040252 KB Output is correct
39 Correct 357 ms 1040524 KB Output is correct
40 Correct 378 ms 1040240 KB Output is correct
41 Correct 353 ms 1040380 KB Output is correct
42 Correct 368 ms 1040248 KB Output is correct
43 Correct 357 ms 1040468 KB Output is correct
44 Correct 344 ms 1040308 KB Output is correct
45 Correct 356 ms 1040468 KB Output is correct
46 Correct 405 ms 1040188 KB Output is correct
47 Correct 369 ms 1040328 KB Output is correct
48 Correct 344 ms 1040464 KB Output is correct
49 Correct 343 ms 1040348 KB Output is correct
50 Correct 352 ms 1040324 KB Output is correct
51 Correct 342 ms 1040252 KB Output is correct
52 Correct 346 ms 1040528 KB Output is correct
53 Correct 338 ms 1040216 KB Output is correct
54 Correct 343 ms 1040368 KB Output is correct
55 Correct 340 ms 1040376 KB Output is correct
56 Correct 346 ms 1040292 KB Output is correct
57 Correct 336 ms 1040208 KB Output is correct
58 Correct 338 ms 1040208 KB Output is correct
59 Correct 375 ms 1040420 KB Output is correct
60 Correct 367 ms 1040348 KB Output is correct
61 Correct 386 ms 1040424 KB Output is correct
62 Correct 369 ms 1040208 KB Output is correct
63 Correct 380 ms 1040216 KB Output is correct
64 Correct 364 ms 1040448 KB Output is correct
65 Correct 371 ms 1040228 KB Output is correct
66 Correct 380 ms 1040664 KB Output is correct
67 Correct 387 ms 1040276 KB Output is correct
68 Correct 368 ms 1040284 KB Output is correct
69 Correct 378 ms 1040208 KB Output is correct
70 Correct 376 ms 1040284 KB Output is correct
71 Correct 366 ms 1040324 KB Output is correct
72 Correct 373 ms 1040656 KB Output is correct
73 Correct 360 ms 1040448 KB Output is correct
74 Correct 373 ms 1040280 KB Output is correct
75 Correct 364 ms 1040212 KB Output is correct
76 Correct 375 ms 1040420 KB Output is correct
77 Correct 375 ms 1040460 KB Output is correct
78 Correct 377 ms 1040456 KB Output is correct
79 Correct 364 ms 1040228 KB Output is correct
80 Correct 377 ms 1040208 KB Output is correct
81 Correct 371 ms 1040296 KB Output is correct
82 Correct 364 ms 1040300 KB Output is correct
83 Correct 380 ms 1040528 KB Output is correct
84 Correct 367 ms 1040208 KB Output is correct
85 Correct 367 ms 1040464 KB Output is correct
86 Correct 377 ms 1040396 KB Output is correct
87 Correct 366 ms 1040360 KB Output is correct
88 Correct 385 ms 1040296 KB Output is correct
89 Correct 377 ms 1040332 KB Output is correct
90 Correct 384 ms 1040212 KB Output is correct
91 Correct 404 ms 1040416 KB Output is correct
92 Correct 385 ms 1040212 KB Output is correct
93 Correct 377 ms 1040408 KB Output is correct