QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#553469 | #8932. Bingo | Grand_Elf | WA | 0ms | 3608kb | C++17 | 1.5kb | 2024-09-08 13:54:36 | 2024-09-08 13:54:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int T, m, pw[9];
string n;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
pw[0] = 1;
for (int i = 1; i <= 8; i++) {
pw[i] = pw[i - 1] * 10;
}
cin >> T;
while (T--) {
cin >> n >> m;
int valn = 0;
for (char c : n) {
valn = (10ll * valn + c - '0') % m;
}
int cnt = m - valn - 1;
int now = (int)n.size() - 1;
while (now >= 0 && n[now] == '9') {
n[now] = '0';
now--;
}
if (now == -1) {
n = '1' + n;
} else {
n[now]++;
}
reverse(n.begin(), n.end());
string strm = "";
int valm = m;
while (valm) {
strm += valm % 10 + '0';
valm /= 10;
}
if (n.find(strm)) {
reverse(n.begin(), n.end());
cout << n << '\n';
continue;
}
long long sum = 1;
for (int i = 0; i < n.size(); i++) {
long long v = 0;
for (int j = i; j < min(i + strm.size(), n.size()); j++) {
v += (n[j] - '0') * pw[j - i];
}
long long dis = m - v;
if (dis > 0) {
if (i >= 9) {
if (dis == 1 && sum < cnt) {
cnt = sum;
}
} else if ((dis - 1) * pw[i] + sum < cnt) {
cnt = (dis - 1) * pw[i] + sum;
}
}
if (n[i] != '9') {
if (i >= 9) {
break;
} else {
sum += ('9' - n[i]) * pw[i];
}
}
}
for (int i = 0; i < n.size(); i++) {
int c = n[i] - '0';
n[i] = (c + cnt) % 10 + '0';
cnt = (c + cnt) / 10;
}
while (cnt) {
n += cnt % 10 + '0';
cnt /= 10;
}
reverse(n.begin(), n.end());
cout << n << '\n';
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3608kb
input:
6 7 3 12 3 9 10 249 51 1369 37 2 1
output:
8 15 10 250 1370 3
result:
wrong answer 1st lines differ - expected: '9', found: '8'