QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#666936 | #6621. Luggage Lock | yangrun | WA | 412ms | 3724kb | C++17 | 1.7kb | 2024-10-22 20:28:49 | 2024-10-22 20:28:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int read() {
int res = 0, flg = 1;
char c = getchar();
while(!isdigit(c)) {
if(c == '-') flg = 0;
c = getchar();
}
while(isdigit(c)) {
res = (res << 3) + (res << 1) + (c ^ 48);
c = getchar();
}
return flg ? res : -res;
}
const int N = 1e6 + 10;
priority_queue<pair<int, string>> q;
string add(string& str, int l, int r, int x) {
string s = str;
for(int i = l; i <= r; ++i) {
int c = s[i] - '0';
c = (c + x + 10) % 10;
s[i] = c + '0';
}
//cout << str << ' ' << l << ' ' << r << ' ' << x << ' ' << s << '\n';
return s;
}
void solve() {
while(q.size()) q.pop();
string ori, tar;
cin >> ori >> tar;
q.emplace(0, ori);
int step = 0, ans = 0;
string cur;
//map<string, int> ma;
//ma[ori] = 0;
while (!q.empty()) {
int size = q.size();
for (int i = 1; i <= size; i++) {
auto p = q.top(); q.pop();
string cur = p.second;
int d = p.first;
// cout << cur << '\n';
int l = 0;
while(l < ori.size() && cur[l] == tar[l]) ++l;
if(l >= (int)tar.size()) {
cout << -d << '\n'; return;
}
for(int r = l; r < tar.size(); ++r) {
int k = (cur[l] - tar[l] + 10) % 10;
if(k < 10 - k) {
//ma[add(cur, l, r, -k)] = ma[cur] + k;
q.emplace(d - k, add(cur, l, r, -k));
} else {
//ma[add(cur, l, r, 10 - k)] = ma[cur] + 10 - k;
q.emplace(d - 10 + k, add(cur, l, r, 10 - k));
}
}
}
step++;
}
}
signed main() {
int t;
t = read();
while(t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3724kb
input:
6 1234 2345 1234 0123 1234 2267 1234 3401 1234 1344 1234 2468
output:
1 1 4 5 1 4
result:
ok 6 numbers
Test #2:
score: -100
Wrong Answer
time: 412ms
memory: 3560kb
input:
100000 9138 9251 0887 4577 2745 6294 6883 1197 8654 2502 7867 7941 7505 2717 1497 7726 3337 8042 2767 8782 5311 4368 9711 6229 7105 8101 3553 6673 6544 7940 8848 8920 1458 6315 4605 2931 5505 7310 5963 4765 7625 0418 4049 0136 2078 6899 3339 1080 2276 6814 4249 4182 1861 0824 8975 8926 6447 6965 226...
output:
3 8 6 10 10 7 8 8 11 9 7 8 5 5 8 5 9 8 9 4 8 8 9 6 8 6 8 6 9 5 7 7 6 8 4 10 6 5 6 7 8 7 5 8 8 8 5 9 7 6 8 11 10 10 7 5 6 5 7 8 8 9 5 7 6 6 8 5 7 9 10 7 11 6 6 7 8 7 8 7 8 8 8 8 7 9 7 7 6 6 5 6 6 5 7 5 9 6 7 8 7 9 6 9 5 5 8 10 7 3 5 8 8 9 8 8 6 7 10 5 5 6 9 8 6 8 7 6 9 6 11 5 10 7 7 5 10 7 5 8 9 8 7 ...
result:
wrong answer 2nd numbers differ - expected: '6', found: '8'