QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#622968 | #8795. Mysterious Sequence | rns_rds# | WA | 0ms | 4036kb | C++23 | 1.5kb | 2024-10-09 09:06:49 | 2024-10-09 09:06:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using Z = long double; // not necessary, maybe MINT
struct Mat {
vector<vector<Z>> a;
static int D;
const static void setD(int _D) {
D = _D;
}
Mat(int k = 0) {
a.assign(D, vector<Z>(D, 0));
for (int i = 0; i < D; i++)
a[i][i] = k;
}
Mat operator*(const Mat &x) {
Mat res;
for (int i = 0; i < D; i++)
for (int j = 0; j < D; j++)
for (int k = 0; k < D; k++)
res.a[i][j] += a[i][k] * x.a[k][j];
return res;
}
Mat pow(long long k) {
Mat res = Mat(1.0), b = *this;
for (; k; k >>= 1) {
if (k & 1) res = res * b;
b = b * b;
}
return res;
}
};
int Mat::D = 2;
// See RNS_CONTEST_2023::D
int main() {
long double A, B;
int n;
long double x1, xn;
cin >> A >> B >> n >> x1 >> xn;
if (n == 2) {
cout << x1 << '\n'
<< xn << '\n';
return 0;
}
Mat matrix;
matrix.a[0][0] = A, matrix.a[0][1] = B;
matrix.a[1][0] = 1, matrix.a[1][1] = 0;
Mat tmp = matrix.pow(n - 2);
long double x2 = 1.0 * (xn - tmp.a[0][1] * x1) / tmp.a[0][0];
cout << setprecision(8) << fixed << x1 << '\n'
<< x2 << '\n';
for (int i = 3; i < n; i++) {
long double ans = x1 + x2;
cout << ans << '\n';
x1 = x2, x2 = ans;
}
cout << xn << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
input:
1.0 1.0 10 1 10
output:
1.00000000 -0.32352941 0.67647059 0.35294118 1.02941176 1.38235294 2.41176471 3.79411765 6.20588235 10.00000000
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
1 1 2 1 100
output:
1 100
result:
ok 2 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
1 1 5 50 100
output:
50.00000000 0.00000000 50.00000000 50.00000000 100.00000000
result:
ok 5 numbers
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 4036kb
input:
0.25 0.25 10 1 1
output:
1.00000000 55.87553648 56.87553648 112.75107296 169.62660944 282.37768240 452.00429185 734.38197425 1186.38626609 1.00000000
result:
wrong answer 3rd numbers differ - expected: '14.2188841', found: '56.8755365', error = '3.0000000'