QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#694936 | #8932. Bingo | Joyemang# | WA | 120ms | 3784kb | C++23 | 3.5kb | 2024-10-31 18:58:31 | 2024-10-31 18:58:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int m;
string N, M;
void print(string str) { for (int i = 0; i < str.size(); ++i) cout << (char)(str[i] + '0'); cout << endl; }
string add(string N, int x) {
reverse(N.begin(), N.end());
vector<int> res;
for (int i = 0; i < N.size(); ++i) res.push_back(N[i]);
res[0] += x;
for (int i = 0; i < res.size(); ++i) {
if (res[i] >= 10) {
if (i + 1 == res.size()) res.push_back(res[i] / 10);
else res[i + 1] += res[i] / 10;
res[i] %= 10;
}
}
reverse(res.begin(), res.end());
N = "";
for (int i = 0; i < res.size(); ++i) N.push_back(res[i]);
return N;
}
string solve1(){
long long r = 0;
for (int i = 0; i < N.size(); ++i) {
r = (r * 10 + N[i]) % m;
}
return add(N, m - r);
}
bool check1(int l){
if (l < 0) return false;
for (int i = 0; i < M.size(); ++i) if (M[i] != N[l + i]) return false;
return true;
}
bool check2(int l, int d) {
if (l < 0) return false;
for (int i = 0; i + 1 < M.size(); ++i) if (M[i] != N[l + i]) return false;
if (d != M.back()) return false;
return true;
}
string solve2(){
M = "";
for (int x = m; x; x/= 10) M += (x % 10);
reverse(M.begin(), M.end());
if (N.size() < M.size()) {
return M;
}
string res = N;
vector<bool> f(N.size(), 0);
for (int i = 0; i < N.size(); ++i) {
f[i] = (i ? f[i - 1] : 0) | check1(i - (int)M.size() + 1);
}
for (int i = (int)N.size() - 1; i >= 0; --i) {
for (int d = N[i] + 1; d < 10; ++d) {
if ((i && f[i - 1]) || check2(i - (int)M.size() + 1, d)) {
res[i] = d;
for (int k = i + 1; k < res.size(); ++k) res[k] = 0;
return res;
}
if (i + M.size() < N.size()) {
res[i] = d;
for (int k = i + 1; k < N.size() - M.size(); ++k) res[k] = 0;
for (int k = N.size() - M.size(); k < N.size(); ++k) res[k] = M[k - (N.size() - M.size())];
return res;
}
}
}
return "";
}
string chkmin(string ans1, string ans2) {
if (ans1 == "") return ans2;
if (ans2 == "") return ans1;
if (ans1.size() < ans2.size()) return ans1;
if (ans2.size() < ans1.size()) return ans2;
for (int i = 0; i < ans1.size(); ++i) {
if (ans1[i] < ans2[i]) return ans1;
if (ans2[i] < ans1[i]) return ans2;
}
return ans1;
}
string solve3(){
string ret = "";
for (int i = (int)N.size() - (int)M.size(); i >= 0 && i >= (int)N.size() - (int)M.size() * 2; --i) {
int p = i;
string res = N;
bool ok = true, flg = false;
for (int j = 0; j < M.size(); ++j, ++p) {
if (!flg && M[j] < N[p]) {
ok = false;
break;
}
res[p] = M[j];
if (res[p] > N[p]) flg = true;
}
// cout << i << " "; print(res); cout << " ok = " << ok << " " << flg << endl;
if (ok && flg) {
for (; p < res.size(); ++p) res[p] = 0;
ret = chkmin(ret, res);
}
}
return ret;
}
inline void solve(){
cin >> N >> m;
for (int i = 0; i < N.size(); ++i) N[i] -= '0';
string ans1 = solve1();
string ans2 = solve2();
string ans3 = solve3();
print(chkmin(ans3, chkmin(ans1, ans2)));
}
int main(){
int T;
for (cin >> T; T--; solve());
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3784kb
input:
6 7 3 12 3 9 10 249 51 1369 37 2 1
output:
9 13 10 251 1370 3
result:
ok 6 lines
Test #2:
score: -100
Wrong Answer
time: 120ms
memory: 3552kb
input:
100000 3196282243 28 7614814237 33 2814581084 97 1075124401 58 7822266214 100 1767317768 31 7189709841 75 9061337538 69 6552679231 38 9946082148 18 5497675062 54 7787300351 65 4310767261 68 4811341953 100 3265496130 31 8294404054 62 2845521744 90 1114254672 26 6442013672 13 3744046866 40 3289624367 ...
output:
3196282244 7614814251 2814581097 1075124424 7822266300 1767317769 7189709850 9061337569 6552679238 9946082160 5497675063 7787300365 4310767268 4811342000 3265496131 8294404062 2845521790 1114254674 6442013673 3744046867 3289624375 6477935360 1292587551 5504674689 2898829180 7882736025 2846033387 923...
result:
wrong answer 79813th lines differ - expected: '3839990000', found: '3839990040'