답안 #915452

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
915452 2024-01-24T00:04:20 Z HorizonWest Self Study (JOI22_ho_t2) C++17
100 / 100
398 ms 16284 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define endl '\n'
#define db double
#define ll long long
#define pb push_back
#define fs first
#define sd second
#define Mod long(1e9 + 7)
#define all(x) x.begin(), x.end()
#define unvisited long(-1)
#define Eps double(1e-9)
#define _for(i, n) for(int i = 0; i < (n); i++)
#define dbg(x) cout << #x ": " << x << endl;

long long Max = 1e6 + 7, Inf = 2e18;

void print(bool x) { cout << (x ? "Yes" : "No") << endl; }

int ans = 0;

bool can(vector <int> &a, vector <int> &b, vector <int> &c, int x)
{ //  cout << x << endl;
    int win = 0LL, lose = 0LL, n = (int) c.size();

    vector <int> r(n);

    for(int i = 0; i < n; i++)
    {
        int v = abs(c[i] - x);

        if(c[i] > x)
        {
            r[i] = c[i] - a[i] * (v / a[i]);
            win = win + abs((int) v / a[i]);
        }

        if(c[i] < x)
        {
            r[i] = c[i] + b[i] * (v/b[i] + ((v%b[i]) != 0));
            lose = lose + abs((int) v / b[i]) + abs((int) ((v%b[i]) != 0));
        }
/*
        if(win > lose) { win -= lose; lose = 0; }
        if(lose > win) { lose -= win; win = 0; }*/

        if(lose > Inf || win > Inf) return false;

        if(c[i] == x) r[i] = c[i];
    }

    bool op = true;

    if(win >= lose)
    {
        //cout << x << endl;
        int temp = Inf;
        for(int i = 0; i < n; i++)
        {
           // cout << r[i] << endl;
             if(r[i] < x) op = false;
             temp = min(temp, r[i]);
        }
       // cout << temp << endl;
        ans = max(ans, temp);
        return op;
    }
    else
        return false;


    return win >= lose;
}

/*
3 3
19 4 5
2 6 2

4 25
1 2 3 4
1 2 3 4
*/

