QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#607928 | #8932. Bingo | UESTC_NLNS | Compile Error | / | / | C++17 | 2.3kb | 2024-10-03 17:09:06 | 2024-10-03 17:09:07 |
Judging History
answer
#include <iostream>
#include <sstream>
using namespace std;
using ll = long long;
const string o = "000000000000000000000000000000000000000000000000000000000000";
void add(string& n, ll k) {
for (int i = n.size() - 1; i >= 0, k; --i) {
n[i] = n[i] + k % 10;
k /= 10;
if (n[i] > '9') {
n[i] -= 10;
k++;
}
}
}
using i128 = __int128_t;
i128 s2i(const string& n) {
i128 ans = 0;
for (i128 i = n.size() - 1, c = 1; i >= 0; --i, c = 1ll * c * 10) {
ans = ans + c * (n[i] - '0');
}
return ans;
}
int cmp(const string& n, const int m) {
if (n.size() > 9) return 1;
ll n1 = s2i(n);
if (n1 > m) return 1;
if (n1 == m) return 0;
return -1;
}
int cmp(const string& n, const string& m) {
if (n.size() != m.size()) return (n.size() < m.size() ? -1 : 1);
for (int i = 0; i < n.size(); ++i) {
if (n[i] != m[i]) return (n[i] < m[i] ? -1 : 1);
}
return 0;
}
string i2s(const ll m) {
stringstream ss;
ss << m;
string ans;
ss >> ans;
return ans;
}
void print(const string& a) {
if (a[0] == '0')
cout << a.substr(1);
else
cout << a;
}
void solve() {
string n;
int m;
cin >> n >> m;
if (cmp(n, m) == -1) {
cout << m << '\n';
return;
}
n = "0" + n;
add(n, 1);
string sm = i2s(m);
int lm = sm.size();
if (n.find(i2s(m)) != string::npos) {
print(n);
cout << '\n';
return;
}
int r = 0;
for (int i = n.size() - 1, c = 1; i >= 0; --i, c = 1ll * c * 10 % m) {
r = (r + 1ll * c * (n[i] - '0')) % m;
}
ll off = r == 0 ? 0 : m - r;
string n2 = n.substr(min(n.size() - 2 * lm - 5, 0uLL));
i128 n2i = s2i(n2);
for (int i = 0; i <= n2.size() - lm; ++i) {
string s1 = n2.substr(0, i) + sm + o.substr(0, n2.size() - lm - i);
i128 m1 = stoi(s1);
if (m1 >= n2i) {
off = min(off, ll(m1 - n2i));
}
}
add(n, off);
print(n);
cout << '\n';
}
int main() {
cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
int t;
cin >> t;
while (t--) solve();
}
/*
6
7 3
12 3
9 10
249 51
1369 37
2 1
*/
详细
answer.code: In function ‘void solve()’: answer.code:87:29: error: no matching function for call to ‘min(std::__cxx11::basic_string<char>::size_type, long long unsigned int)’ 87 | string n2 = n.substr(min(n.size() - 2 * lm - 5, 0uLL)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/13/string:51, from /usr/include/c++/13/bits/locale_classes.h:40, from /usr/include/c++/13/bits/ios_base.h:41, from /usr/include/c++/13/ios:44, from /usr/include/c++/13/ostream:40, from /usr/include/c++/13/iostream:41, from answer.code:1: /usr/include/c++/13/bits/stl_algobase.h:233:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)’ 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/13/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed: answer.code:87:29: note: deduced conflicting types for parameter ‘const _Tp’ (‘long unsigned int’ and ‘long long unsigned int’) 87 | string n2 = n.substr(min(n.size() - 2 * lm - 5, 0uLL)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_algobase.h:281:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)’ 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/13/bits/stl_algobase.h:281:5: note: template argument deduction/substitution failed: answer.code:87:29: note: deduced conflicting types for parameter ‘const _Tp’ (‘long unsigned int’ and ‘long long unsigned int’) 87 | string n2 = n.substr(min(n.size() - 2 * lm - 5, 0uLL)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~