Submission #941114

# Submission time Handle Problem Language Result Execution time Memory
941114 2024-03-08T07:22:38 Z Pring Self Study (JOI22_ho_t2) C++17
0 / 100
5 ms 4700 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef MIKU
const string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif

#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;

const int MXN = 300005, INF = 3.9e18;
int n, m, a[MXN], b[MXN];

__int128_t DC(__int128_t a, __int128_t b) {
    if (a == 0) return 0;
    return (a - 1) / b + 1;
}

bool check(__int128_t x) {
    auto f = [&](__int128 x, int a, int b) -> __int128_t {
        if (DC(x, a) <= m) return m - DC(x, a);
        x -= a * m;
        return -DC(x, b);
    };
    __int128_t now = 0;
    FOR(i, 0, n) {
        if (a[i] > b[i]) now += f(x, a[i], b[i]);
        else {
            now += m;
            now -= DC(x, b[i]);
        }
    }
    return (now >= 0);
}

int miku() {
    cin >> n >> m;
    FOR(i, 0, n) cin >> a[i];
    FOR(i, 0, n) cin >> b[i];
    __int128_t l = 0, r = INF;
    r *= INF;
    while (l + 1 < r) {
        __int128_t mid = (l + r) / 2;
        (check(mid) ? l : r) = mid;
    }
    return l;
}

int check() {
    int ans = LLONG_MAX;
    FOR(i, 0, n) ans = min(ans, max(a[i], b[i]));
    return ans;
}

void PRINT() {
    debug();
    cout << n << ' ' << m << '\n';
    FOR(i, 0, n) cout << a[i] << ' ';
    cout << '\n';
    FOR(i, 0, n) cout << b[i] << ' ';
    cout << '\n';
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    // cout << miku() << '\n';
    int t;
    cin >> t;
    while (t--) {
        int x = miku();
        int y = check();
        if (x != y) {
            PRINT();
            return 0;
        }
    }
    return 0;
}

Compilation message

Main.cpp: In function 'void PRINT()':
Main.cpp:11:20: warning: statement has no effect [-Wunused-value]
   11 | #define debug(...) 39
      |                    ^~
Main.cpp:66:5: note: in expansion of macro 'debug'
   66 |     debug();
      |     ^~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 4700 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 4700 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 4700 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 4700 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 4700 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -