답안 #610586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
610586 2022-07-28T11:01:40 Z ishmam8683 Self Study (JOI22_ho_t2) C++14
62 / 100
232 ms 16180 KB
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <array>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <iomanip>
#include <cstring>
#include <string> // for getline
using namespace std;

#define endl "\n"
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define e emplace

template <typename T> istream& operator>>(istream &is, vector<T>& a) { for (auto& i : a) is >> i; return is; }
template <typename T> ostream& operator<<(ostream& os, vector<T>& a) { for (auto& i : a) os << i << " "; return os; };
// template <typename T> ostream& operator<<(ostream &os, const vector<T>& v) { os << '{'; string s; for (const auto &x : v) os << s << x, s = " "; return os << '}'; }
template <typename A, typename B> istream& operator>>(istream& is, pair<A, B>& i) { return is >> i.ff >> i.ss; }
template <typename A, typename B> ostream& operator<<(ostream& os, const pair<A, B>& i) { return os << i.ff << " " << i.ss; }
// template <typename A, typename B> ostream& operator<<(ostream& os, const pair<A, B>& i) { return os << '{' << i.ff << ", " << i.ss << '}'; }
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

using ll = long long;
using ld = long double;
using pii = pair<int, int>; using pli = pair<ll, int>; using pil = pair<int, ll>;
using pll = pair<ll, ll>;   using vl = vector<ll>;     using vvl = vector<vl>;
using vi = vector<int>;     using vb = vector<bool>;   using vc = vector<char>;
using vvi = vector<vi>;     using vvb = vector<vb>;    using vvc = vector<vc>;
using vpii = vector<pii>;   using vpll = vector<pll>;  using vs = vector<string>;
using tiii = tuple<int, int, int>; using vtiii = vector<tiii>;
template <class A, class B> using umap = unordered_map<A, B>;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bug cerr << "!Bugged..." << endl
#define add(x, y) (x + y >= MOD ? x + y - MOD : x + y)

const vs cq = { "NO", "YES"};
const int dx[8] = { -1,  0, 0, 1, 1,  1, -1, -1};
const int dy[8] = { 0, -1, 1, 0, 1, -1,  1, -1};
const int INF = 2147483647;
const ll LINF = 9223372036854775807;
const int MOD = 1e9 + 7;
const int maxn = 1e5 + 1;

int main()
{
#ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    freopen("error.txt", "a", stderr);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    // cout.tie(NULL);

    int ttt(1);
    // cin >> ttt;
    for (int itt = 1; itt <= ttt; itt++)
    {
        ll n, m;
        cin >> n >> m;
        vl a(n); cin >> a;
        vl b(n); cin >> b;
        vl c(n);
        for (int i = 0; i < n; i++) {
            c[i] = max(a[i], b[i]);
        }

        ll l = 0, r = 1e16, ans;
        auto chk = [&](ll x) {
            ll days = n * m;
            vl cur(n, x); // c[i] * g >= x;
            for (int i = 0; i < n; ++i) {
                ll g = (x + c[i] - 1) / c[i];
                if (b[i] >= a[i]) {
                    cur[i] -= c[i] * g;
                    days -= g;
                } else {
                    // a[i] > b[i];
                    g = min(g, m);
                    cur[i] -= c[i] * g;
                    days -= g;
                }
                if (days < 0) return false;
            }
            for (int i = 0; i < n; ++i) {
                if (cur[i] > 0) {
                    ll g = (cur[i] + b[i] - 1) / b[i];
                    days -= g;
                }
                if (days < 0) return false;
            }
            // debug(x, days);
            // debug(cur);
            return true;
        };
        while (l <= r) {
            ll mid = l + r >> 1;
            if (chk(mid)) l = mid + 1, ans = mid;
            else r = mid - 1;
        }
        cout << ans;

    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:113:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  113 |             ll mid = l + r >> 1;
      |                      ~~^~~
Main.cpp:65:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     freopen("error.txt", "a", stderr);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 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 1 ms 328 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 121 ms 15436 KB Output is correct
12 Correct 120 ms 15648 KB Output is correct
13 Correct 104 ms 13456 KB Output is correct
14 Correct 152 ms 13532 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 41 ms 10896 KB Output is correct
17 Correct 157 ms 16180 KB Output is correct
18 Correct 117 ms 15524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 41 ms 10896 KB Output is correct
3 Correct 157 ms 16180 KB Output is correct
4 Correct 117 ms 15524 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 368 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 66 ms 7928 KB Output is correct
14 Correct 36 ms 5392 KB Output is correct
15 Correct 29 ms 4128 KB Output is correct
16 Correct 24 ms 3364 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 324 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 3 ms 584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 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 1 ms 328 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 121 ms 15436 KB Output is correct
12 Correct 120 ms 15648 KB Output is correct
13 Correct 104 ms 13456 KB Output is correct
14 Correct 152 ms 13532 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 368 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 66 ms 7928 KB Output is correct
24 Correct 36 ms 5392 KB Output is correct
25 Correct 29 ms 4128 KB Output is correct
26 Correct 24 ms 3364 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 324 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 3 ms 584 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 41 ms 10896 KB Output is correct
36 Correct 157 ms 16180 KB Output is correct
37 Correct 117 ms 15524 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 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 1 ms 336 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 4 ms 468 KB Output is correct
46 Correct 5 ms 852 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 24 ms 2896 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 3 ms 464 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 320 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 64 ms 7752 KB Output is correct
56 Correct 38 ms 4700 KB Output is correct
57 Correct 50 ms 4684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 368 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 66 ms 7928 KB Output is correct
10 Correct 36 ms 5392 KB Output is correct
11 Correct 29 ms 4128 KB Output is correct
12 Correct 24 ms 3364 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 324 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 3 ms 584 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 41 ms 10896 KB Output is correct
22 Correct 157 ms 16180 KB Output is correct
23 Correct 117 ms 15524 KB Output is correct
24 Correct 31 ms 2656 KB Output is correct
25 Correct 76 ms 7132 KB Output is correct
26 Correct 13 ms 1856 KB Output is correct
27 Correct 116 ms 15516 KB Output is correct
28 Correct 119 ms 15512 KB Output is correct
29 Correct 136 ms 15464 KB Output is correct
30 Correct 153 ms 15524 KB Output is correct
31 Incorrect 232 ms 15464 KB Output isn't correct
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 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 1 ms 328 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 121 ms 15436 KB Output is correct
12 Correct 120 ms 15648 KB Output is correct
13 Correct 104 ms 13456 KB Output is correct
14 Correct 152 ms 13532 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 368 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 66 ms 7928 KB Output is correct
24 Correct 36 ms 5392 KB Output is correct
25 Correct 29 ms 4128 KB Output is correct
26 Correct 24 ms 3364 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 324 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 3 ms 584 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 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 1 ms 336 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 4 ms 468 KB Output is correct
42 Correct 5 ms 852 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 24 ms 2896 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 3 ms 464 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 320 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 64 ms 7752 KB Output is correct
52 Correct 38 ms 4700 KB Output is correct
53 Correct 50 ms 4684 KB Output is correct
54 Correct 31 ms 2656 KB Output is correct
55 Correct 76 ms 7132 KB Output is correct
56 Correct 13 ms 1856 KB Output is correct
57 Correct 116 ms 15516 KB Output is correct
58 Correct 119 ms 15512 KB Output is correct
59 Correct 136 ms 15464 KB Output is correct
60 Correct 153 ms 15524 KB Output is correct
61 Incorrect 232 ms 15464 KB Output isn't correct
62 Halted 0 ms 0 KB -