제출 #95666

#제출 시각아이디문제언어결과실행 시간메모리
95666jeffGap (APIO16_gap)C++14
0 / 100
38 ms2296 KiB
#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
 
inline unsigned long long mde(unsigned long long a, unsigned long long b, unsigned long long c) {
    unsigned long long t = 0, y = 0, z = 0, i;
    stack<unsigned long long> st;
    while (b) st.push(b % 2), b /= 2;
    while (!st.empty()) {
        z *= 2;
        y *= 2;
        z += a * st.top();
        st.pop();
        y += z / (1LL << 62);
        z %= (1LL << 62);
    }
    t += y / c;
    y %= c;
    for (i = 0; i < 62; ++i) {
        y *= 10;
        z *= 10;
        t *= 10;
        y += z / (1LL << 62);
        z %= (1LL << 62);
        t += y / c;
        y %= c;
    }
    return t;
}
 
long long findGap(int T, int N) {
    long long l, r, y, z, ls = -1, rs = 0, a, b = 0, i;
    MinMax(0, 1000000000000000000, &y, &z);
    assert((long long) mde(z - y, N - 1, N - 1) == z - y); 
    for (i = 0; i < N - 1; ++i) {
        a = y + mde(z - y, i, N - 1);
        b = y + mde(z - y, i + 1, N - 1) - 1;
        if (a >= b) continue;
        MinMax(a, b, &l, &r);
        if (l < 0 && r < 0) continue;
        if (ls > -1) rs = max(rs, l - ls);
        ls = r;
    }
	return max(rs, z - ls);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...