Submission #855952

# Submission time Handle Problem Language Result Execution time Memory
855952 2023-10-02T11:38:51 Z hariaakas646 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
544 ms 130644 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;
    lli l;
    scd(n);
    sclld(l);
    vector<lli> vec(n+1), tim(n+1);
    frange(i, n) {
        sclld(vec[i+1]);
    }
    frange(i, n) {
        sclld(tim[i+1]);
    }
    tim[0] = -1;

    vector<vector<vll>> dp1(n+1, vector<vll>(n+1, vll(n+1, 2e18+5))), dp2(n+1, vector<vll>(n+1, vll(n+1, 2e18+5)));
    dp1[0][0][0] = dp2[0][0][0] = 0;
    forr(le, 1, n+1) {
        forr(j, 0, n+1) {
            int k = (j + le) % (n+1);
            int i = 0;
            dp1[j][k][i] = min(dp1[(j+1)%(n+1)][k][i] + (vec[(j+1) % (n+1)] - vec[j] + l) % l, dp2[(j+1) % (n+1)][k][i] + (vec[k] + l - vec[j]) % l);
            dp2[j][k][i] = min(dp1[j][(k-1+n+1)%(n+1)][i] + (l - vec[j] + vec[k]) % l, dp2[j][(k-1+n+1)%(n+1)][i] + (vec[k] + l - vec[(k-1+n+1)%(n+1)]) % l);

        }
    }

    forr(i, 1, n+1) {
        forr(le, 1, n+1) {
            forr(j, 0, n+1) {
                int k = (j + le) % (n+1);
                
                dp1[j][k][i] = min(dp1[(j+1)%(n+1)][k][i] + (vec[(j+1) % (n+1)] - vec[j] + l) % l, dp2[(j+1) % (n+1)][k][i] + (vec[k] + l - vec[j]) % l);
                if(dp1[(j+1)%(n+1)][k][i-1] + (vec[(j+1) % (n+1)] - vec[j] + l) % l <= tim[j]) {
                    dp1[j][k][i] = min(dp1[j][k][i], dp1[(j+1)%(n+1)][k][i-1] + (vec[(j+1) % (n+1)] - vec[j] + l) % l);
                }
                if(dp2[(j+1) % (n+1)][k][i-1] + (vec[k] + l - vec[j]) % l <= tim[j]) {
                    dp1[j][k][i] = min(dp1[j][k][i], dp2[(j+1) % (n+1)][k][i-1] + (vec[k] + l - vec[j]) % l);
                }

                dp2[j][k][i] = min(dp1[j][(k-1+n+1)%(n+1)][i] + (l - vec[j] + vec[k]) % l, dp2[j][(k-1+n+1)%(n+1)][i] + (vec[k] + l - vec[(k-1+n+1)%(n+1)]) % l);

                if(dp1[j][(k-1+n+1)%(n+1)][i-1] + (l - vec[j] + vec[k]) % l <= tim[k]) {
                    dp2[j][k][i] = min(dp2[j][k][i], dp1[j][(k-1+n+1)%(n+1)][i-1] + (l - vec[j] + vec[k]) % l);
                }
                if(dp2[j][(k-1+n+1)%(n+1)][i-1] + (vec[k] + l - vec[(k-1+n+1)%(n+1)]) % l <= tim[k]) {
                    dp2[j][k][i] = min(dp2[j][k][i], dp2[j][(k-1+n+1)%(n+1)][i-1] + (vec[k] + l - vec[(k-1+n+1)%(n+1)]) % l);
                }
            }
        }
    }
    for(int v=n; v>= 0; v--) {
        frange(i, n+1) {
            frange(j, n+1) {
                if(dp1[i][j][v] < 2e18+5 || dp2[i][j][v] < 2e18+5) {
                    printf("%d\n", v);
                    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:38:5: note: in expansion of macro 'scd'
   38 |     scd(n);
      |     ^~~
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:39:5: note: in expansion of macro 'sclld'
   39 |     sclld(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:42:9: note: in expansion of macro 'sclld'
   42 |         sclld(vec[i+1]);
      |         ^~~~~
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:45:9: note: in expansion of macro 'sclld'
   45 |         sclld(tim[i+1]);
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 344 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 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 344 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 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 360 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 344 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 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 353 ms 94528 KB Output is correct
19 Correct 157 ms 45072 KB Output is correct
20 Correct 63 ms 17928 KB Output is correct
21 Correct 145 ms 41308 KB Output is correct
22 Correct 208 ms 60248 KB Output is correct
23 Correct 45 ms 14172 KB Output is correct
24 Correct 32 ms 9816 KB Output is correct
25 Correct 44 ms 13400 KB Output is correct
26 Correct 10 ms 3672 KB Output is correct
27 Correct 48 ms 14428 KB Output is correct
28 Correct 29 ms 8796 KB Output is correct
29 Correct 51 ms 15080 KB Output is correct
30 Correct 35 ms 10332 KB Output is correct
31 Correct 47 ms 13660 KB Output is correct
32 Correct 17 ms 5212 KB Output is correct
33 Correct 45 ms 13492 KB Output is correct
34 Correct 9 ms 3164 KB Output is correct
35 Correct 47 ms 13148 KB Output is correct
36 Correct 14 ms 4884 KB Output is correct
37 Correct 50 ms 14428 KB Output is correct
38 Correct 19 ms 6236 KB Output is correct
39 Correct 53 ms 15376 KB Output is correct
40 Correct 23 ms 7004 KB Output is correct
41 Correct 494 ms 129108 KB Output is correct
42 Correct 276 ms 72020 KB Output is correct
43 Correct 513 ms 129028 KB Output is correct
44 Correct 264 ms 70224 KB Output is correct
45 Correct 496 ms 129120 KB Output is correct
46 Correct 280 ms 72016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 344 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 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 360 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 353 ms 94528 KB Output is correct
37 Correct 157 ms 45072 KB Output is correct
38 Correct 63 ms 17928 KB Output is correct
39 Correct 145 ms 41308 KB Output is correct
40 Correct 208 ms 60248 KB Output is correct
41 Correct 45 ms 14172 KB Output is correct
42 Correct 32 ms 9816 KB Output is correct
43 Correct 44 ms 13400 KB Output is correct
44 Correct 10 ms 3672 KB Output is correct
45 Correct 48 ms 14428 KB Output is correct
46 Correct 29 ms 8796 KB Output is correct
47 Correct 51 ms 15080 KB Output is correct
48 Correct 35 ms 10332 KB Output is correct
49 Correct 47 ms 13660 KB Output is correct
50 Correct 17 ms 5212 KB Output is correct
51 Correct 45 ms 13492 KB Output is correct
52 Correct 9 ms 3164 KB Output is correct
53 Correct 47 ms 13148 KB Output is correct
54 Correct 14 ms 4884 KB Output is correct
55 Correct 50 ms 14428 KB Output is correct
56 Correct 19 ms 6236 KB Output is correct
57 Correct 53 ms 15376 KB Output is correct
58 Correct 23 ms 7004 KB Output is correct
59 Correct 494 ms 129108 KB Output is correct
60 Correct 276 ms 72020 KB Output is correct
61 Correct 513 ms 129028 KB Output is correct
62 Correct 264 ms 70224 KB Output is correct
63 Correct 496 ms 129120 KB Output is correct
64 Correct 280 ms 72016 KB Output is correct
65 Correct 408 ms 110940 KB Output is correct
66 Correct 366 ms 97660 KB Output is correct
67 Correct 354 ms 91452 KB Output is correct
68 Correct 290 ms 80720 KB Output is correct
69 Correct 398 ms 108636 KB Output is correct
70 Correct 440 ms 101968 KB Output is correct
71 Correct 384 ms 104020 KB Output is correct
72 Correct 380 ms 105296 KB Output is correct
73 Correct 358 ms 94292 KB Output is correct
74 Correct 302 ms 85508 KB Output is correct
75 Correct 359 ms 98728 KB Output is correct
76 Correct 514 ms 121620 KB Output is correct
77 Correct 453 ms 121624 KB Output is correct
78 Correct 284 ms 82512 KB Output is correct
79 Correct 310 ms 86496 KB Output is correct
80 Correct 453 ms 117984 KB Output is correct
81 Correct 322 ms 88404 KB Output is correct
82 Correct 368 ms 95568 KB Output is correct
83 Correct 483 ms 129120 KB Output is correct
84 Correct 381 ms 101972 KB Output is correct
85 Correct 449 ms 115544 KB Output is correct
86 Correct 422 ms 111956 KB Output is correct
87 Correct 377 ms 98732 KB Output is correct
88 Correct 480 ms 130412 KB Output is correct
89 Correct 508 ms 130640 KB Output is correct
90 Correct 394 ms 100880 KB Output is correct
91 Correct 541 ms 130412 KB Output is correct
92 Correct 544 ms 130644 KB Output is correct
93 Correct 519 ms 126600 KB Output is correct