Submission #674406

# Submission time Handle Problem Language Result Execution time Memory
674406 2022-12-24T04:03:47 Z abysmal Self Study (JOI22_ho_t2) C++14
100 / 100
248 ms 13816 KB
#include<iostream>
#include<stdio.h>
#include<stdint.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>

using namespace std;

const int64_t INF = (int64_t) 1e18;
const int64_t mINF = (int64_t) 1e9 + 7;
const int64_t MOD = 998244353;
const int nbit = 11;
const int ndig = 10;
const int nchar = 26;
const int p1 = 31;
const int p2 = 53;
const int D = 4;
int dr[D] = {0, 1, 0, -1};
int dc[D] = {1, 0, -1, 0};
// 0 right // 1 down // 2 left // 3 up

struct Solution
{
    int n;
    int64_t m;
    vector<int64_t> a;
    vector<int64_t> b;
    vector<int64_t> c;
    Solution() {}

    void solve()
    {
        cin >> n >> m;
        a.resize(n);
        b.resize(n);
        c.resize(n);
        for(int i = 0; i < n; i++)
        {
            cin >> a[i];
        }

        for(int i = 0; i < n; i++)
        {
            cin >> b[i];

            if(b[i] > a[i]) a[i] = b[i];
            c[i] = a[i] * m;
        }

        int64_t ans = INF;
        int64_t l = 1;
        int64_t r = INF;

        while(l <= r)
        {
            int64_t mid = l + (r - l) / 2;

            if(check(mid))
            {
                ans = mid;
                l = mid + 1;
            }
            else r = mid - 1;
        }

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

    bool check(int64_t mid)
    {
        int64_t cnt = 0;
        for(int i = 0; i < n; i++)
        {
            if(c[i] < mid) continue;

            int64_t val = c[i] - mid;
            cnt += val / a[i];
        }

        for(int i = 0; i < n; i++)
        {
            if(c[i] >= mid) continue;

            int64_t val = mid - c[i];
            int64_t need = (val + b[i] - 1) / b[i];

            if(cnt < need) return false;
            cnt -= need;
        }

        return true;
    }

    int modsub(int t1, int t2)
    {
        int res = t1 - t2;
        if(res < 0) res += MOD;

        return res;
    }

    int modadd(int t1, int t2)
    {
        int res = t1 + t2;
        if(res >= MOD) res -= MOD;

        return res;
    }

    int modmul(int t1, int t2)
    {
        int64_t res = 1LL * t1 * t2;
        return (res % MOD);
    }

    bool BIT(int& mask, int& j)
    {
        return (mask & MASK(j));
    }

    int MASK(int j)
    {
        return (1 << j);
    }
};

void __startup()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
}

