QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#395797 | #6749. Target | potremz | WA | 0ms | 3812kb | C++17 | 1013b | 2024-04-21 19:28:02 | 2024-04-21 19:28:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-4;
double a, b;
map<double, int>cnt;
bool have_answer;
void dfs(double x, string ans) {
if (have_answer) {
return;
}
if (cnt.count(x)) {
if (cnt[x] < ans.size()) {
return;
} else {
cnt[x] = ans.size();
}
}
if (ans.size() > 50) {
return;
}
if (fabs(x - b) <= eps) {
have_answer = 1;
cout << ans << ' '<< x ;
return;
}
if (x > b) {
cnt[x / 2] = ans.size() + 1;
dfs(x / 2, ans + '1');
if (have_answer) {
return;
}
cnt[(x + 1) / 2] = ans.size() + 1;
dfs((x + 1) / 2, ans + '2');
if (have_answer) {
return;
}
} else {
cnt[(x + 1) / 2] = ans.size() + 1;
dfs((x + 1) / 2, ans + '2');
if (have_answer) {
return;
}
cnt[x / 2] = ans.size() + 1;
dfs(x / 2, ans + '1');
if (have_answer) {
return;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> a >> b;
string ans = "";
dfs(a, ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3812kb
input:
0.5 0.25
output:
1 0.25
result:
wrong answer wa