QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#533216 | #8795. Mysterious Sequence | deepthought | WA | 0ms | 3908kb | C++23 | 1.1kb | 2024-08-25 18:42:05 | 2024-08-25 18:42:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
double a, b, x1, xn;
int n;
cin >> a >> b >> n >> x1 >> xn;
assert(n > 1);
if(n == 2) {
cout << x1 << endl << xn << endl;
return 0;
}
double lo = -1e9;
double hi = 1e9;
double prec = 1e-9;
while(hi - lo > prec) {
double mid = lo + (hi - lo) / 2.0;
double xs[n + 1];
xs[1] = x1;
xs[2] = mid;
for(int i = 3; i <= n; i++) {
xs[i] = a * xs[i - 1] + b * xs[i - 2];
}
if(abs(xs[n] - xn) / (max(1.0, xn)) < prec) break;
else if(xs[n] > xn) hi = mid;
else if(xs[n] < xn) lo = mid;
}
double ans[n + 1];
ans[1] = x1;
ans[n] = xn;
ans[2] = lo;
cout << x1 << endl << fixed << setprecision(9) << lo << endl;
for(int i = 3; i < n; i++) {
ans[i] = a * ans[i - 1] + b * ans[i - 2];
cout << fixed << setprecision(9) << ans[i] << endl;
}
cout << xn << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3900kb
input:
1.0 1.0 10 1 10
output:
1 -0.323529425 0.676470575 0.352941149 1.029411724 1.382352873 2.411764596 3.794117469 6.205882065 10.000000000
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3908kb
input:
1 1 2 1 100
output:
1 100
result:
ok 2 numbers
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3812kb
input:
1 1 5 50 100
output:
50 -1000000000.000000000 -999999950.000000000 -1999999950.000000000 100.000000000
result:
wrong answer 2nd numbers differ - expected: '0.0000000', found: '-1000000000.0000000', error = '1000000000.0000000'