QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#129755#4366. Forever YoungSwarthmore#AC ✓6ms3880kbC++173.9kb2023-07-22 23:08:522023-07-22 23:08:55

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-22 23:08:55]
  • 评测
  • 测评结果:AC
  • 用时:6ms
  • 内存:3880kb
  • [2023-07-22 23:08:52]
  • 提交

answer

#include "bits/stdc++.h"
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define dbg(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define dbg(x...)
#endif


const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; 

ll mul(ll A, ll B) {
    if (A == 0 || B == 0) return 0;
    if (log10(A) + log10(B) > 18.3) return 2e18;
    return A*B;
}
ll add(ll A, ll B) {
    return min(A+B, (ll) 2e18);
}

void solve() {
    ll Y, L; cin >> Y >> L;
    ll ans = 10;
    FOR(i, 10, 1000110) {
        vl digs;
        ll cur = Y;
        ll res = 0;
        while (cur) {
            if (cur%i >= 10) goto done;
            digs.pb(cur%i);
            cur /= i;
        }
        reverse(all(digs));
        res = 0; trav(a, digs) {
            res *= 10; res += a;
        }
        if (res >= L) {
            ans = i;
        }
        done:;
    }

    F0R(a, 10) {
        F0R(b, 10) {
            F0R(c, 10) {
                if (100*a+10*b+c < L) continue;
                ll lo = 2, hi = 2e18;
                while (lo < hi) {
                    ll mid = (lo+hi+1)/2;
                    if (add(c, add(mul(b, mid), mul(mul(mid, mid), a))) <= Y) {
                        lo = mid;
                    } else hi = mid-1;
                }
                if (add(c, add(mul(b, lo), mul(mul(lo, lo), a))) == Y) {
                    ckmax(ans, lo);
                }
            }
        }
    }
    cout << ans << nl;

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

    int T = 1;
//    cin >> T;
    while(T--) {
        solve();
    }

	return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 3752kb

input:

32 20

output:

16

result:

ok single line: '16'

Test #2:

score: 0
Accepted
time: 3ms
memory: 3788kb

input:

2016 100

output:

42

result:

ok single line: '42'

Test #3:

score: 0
Accepted
time: 6ms
memory: 3824kb

input:

1000000000000000000 10

output:

1000000000000000000

result:

ok single line: '1000000000000000000'

Test #4:

score: 0
Accepted
time: 5ms
memory: 3848kb

input:

149239876439186 470

output:

11

result:

ok single line: '11'

Test #5:

score: 0
Accepted
time: 6ms
memory: 3744kb

input:

4851495 95

output:

539054

result:

ok single line: '539054'

Test #6:

score: 0
Accepted
time: 2ms
memory: 3508kb

input:

19839853985 19839853985

output:

10

result:

ok single line: '10'

Test #7:

score: 0
Accepted
time: 6ms
memory: 3852kb

input:

1000000000000000000 17

output:

999999999999999993

result:

ok single line: '999999999999999993'

Test #8:

score: 0
Accepted
time: 6ms
memory: 3852kb

input:

1000000000000000000 23

output:

499999999999999998

result:

ok single line: '499999999999999998'

Test #9:

score: 0
Accepted
time: 6ms
memory: 3744kb

input:

1000000000000000000 58

output:

166666666666666666

result:

ok single line: '166666666666666666'

Test #10:

score: 0
Accepted
time: 4ms
memory: 3824kb

input:

1000000000000000000 145

output:

999999997

result:

ok single line: '999999997'

Test #11:

score: 0
Accepted
time: 6ms
memory: 3656kb

input:

1000000000000000000 230

output:

500000000

result:

ok single line: '500000000'

Test #12:

score: 0
Accepted
time: 4ms
memory: 3600kb

input:

1000000000000000000 1050

output:

999999

result:

ok single line: '999999'

Test #13:

score: 0
Accepted
time: 4ms
memory: 3524kb

input:

1000000000000000000 9593

output:

1000

result:

ok single line: '1000'

Test #14:

score: 0
Accepted
time: 1ms
memory: 3480kb

input:

1000000000000000000 1000000000000000000

output:

10

result:

ok single line: '10'

Test #15:

score: 0
Accepted
time: 4ms
memory: 3740kb

input:

981759819857981583 10

output:

981759819857981583

result:

ok single line: '981759819857981583'

Test #16:

score: 0
Accepted
time: 3ms
memory: 3876kb

input:

981759819857981583 17

output:

981759819857981576

result:

ok single line: '981759819857981576'

Test #17:

score: 0
Accepted
time: 3ms
memory: 3828kb

input:

981759819857981583 23

output:

490879909928990790

result:

ok single line: '490879909928990790'

Test #18:

score: 0
Accepted
time: 6ms
memory: 3744kb

input:

981759819857981583 58

output:

196351963971596315

result:

ok single line: '196351963971596315'

Test #19:

score: 0
Accepted
time: 4ms
memory: 3804kb

input:

981759819857981583 140

output:

10

result:

ok single line: '10'

Test #20:

score: 0
Accepted
time: 6ms
memory: 3864kb

input:

981759819857981583 230

output:

10

result:

ok single line: '10'

Test #21:

score: 0
Accepted
time: 4ms
memory: 3420kb

input:

981759819857981583 1050

output:

10

result:

ok single line: '10'

Test #22:

score: 0
Accepted
time: 4ms
memory: 3580kb

input:

981759819857981583 9593

output:

10

result:

ok single line: '10'

Test #23:

score: 0
Accepted
time: 4ms
memory: 3416kb

input:

981759819857981583 74292

output:

10

result:

ok single line: '10'

Test #24:

score: 0
Accepted
time: 6ms
memory: 3572kb

input:

140986742987698176 10

output:

140986742987698176

result:

ok single line: '140986742987698176'

Test #25:

score: 0
Accepted
time: 4ms
memory: 3796kb

input:

158918593147583853 849

output:

10

result:

ok single line: '10'

Test #26:

score: 0
Accepted
time: 6ms
memory: 3744kb

input:

206808958398095782 82

output:

25851119799761972

result:

ok single line: '25851119799761972'

Test #27:

score: 0
Accepted
time: 6ms
memory: 3764kb

input:

675097804382958295 123

output:

12

result:

ok single line: '12'

Test #28:

score: 0
Accepted
time: 6ms
memory: 3712kb

input:

782891909194182377 95

output:

86987989910464708

result:

ok single line: '86987989910464708'

Test #29:

score: 0
Accepted
time: 3ms
memory: 3532kb

input:

782891909194182377 96

output:

25012

result:

ok single line: '25012'

Test #30:

score: 0
Accepted
time: 4ms
memory: 3520kb

input:

782891909194182377 30000

output:

11

result:

ok single line: '11'

Test #31:

score: 0
Accepted
time: 6ms
memory: 3748kb

input:

988246947114416919 93

output:

109805216346046324

result:

ok single line: '109805216346046324'

Test #32:

score: 0
Accepted
time: 6ms
memory: 3756kb

input:

988246947114416919 95

output:

26512

result:

ok single line: '26512'

Test #33:

score: 0
Accepted
time: 4ms
memory: 3516kb

input:

988246947114416919 29000

output:

10

result:

ok single line: '10'

Test #34:

score: 0
Accepted
time: 6ms
memory: 3880kb

input:

9000630015000129 100

output:

100002

result:

ok single line: '100002'

Test #35:

score: 0
Accepted
time: 6ms
memory: 3656kb

input:

999996640752785561 100

output:

31622

result:

ok single line: '31622'

Test #36:

score: 0
Accepted
time: 6ms
memory: 3732kb

input:

10 10

output:

10

result:

ok single line: '10'

Test #37:

score: 0
Accepted
time: 6ms
memory: 3736kb

input:

11 10

output:

11

result:

ok single line: '11'

Test #38:

score: 0
Accepted
time: 6ms
memory: 3740kb

input:

19 13

output:

16

result:

ok single line: '16'

Test #39:

score: 0
Accepted
time: 6ms
memory: 3664kb

input:

949986743716085769 100

output:

983040

result:

ok single line: '983040'

Test #40:

score: 0
Accepted
time: 6ms
memory: 3780kb

input:

801548868891525129 100

output:

737280

result:

ok single line: '737280'

Test #41:

score: 0
Accepted
time: 6ms
memory: 3800kb

input:

926093549141544969 100

output:

675841

result:

ok single line: '675841'

Test #42:

score: 0
Accepted
time: 6ms
memory: 3576kb

input:

949980220730081289 100

output:

491520

result:

ok single line: '491520'

Test #43:

score: 0
Accepted
time: 6ms
memory: 3744kb

input:

618476800577126409 100

output:

409600

result:

ok single line: '409600'

Test #44:

score: 0
Accepted
time: 3ms
memory: 3580kb

input:

890865346255534089 100

output:

30720

result:

ok single line: '30720'

Test #45:

score: 0
Accepted
time: 3ms
memory: 3660kb

input:

859144460042470409 99

output:

25600

result:

ok single line: '25600'

Test #46:

score: 0
Accepted
time: 6ms
memory: 3840kb

input:

845488492963637769 100

output:

23040

result:

ok single line: '23040'

Test #47:

score: 0
Accepted
time: 4ms
memory: 3828kb

input:

896892642854698249 92

output:

21760

result:

ok single line: '21760'

Test #48:

score: 0
Accepted
time: 6ms
memory: 3824kb

input:

994907428831831689 100

output:

21120

result:

ok single line: '21120'

Test #49:

score: 0
Accepted
time: 6ms
memory: 3748kb

input:

836899046557320969 100

output:

3840

result:

ok single line: '3840'

Test #50:

score: 0
Accepted
time: 6ms
memory: 3796kb

input:

949986743716085769 99

output:

105554082635120640

result:

ok single line: '105554082635120640'

Test #51:

score: 0
Accepted
time: 6ms
memory: 3532kb

input:

801548868891525129 99

output:

89060985432391680

result:

ok single line: '89060985432391680'

Test #52:

score: 0
Accepted
time: 4ms
memory: 3852kb

input:

926093549141544969 99

output:

102899283237949440

result:

ok single line: '102899283237949440'

Test #53:

score: 0
Accepted
time: 6ms
memory: 3792kb

input:

949980220730081289 99

output:

105553357858897920

result:

ok single line: '105553357858897920'

Test #54:

score: 0
Accepted
time: 6ms
memory: 3868kb

input:

618476800577126409 99

output:

68719644508569600

result:

ok single line: '68719644508569600'

Test #55:

score: 0
Accepted
time: 6ms
memory: 3576kb

input:

890865346255534089 99

output:

98985038472837120

result:

ok single line: '98985038472837120'

Test #56:

score: 0
Accepted
time: 6ms
memory: 3856kb

input:

859144460042470409 98

output:

95460495560274489

result:

ok single line: '95460495560274489'

Test #57:

score: 0
Accepted
time: 3ms
memory: 3752kb

input:

845488492963637769 99

output:

93943165884848640

result:

ok single line: '93943165884848640'

Test #58:

score: 0
Accepted
time: 6ms
memory: 3792kb

input:

896892642854698249 91

output:

99654738094966472

result:

ok single line: '99654738094966472'

Test #59:

score: 0
Accepted
time: 2ms
memory: 3828kb

input:

994907428831831689 99

output:

110545269870203520

result:

ok single line: '110545269870203520'

Test #60:

score: 0
Accepted
time: 3ms
memory: 3660kb

input:

836899046557320969 99

output:

92988782950813440

result:

ok single line: '92988782950813440'