QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#389244 | #4366. Forever Young | TWTP_TCTF# | WA | 4ms | 3880kb | C++20 | 1.9kb | 2024-04-14 07:53:35 | 2024-04-14 07:53:36 |
Judging History
answer
#include<iostream>
#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define rep(i, a, b) for(int i = a ; i < b ; i ++)
#define sz(v) (int)v.size()
#define all(v) begin(v), end(v)
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 5e3 + 5;
const ll inf = 1e18;
ll solve(ll val, ll base) {
ll ans = 0;
vector<int> v;
while (val) {
if (val % base > 9) return 0;
v.push_back(val % base);
val /= base;
}
reverse(v.begin(), v.end());
if (v.size() >= 19) return inf;
for (auto i: v) {
ans = ans * 10 + i;
}
return ans;
}
ll check(vector<int> &d, ll base) {
ll sum = 0;
ll p = 1;
for (int i = 0; i < d.size(); i++) {
// check if sum + p * d[i] > inf
if ((sum + (ld) p * d[i]) > inf)return inf;
sum += p * d[i];
// check if p * base > inf
if (i + 1 < d.size()) {
if (base > inf / p) return inf;
p *= base;
}
}
return sum;
}
void doWork() {
ll y, l;
cin >> y >> l;
ll ans = 0;
for (ll i = l; i <= 999; i++) {
vector<int> temp;
int x = i;
while (x) {
temp.push_back(x % 10);
x /= 10;
}
ll low = 2, high = 1e18;
while (low < high) {
ll mid = low + high + 1 >> 1;
if (check(temp, mid) > y) high = mid - 1;
else low = mid;
}
if (check(temp, low) == y) ans = max(ans, low);
}
for (ll i = 1e6; i > ans; i--) {
if (solve(y, i) >= l) {
ans = i;
break;
}
}
cout << ans;
}
int main() {
IO
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
// cout << "Case #" << i << ": ";
doWork();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 3648kb
input:
32 20
output:
16
result:
ok single line: '16'
Test #2:
score: 0
Accepted
time: 4ms
memory: 3588kb
input:
2016 100
output:
42
result:
ok single line: '42'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
1000000000000000000 10
output:
1000000000000000000
result:
ok single line: '1000000000000000000'
Test #4:
score: 0
Accepted
time: 4ms
memory: 3880kb
input:
149239876439186 470
output:
11
result:
ok single line: '11'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3644kb
input:
4851495 95
output:
539054
result:
ok single line: '539054'
Test #6:
score: 0
Accepted
time: 3ms
memory: 3640kb
input:
19839853985 19839853985
output:
10
result:
ok single line: '10'
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 3876kb
input:
1000000000000000000 17
output:
1000000000000000000
result:
wrong answer 1st lines differ - expected: '999999999999999993', found: '1000000000000000000'