void solve()
{
    int n, m; cin >> n >> m;
    vector <int> a(n), b(n), c(n);
    for(auto& u : a) cin >> u;
    for(auto& u : b) cin >> u;

    int rx = Inf;

    for(int i = 0; i < n; i++)
    {
        a[i] = max(a[i], b[i]);
        c[i] = a[i] * m;
        rx = min(rx, c[i]);
    }

    if(m == 1)
    {
        cout << rx << endl;
        return;
    }

    int l = 0, r = Inf;

    while(abs(l - r) != 1)
    {
        int middle = (l + r) / 2;

        if(can(a, b, c, middle))
            l = middle;
        else
            r = middle;
    }

/*
    for(int i = max(1LL, l - 10LL); i < l + 10LL; i++)
        if(can(a, b, c, i)) l = i;*/

    cout << ans << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

   // freopen("02-18.in", "r", stdin);
   // freopen("output.txt", "w", stdout);

    int Q = 1; //cin >> Q;

    while(Q--)
    {
        solve();
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 48 ms 13104 KB Output is correct
12 Correct 48 ms 13240 KB Output is correct
13 Correct 38 ms 11092 KB Output is correct
14 Correct 38 ms 11088 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 25 ms 8524 KB Output is correct
17 Correct 64 ms 13760 KB Output is correct
18 Correct 47 ms 13232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 25 ms 8524 KB Output is correct
3 Correct 64 ms 13760 KB Output is correct
4 Correct 47 ms 13232 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 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 131 ms 8016 KB Output is correct
14 Correct 88 ms 5468 KB Output is correct
15 Correct 70 ms 4264 KB Output is correct
16 Correct 55 ms 3572 KB Output is correct
17 Correct 1 ms 344 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 452 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 5 ms 604 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 48 ms 13104 KB Output is correct
12 Correct 48 ms 13240 KB Output is correct
13 Correct 38 ms 11092 KB Output is correct
14 Correct 38 ms 11088 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 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 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 131 ms 8016 KB Output is correct
24 Correct 88 ms 5468 KB Output is correct
25 Correct 70 ms 4264 KB Output is correct
26 Correct 55 ms 3572 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 452 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 5 ms 604 KB Output is correct
33 Correct 4 ms 468 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 25 ms 8524 KB Output is correct
36 Correct 64 ms 13760 KB Output is correct
37 Correct 47 ms 13232 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 464 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 5 ms 600 KB Output is correct
46 Correct 8 ms 916 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 45 ms 3016 KB Output is correct
49 Correct 1 ms 452 KB Output is correct
50 Correct 1 ms 456 KB Output is correct
51 Correct 5 ms 696 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 134 ms 8028 KB Output is correct
56 Correct 83 ms 4696 KB Output is correct
57 Correct 78 ms 4856 KB Output is correct
# 결과 실행 시간 메모리 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 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 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 131 ms 8016 KB Output is correct
10 Correct 88 ms 5468 KB Output is correct
11 Correct 70 ms 4264 KB Output is correct
12 Correct 55 ms 3572 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 452 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 5 ms 604 KB Output is correct
19 Correct 4 ms 468 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 25 ms 8524 KB Output is correct
22 Correct 64 ms 13760 KB Output is correct
23 Correct 47 ms 13232 KB Output is correct
24 Correct 59 ms 2796 KB Output is correct
25 Correct 142 ms 7252 KB Output is correct
26 Correct 30 ms 1892 KB Output is correct
27 Correct 262 ms 15636 KB Output is correct
28 Correct 263 ms 15428 KB Output is correct
29 Correct 266 ms 15628 KB Output is correct
30 Correct 293 ms 15440 KB Output is correct
31 Correct 398 ms 15748 KB Output is correct
32 Correct 235 ms 11008 KB Output is correct
33 Correct 252 ms 16284 KB Output is correct
34 Correct 244 ms 11016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 48 ms 13104 KB Output is correct
12 Correct 48 ms 13240 KB Output is correct
13 Correct 38 ms 11092 KB Output is correct
14 Correct 38 ms 11088 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 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 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 131 ms 8016 KB Output is correct
24 Correct 88 ms 5468 KB Output is correct
25 Correct 70 ms 4264 KB Output is correct
26 Correct 55 ms 3572 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 452 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 5 ms 604 KB Output is correct
33 Correct 4 ms 468 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 464 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 5 ms 600 KB Output is correct
42 Correct 8 ms 916 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 45 ms 3016 KB Output is correct
45 Correct 1 ms 452 KB Output is correct
46 Correct 1 ms 456 KB Output is correct
47 Correct 5 ms 696 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 134 ms 8028 KB Output is correct
52 Correct 83 ms 4696 KB Output is correct
53 Correct 78 ms 4856 KB Output is correct
54 Correct 59 ms 2796 KB Output is correct
55 Correct 142 ms 7252 KB Output is correct
56 Correct 30 ms 1892 KB Output is correct
57 Correct 262 ms 15636 KB Output is correct
58 Correct 263 ms 15428 KB Output is correct
59 Correct 266 ms 15628 KB Output is correct
60 Correct 293 ms 15440 KB Output is correct
61 Correct 398 ms 15748 KB Output is correct
62 Correct 235 ms 11008 KB Output is correct
63 Correct 252 ms 16284 KB Output is correct
64 Correct 244 ms 11016 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 25 ms 8524 KB Output is correct
67 Correct 64 ms 13760 KB Output is correct
68 Correct 47 ms 13232 KB Output is correct
69 Correct 38 ms 1880 KB Output is correct
70 Correct 11 ms 864 KB Output is correct
71 Correct 1 ms 344 KB Output is correct
72 Correct 56 ms 2652 KB Output is correct
73 Correct 12 ms 856 KB Output is correct
74 Correct 1 ms 348 KB Output is correct
75 Correct 263 ms 15628 KB Output is correct
76 Correct 271 ms 15752 KB Output is correct
77 Correct 285 ms 15444 KB Output is correct
78 Correct 316 ms 15808 KB Output is correct
79 Correct 365 ms 15620 KB Output is correct
80 Correct 379 ms 15652 KB Output is correct
81 Correct 249 ms 13616 KB Output is correct
82 Correct 241 ms 13628 KB Output is correct