QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#622968#8795. Mysterious Sequencerns_rds#WA 0ms4036kbC++231.5kb2024-10-09 09:06:492024-10-09 09:06:50

Judging History

你现在查看的是最新测评结果

  • [2024-10-09 09:06:50]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4036kb
  • [2024-10-09 09:06:49]
  • 提交

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';
}

Details

Tip: Click on the bar to expand more detailed information

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'