QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#622966 | #8795. Mysterious Sequence | rns_rds# | WA | 0ms | 4024kb | C++23 | 1.4kb | 2024-10-09 09:03:54 | 2024-10-09 09:03:55 |
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;
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: 4024kb
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: -100
Wrong Answer
time: 0ms
memory: 4024kb
input:
1 1 2 1 100
output:
1.00000000 100.00000000 100.00000000
result:
wrong output format Extra information in the output file