谨以此题纪念边界测试数据浪费了我多少时间:https://pintia.cn/problem-sets/994805342720868352/problems/994805507225665536

 #include <iostream>
#include <string>
#include <vector>
#include <algorithm> void read(std::vector<int>& _data)
{
std::string s;
std::cin >> s;
_data.reserve(s.size());
for (auto c : s)
if (c < 'a')
_data.push_back(c - '');
else
_data.push_back(c - 'a' + );
} auto convert(const std::vector<int>& _data, uint64_t _radix)
{
uint64_t res = ;
for (auto i : _data)
res = res * _radix + i;
return res;
} uint64_t solve(const std::vector<int>& _data, uint64_t _value)
{
if (_data.size() == )
return _data[] == _value ? _value + : -;
uint64_t radix;
for (radix = ; convert(_data, radix) <= _value; radix *= )
;
if (radix == )
return -;
auto begin = std::max<uint64_t>(*std::max_element(_data.begin(), _data.end()) + , radix / );
auto end = radix;
while (begin < end)
{
auto mid = (begin + end) / ;
auto res = convert(_data, mid);
if (res > _value)
end = mid;
else if (res < _value)
begin = mid + ;
else
return mid;
}
return -;
} int main(int argc, char const *argv[])
{
std::vector<int> data;
int64_t value;
{
std::vector<int> source;
read(source);
read(data);
int which;
std::cin >> which;
if (which == )
source.swap(data);
int radix;
std::cin >> radix;
value = convert(source, radix);
} auto res = solve(data, value);
if (res == -)
std::cout << "Impossible";
else
std::cout << res; return ;
}
04-18 01:15