QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#563969 | #8932. Bingo | ucup-team3691# | WA | 29ms | 3884kb | C++14 | 3.1kb | 2024-09-14 18:13:37 | 2024-09-14 18:13:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
using ll = long long;
using ull = unsigned long long;
string to_string(const string &s) {
return '"' + s + '"';
}
string to_string(bool b) {
return b ? "true" : "false";
}
template <typename A, typename B>
string to_string(const pair<A, B> &p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename T>
string to_string(const T &v) {
string s = "{";
bool first = true;
for (const auto &it : v) {
if (!first)
s += ", ";
else
first = false;
s += to_string(it);
}
return s += "}";
}
void debug_out() {
cerr << endl;
}
template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
cerr << to_string(first) << " ";
debug_out(rest...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
auto startTime = high_resolution_clock::now();
int get_time() {
auto stopTime = chrono::high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stopTime - startTime);
return duration.count(); // in ms
}
void solve() {
string s;
cin >> s;
ull r = 1;
for (int i = s.size() - 1; i >= 0; --i) {
s[i] += r;
if (s[i] > '9') {
s[i] = '0';
r = 1;
} else {
r = 0;
}
}
if (r == 1)
s = '1' + s;
ull m;
cin >> m;
r = 0;
for (auto it : s) {
r = (r * 10 + it - '0') % m;
}
ull ans = (r == 0) ? (0) : (m - r);
string ms = to_string(m);
ull add = 1; // cat mai am nevoie sa fac un ovf cu 1
ull p = 1, k = 0, pf = 1;
while (k + 1 < ms.size()) {
++k;
p = p * 10;
}
for (int i = s.size() - ms.size(); i >= 0; --i) {
string n = s.substr(i, ms.size());
bool found = false;
for (ull i = 0, p2 = p; i < ms.size(); ++i, p2 /= 10) {
if (n[i] != ms[i]) {
found = true;
if (n[i] < ms[i]) {
ull x = 0, y = 0;
for (int j = i; j < ms.size(); ++j) {
x = x * 10 + n[j] - '0';
y = y * 10 + ms[j] - '0';
}
auto dif = y - x - 1;
auto cost = dif * p + add;
ans = min(ans, cost);
} else {
ull x = 0;
for (int j = 0; j < ms.size(); ++j) {
x = x * 10 + n[j] - '0';
}
auto cost = pf * ((p - x) + m - 1) + add;
ans = min(ans, cost);
}
break;
}
}
if (!found) {
ans = 0;
break;
}
add = add + ('9' - s[i]) * pf;
add = min(add, m);
pf = pf * 10;
pf = min(pf, m);
}
r = ans;
for (int i = s.size() - 1; i >= 0; --i) {
r = r + s[i] - '0';
s[i] = '0' + r % 10;
r = r / 10;
}
while (r > 0) {
s.insert(0, 1, (char)(r % 10 + '0'));
r /= 10;
}
cout << s << "\n";
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int t = 1;
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: 3884kb
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: 29ms
memory: 3660kb
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 7614814243 2814581100 1075124424 7822266300 1767317769 7189709848 9061337577 6552679264 9946082160 5497675063 7787300365 4310767313 4811341995 3265496131 8294404082 2845521810 1114254674 6442013673 3744046867 3289624425 6477935360 1292587554 5504674742 2898829200 7882736025 2846033436 923...
result:
wrong answer 2nd lines differ - expected: '7614814251', found: '7614814243'