QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#764841#9479. And DNAforgotmyhandleCompile Error//C++141.5kb2024-11-20 10:53:542024-11-20 10:53:59

Judging History

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

  • [2024-11-20 10:53:59]
  • 评测
  • [2024-11-20 10:53:54]
  • 提交

answer

#include <iostream>
#include <string.h>
#include <cassert>
#include <map>
#define int long long
using namespace std;
const int P = 998244353;
struct Matrix {
    int a[4][4];
    Matrix() { memset(a, 0, sizeof a); }
    void ini(int x = 1) { for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) a[i][j] = (i == j) * x; }
    int* operator[](int x) { return a[x]; }
} I, T;
Matrix operator*(Matrix a, Matrix b) {
    Matrix c;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) 
                c[i][j] += a[i][k] * b[k][j] % P;
            c[i][j] %= P;
        }
    }
    return c;
}
Matrix qpow(Matrix x, int y) {
    Matrix ret;
    ret.ini();
    while (y) {
        if (y & 1) 
            ret = ret * x;
        y >>= 1;
        x = x * x;
    }
    return ret;
}
int n, m;
int ans0;
map<int, int> mp;
int dfss(int x) {
    if (mp.count(x)) 
        return mp[x];
    if (x & 1) 
        return mp[x] = dfss(x >> 1) * ans0 % P;
    else 
        return mp[x] = (dfss(x >> 1) + dfss((x >> 1) - 1)) % P;
}
int main() {
    cin >> n >> m;
    T[1][2] = T[1][3] = T[2][1] = T[3][2] = 1;
    I.ini(0); I[0][1] = 1; I = I * qpow(T, n - 2); ans0 += I[0][1] + I[0][3];
    I.ini(0); I[0][2] = 1; I = I * qpow(T, n - 2); ans0 += I[0][1] + I[0][2];
    I.ini(0); I[0][3] = 1; I = I * qpow(T, n - 2); ans0 += I[0][0] + I[0][2];
    ans0 %= P;
    mp[0] = 1;
    cout << dfss(m) << "\n";
    return 0;
}

Details

cc1plus: error: ‘::main’ must return ‘int’