int main()
{
    __startup();
    int t = 1;
//    cin >> t;

    for(int i = 1; i <= t; i++)
    {
        Solution().solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 113 ms 13112 KB Output is correct
12 Correct 111 ms 13116 KB Output is correct
13 Correct 90 ms 11052 KB Output is correct
14 Correct 87 ms 11048 KB Output is correct
15 Correct 0 ms 316 KB Output is correct
16 Correct 47 ms 8516 KB Output is correct
17 Correct 110 ms 13752 KB Output is correct
18 Correct 108 ms 13112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 47 ms 8516 KB Output is correct
3 Correct 110 ms 13752 KB Output is correct
4 Correct 108 ms 13112 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 60 ms 6632 KB Output is correct
14 Correct 40 ms 4556 KB Output is correct
15 Correct 30 ms 3404 KB Output is correct
16 Correct 25 ms 2896 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 113 ms 13112 KB Output is correct
12 Correct 111 ms 13116 KB Output is correct
13 Correct 90 ms 11052 KB Output is correct
14 Correct 87 ms 11048 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 320 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 60 ms 6632 KB Output is correct
24 Correct 40 ms 4556 KB Output is correct
25 Correct 30 ms 3404 KB Output is correct
26 Correct 25 ms 2896 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 320 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 0 ms 316 KB Output is correct
35 Correct 47 ms 8516 KB Output is correct
36 Correct 110 ms 13752 KB Output is correct
37 Correct 108 ms 13112 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 3 ms 456 KB Output is correct
46 Correct 4 ms 596 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 21 ms 2516 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 316 KB Output is correct
51 Correct 3 ms 468 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 316 KB Output is correct
55 Correct 65 ms 6624 KB Output is correct
56 Correct 31 ms 3964 KB Output is correct
57 Correct 31 ms 3924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 60 ms 6632 KB Output is correct
10 Correct 40 ms 4556 KB Output is correct
11 Correct 30 ms 3404 KB Output is correct
12 Correct 25 ms 2896 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 0 ms 316 KB Output is correct
21 Correct 47 ms 8516 KB Output is correct
22 Correct 110 ms 13752 KB Output is correct
23 Correct 108 ms 13112 KB Output is correct
24 Correct 32 ms 2260 KB Output is correct
25 Correct 81 ms 6076 KB Output is correct
26 Correct 15 ms 1620 KB Output is correct
27 Correct 117 ms 13168 KB Output is correct
28 Correct 117 ms 13132 KB Output is correct
29 Correct 124 ms 13128 KB Output is correct
30 Correct 154 ms 13172 KB Output is correct
31 Correct 248 ms 13116 KB Output is correct
32 Correct 72 ms 8512 KB Output is correct
33 Correct 190 ms 13816 KB Output is correct
34 Correct 90 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 113 ms 13112 KB Output is correct
12 Correct 111 ms 13116 KB Output is correct
13 Correct 90 ms 11052 KB Output is correct
14 Correct 87 ms 11048 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 320 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 60 ms 6632 KB Output is correct
24 Correct 40 ms 4556 KB Output is correct
25 Correct 30 ms 3404 KB Output is correct
26 Correct 25 ms 2896 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 320 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 3 ms 456 KB Output is correct
42 Correct 4 ms 596 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 21 ms 2516 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 316 KB Output is correct
47 Correct 3 ms 468 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 316 KB Output is correct
51 Correct 65 ms 6624 KB Output is correct
52 Correct 31 ms 3964 KB Output is correct
53 Correct 31 ms 3924 KB Output is correct
54 Correct 32 ms 2260 KB Output is correct
55 Correct 81 ms 6076 KB Output is correct
56 Correct 15 ms 1620 KB Output is correct
57 Correct 117 ms 13168 KB Output is correct
58 Correct 117 ms 13132 KB Output is correct
59 Correct 124 ms 13128 KB Output is correct
60 Correct 154 ms 13172 KB Output is correct
61 Correct 248 ms 13116 KB Output is correct
62 Correct 72 ms 8512 KB Output is correct
63 Correct 190 ms 13816 KB Output is correct
64 Correct 90 ms 8536 KB Output is correct
65 Correct 0 ms 316 KB Output is correct
66 Correct 47 ms 8516 KB Output is correct
67 Correct 110 ms 13752 KB Output is correct
68 Correct 108 ms 13112 KB Output is correct
69 Correct 22 ms 1620 KB Output is correct
70 Correct 6 ms 588 KB Output is correct
71 Correct 1 ms 320 KB Output is correct
72 Correct 34 ms 2108 KB Output is correct
73 Correct 7 ms 724 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 120 ms 13132 KB Output is correct
76 Correct 129 ms 13112 KB Output is correct
77 Correct 140 ms 13112 KB Output is correct
78 Correct 173 ms 13108 KB Output is correct
79 Correct 226 ms 13112 KB Output is correct
80 Correct 247 ms 13240 KB Output is correct
81 Correct 164 ms 11060 KB Output is correct
82 Correct 164 ms 11084 KB Output is correct