QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#650549 | #8932. Bingo | Yoshinow2001# | WA | 122ms | 3552kb | C++20 | 2.5kb | 2024-10-18 15:34:33 | 2024-10-18 15:34:38 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define endl '\n'
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
string sn, sm;
int m;
string sa, sb, sc;
string add(string a, string b) {
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
string c;
c.resize(max(a.size(), b.size()) + 1);
a.resize(c.size(), '0');
b.resize(c.size(), '0');
int v = 0;
for (int i = 0; i < c.size(); i++) {
v += a[i] + b[i] - '0' - '0';
c[i] = v % 10 + '0';
v /= 10;
}
// while (c.size() > 1 && c.back() == '0') c.pop_back();
reverse(c.begin(), c.end());
return c;
}
int smod(string a, int m) {
reverse(a.begin(), a.end());
int res = 0;
for (char c : a) res = (res + c - '0') % m;
return res;
}
string itos(int x) {
string res;
while (x) {
res += char('0' + x % 10);
x /= 10;
}
reverse(res.begin(), res.end());
if (!res.size()) res = "0";
return res;
}
void f(string &sa) {
reverse(sa.begin(), sa.end());
while (sa.size() > sn.size()) sa.pop_back();
reverse(sa.begin(), sa.end());
}
void solve() {
cin >> sn >> sm;
// cout << sn << " = ";
sn = add(sn, "1");
// cout << sn << " = ";
reverse(sn.begin(), sn.end());
for (int i = 0; i < 10; i++) sn += '0';
reverse(sn.begin(), sn.end());
m = stoi(sm);
sa = add(sn, itos((m - smod(sn, m)) % m));
sc = sb = sa;
bool fb = 0, fc = 0;
for (int i = sn.size() - sm.size(); i >= 0; i--) {
string x = sn.substr(i, sm.size());
if (stoi(x) <= m) {
if (!fb) {
sb = sn.substr(0, i) + sm;
for (int j = sn.size() - sm.size(); j > i; j--) sb += '0';
fb = 1;
}
}
else {
if (!fc) {
sc = add(sn.substr(0, i), "1") + sm;
for (int j = sn.size() - sm.size(); j > i; j--) sc += '0';
fc = 1;
}
}
}
f(sa);
f(sb);
f(sc);
string ans = min({sa, sb, sc});
reverse(ans.begin(), ans.end());
while (ans.size() > 1 && ans.back() == '0') ans.pop_back();
reverse(ans.begin(), ans.end());
cout << ans << endl;
}
int main(){
fastio;
int T;
cin >> T;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
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: 122ms
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:
3196282259 7614814260 2814581097 1075124434 7822266274 1767317777 7189709862 9061337562 6552679238 9946082151 5497675065 7787300365 4310767268 4811342014 3265496131 8294404062 2845521790 1114254691 6442013000 3744046898 3289624375 6477935379 1292587539 5504674689 2898829169 7882736018 2846033387 923...
result:
wrong answer 1st lines differ - expected: '3196282244', found: '3196282259'