Submission #855948

# Submission time Handle Problem Language Result Execution time Memory
855948 2023-10-02T11:28:37 Z hariaakas646 Collecting Stamps 3 (JOI20_ho_t3) C++17
25 / 100
485 ms 129124 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<lli> vec(n+1), tim(n+1);
    frange(i, n) {
        sclld(vec[i+1]);
    }
    frange(i, n) {
        sclld(tim[i+1]);
    }

    vector<vector<vll>> dp1(n+1, vector<vll>(n+1, vll(n+1, 1e18))), dp2(n+1, vector<vll>(n+1, vll(n+1, 1e18)));
    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)]));

        }
    }

    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] < 1e18 || dp2[i][j][v] < 1e18) {
                    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: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]);
      |         ^~~~~
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(tim[i+1]);
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 1 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 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 1 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 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 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 348 KB Output is correct
24 Correct 0 ms 436 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 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 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 1 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 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 340 ms 94288 KB Output is correct
19 Correct 157 ms 45140 KB Output is correct
20 Correct 60 ms 17752 KB Output is correct
21 Correct 151 ms 41304 KB Output is correct
22 Correct 206 ms 60252 KB Output is correct
23 Correct 46 ms 14188 KB Output is correct
24 Correct 32 ms 9816 KB Output is correct
25 Correct 43 ms 13404 KB Output is correct
26 Correct 11 ms 3416 KB Output is correct
27 Correct 47 ms 14264 KB Output is correct
28 Correct 28 ms 8796 KB Output is correct
29 Correct 50 ms 14940 KB Output is correct
30 Correct 36 ms 10328 KB Output is correct
31 Correct 46 ms 13404 KB Output is correct
32 Correct 17 ms 5212 KB Output is correct
33 Correct 45 ms 13648 KB Output is correct
34 Correct 9 ms 3164 KB Output is correct
35 Correct 45 ms 13212 KB Output is correct
36 Correct 14 ms 4444 KB Output is correct
37 Correct 49 ms 14312 KB Output is correct
38 Correct 19 ms 6236 KB Output is correct
39 Correct 54 ms 15196 KB Output is correct
40 Correct 22 ms 7004 KB Output is correct
41 Correct 464 ms 129088 KB Output is correct
42 Correct 267 ms 71620 KB Output is correct
43 Correct 467 ms 129116 KB Output is correct
44 Correct 260 ms 69968 KB Output is correct
45 Correct 462 ms 129108 KB Output is correct
46 Correct 268 ms 71808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 1 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 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 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 348 KB Output is correct
24 Correct 0 ms 436 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 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 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 340 ms 94288 KB Output is correct
37 Correct 157 ms 45140 KB Output is correct
38 Correct 60 ms 17752 KB Output is correct
39 Correct 151 ms 41304 KB Output is correct
40 Correct 206 ms 60252 KB Output is correct
41 Correct 46 ms 14188 KB Output is correct
42 Correct 32 ms 9816 KB Output is correct
43 Correct 43 ms 13404 KB Output is correct
44 Correct 11 ms 3416 KB Output is correct
45 Correct 47 ms 14264 KB Output is correct
46 Correct 28 ms 8796 KB Output is correct
47 Correct 50 ms 14940 KB Output is correct
48 Correct 36 ms 10328 KB Output is correct
49 Correct 46 ms 13404 KB Output is correct
50 Correct 17 ms 5212 KB Output is correct
51 Correct 45 ms 13648 KB Output is correct
52 Correct 9 ms 3164 KB Output is correct
53 Correct 45 ms 13212 KB Output is correct
54 Correct 14 ms 4444 KB Output is correct
55 Correct 49 ms 14312 KB Output is correct
56 Correct 19 ms 6236 KB Output is correct
57 Correct 54 ms 15196 KB Output is correct
58 Correct 22 ms 7004 KB Output is correct
59 Correct 464 ms 129088 KB Output is correct
60 Correct 267 ms 71620 KB Output is correct
61 Correct 467 ms 129116 KB Output is correct
62 Correct 260 ms 69968 KB Output is correct
63 Correct 462 ms 129108 KB Output is correct
64 Correct 268 ms 71808 KB Output is correct
65 Correct 405 ms 110928 KB Output is correct
66 Correct 376 ms 97664 KB Output is correct
67 Correct 347 ms 91224 KB Output is correct
68 Correct 296 ms 80720 KB Output is correct
69 Correct 395 ms 108648 KB Output is correct
70 Correct 386 ms 102224 KB Output is correct
71 Correct 382 ms 104156 KB Output is correct
72 Correct 392 ms 105272 KB Output is correct
73 Correct 334 ms 94292 KB Output is correct
74 Correct 297 ms 85340 KB Output is correct
75 Correct 354 ms 98652 KB Output is correct
76 Correct 445 ms 121620 KB Output is correct
77 Correct 465 ms 121624 KB Output is correct
78 Correct 308 ms 82768 KB Output is correct
79 Correct 301 ms 86492 KB Output is correct
80 Correct 448 ms 117984 KB Output is correct
81 Correct 313 ms 88412 KB Output is correct
82 Correct 352 ms 95580 KB Output is correct
83 Correct 485 ms 129124 KB Output is correct
84 Correct 398 ms 101972 KB Output is correct
85 Incorrect 471 ms 115608 KB Output isn't correct
86 Halted 0 ms 0 KB -