Submission #855950

# Submission time Handle Problem Language Result Execution time Memory
855950 2023-10-02T11:34:59 Z hariaakas646 Collecting Stamps 3 (JOI20_ho_t3) C++17
25 / 100
573 ms 129128 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)]));

        }
    }

    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 348 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 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 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 352 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 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 348 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 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 352 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 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 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 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 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 388 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 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 348 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 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 352 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 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 352 ms 94528 KB Output is correct
19 Correct 154 ms 45080 KB Output is correct
20 Correct 61 ms 17756 KB Output is correct
21 Correct 146 ms 41556 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 9820 KB Output is correct
25 Correct 45 ms 13404 KB Output is correct
26 Correct 11 ms 3416 KB Output is correct
27 Correct 47 ms 14428 KB Output is correct
28 Correct 29 ms 8796 KB Output is correct
29 Correct 51 ms 14940 KB Output is correct
30 Correct 35 ms 10332 KB Output is correct
31 Correct 44 ms 13404 KB Output is correct
32 Correct 17 ms 5212 KB Output is correct
33 Correct 45 ms 13404 KB Output is correct
34 Correct 9 ms 3256 KB Output is correct
35 Correct 47 ms 13148 KB Output is correct
36 Correct 14 ms 4444 KB Output is correct
37 Correct 49 ms 14428 KB Output is correct
38 Correct 20 ms 6236 KB Output is correct
39 Correct 54 ms 15196 KB Output is correct
40 Correct 23 ms 7260 KB Output is correct
41 Correct 487 ms 128908 KB Output is correct
42 Correct 270 ms 71800 KB Output is correct
43 Correct 561 ms 129124 KB Output is correct
44 Correct 268 ms 70112 KB Output is correct
45 Correct 503 ms 129128 KB Output is correct
46 Correct 274 ms 71800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 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 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 352 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 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 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 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 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 388 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 352 ms 94528 KB Output is correct
37 Correct 154 ms 45080 KB Output is correct
38 Correct 61 ms 17756 KB Output is correct
39 Correct 146 ms 41556 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 9820 KB Output is correct
43 Correct 45 ms 13404 KB Output is correct
44 Correct 11 ms 3416 KB Output is correct
45 Correct 47 ms 14428 KB Output is correct
46 Correct 29 ms 8796 KB Output is correct
47 Correct 51 ms 14940 KB Output is correct
48 Correct 35 ms 10332 KB Output is correct
49 Correct 44 ms 13404 KB Output is correct
50 Correct 17 ms 5212 KB Output is correct
51 Correct 45 ms 13404 KB Output is correct
52 Correct 9 ms 3256 KB Output is correct
53 Correct 47 ms 13148 KB Output is correct
54 Correct 14 ms 4444 KB Output is correct
55 Correct 49 ms 14428 KB Output is correct
56 Correct 20 ms 6236 KB Output is correct
57 Correct 54 ms 15196 KB Output is correct
58 Correct 23 ms 7260 KB Output is correct
59 Correct 487 ms 128908 KB Output is correct
60 Correct 270 ms 71800 KB Output is correct
61 Correct 561 ms 129124 KB Output is correct
62 Correct 268 ms 70112 KB Output is correct
63 Correct 503 ms 129128 KB Output is correct
64 Correct 274 ms 71800 KB Output is correct
65 Correct 416 ms 110940 KB Output is correct
66 Correct 376 ms 97672 KB Output is correct
67 Correct 357 ms 91456 KB Output is correct
68 Correct 306 ms 80980 KB Output is correct
69 Correct 417 ms 108632 KB Output is correct
70 Correct 367 ms 101716 KB Output is correct
71 Correct 427 ms 104152 KB Output is correct
72 Correct 399 ms 105268 KB Output is correct
73 Correct 343 ms 94536 KB Output is correct
74 Correct 304 ms 85584 KB Output is correct
75 Correct 371 ms 98640 KB Output is correct
76 Correct 481 ms 121620 KB Output is correct
77 Correct 477 ms 121620 KB Output is correct
78 Correct 288 ms 82640 KB Output is correct
79 Correct 324 ms 86356 KB Output is correct
80 Correct 466 ms 118096 KB Output is correct
81 Correct 329 ms 88412 KB Output is correct
82 Correct 361 ms 95564 KB Output is correct
83 Correct 573 ms 129116 KB Output is correct
84 Correct 380 ms 101968 KB Output is correct
85 Incorrect 472 ms 115796 KB Output isn't correct
86 Halted 0 ms 0 KB -