結果

問題 No.2156 ぞい文字列
ユーザー maclemacle
提出日時 2022-12-13 15:24:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 5,905 bytes
コンパイル時間 2,308 ms
コンパイル使用メモリ 202,268 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 01:10:22
合計ジャッジ時間 3,261 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;

// const long long mod = 1e9 + 7;
const long long mod = 998244353;
const double PI = acos(-1);
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define rep(i,a,b) for(int i=(a);i<(b);i++)


// begin() end()
#define all(x) (x).begin(),(x).end()

//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(12) << x << endl
#define printc(x) cout << setw(6) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

//最大公約数 
 ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}
 
// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}
const int INF = 1000000000;
const double DINF = 1LL<<60;
const long long LINF = 1LL<<60;
const int MAX = 510000;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// Nは問題によって変更すること
// vector<int>ind(N);
// REP(i, N) ind[i]= i;
//sort(all(ind), [&](int i, int j) {return x[i] < x[j];});


ll dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
// ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}, dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};

struct Mint {
    int val;
    Mint inv() const{
        int tmp,a=val,b=mod,x=1,y=0;
        while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
        return Mint(x);
    }
public:
    Mint():val(0){}
    Mint(ll x){if((val=x%mod)<0)val+=mod;}
    Mint pow(ll t){Mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
    Mint& operator+=(const Mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
    Mint& operator-=(const Mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
    Mint& operator*=(const Mint& x){val=(ll)val*x.val%mod; return *this;}
    Mint& operator/=(const Mint& x){return *this*=x.inv();}
    bool operator==(const Mint& x) const{return val==x.val;}
    bool operator!=(const Mint& x) const{return val!=x.val;}
    bool operator<(const Mint& x) const{return val<x.val;}
    bool operator<=(const Mint& x) const{return val<=x.val;}
    bool operator>(const Mint& x) const{return val>x.val;}
    bool operator>=(const Mint& x) const{return val>=x.val;}
    Mint operator+(const Mint& x) const{return Mint(*this)+=x;}
    Mint operator-(const Mint& x) const{return Mint(*this)-=x;}
    Mint operator*(const Mint& x) const{return Mint(*this)*=x;}
    Mint operator/(const Mint& x) const{return Mint(*this)/=x;}
};
struct factorial {
    vector<Mint> Fact, Finv;
public:
   //factorial fact(10000010);
   //fact.nCr(a, b)
  //「fact」の部分は自由に名前変更可能
    factorial(int maxx){
        Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
        Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
    }
    Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
    Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
    Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
    Mint nHr(int n, int r){return nCr(n + r - 1, r);}// 重複組み合わせ
};


template <typename T>
struct Matrix
{
    int n, m;
    std::vector<std::vector<T>> a;

    Matrix() {}

    Matrix(int n, int m) : n(n), m(m), a(n, std::vector<T>(m)) {}

    Matrix(int n) : n(n), m(n), a(n, std::vector<T>(n)) {}

    static Matrix<T> I(int n)
    {
        Matrix<T> res(n);
        for (int i = 0; i < n; i++)
        {
            res[i][i] = 1;
        }
        return res;
    }

    Matrix<T> &operator+=(const Matrix<T> &b)
    {
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                (*this)[i][j] += b[i][j];
            }
        }
        return *this;
    }

    Matrix<T> &operator-=(const Matrix<T> &b)
    {
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                (*this)[i][j] -= b[i][j];
            }
        }
        return *this;
    }

    Matrix<T> &operator*=(const Matrix<T> &b)
    {
        assert(m == b.n);
        std::vector<std::vector<T>> c(n, std::vector<T>(b.m));
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < b.m; j++)
            {
                for (int k = 0; k < m; k++)
                {
                    c[i][j] += (*this)[i][k] * b[k][j];
                }
            }
        }
        m = b.m;
        a.swap(c);
        return *this;
    }

    Matrix<T> &operator^=(long long k)
    {
        Matrix<T> b = Matrix<T>::I(n);
        while (k)
        {
            if (k & 1)
            {
                b *= *this;
            }
            *this *= *this;
            k >>= 1;
        }
        a.swap(b.a);
        return *this;
    }

    Matrix<T> operator+(const Matrix<T> &a)
    {
        return (Matrix<T>(*this) += a);
    }

    Matrix<T> operator-(const Matrix<T> &a)
    {
        return (Matrix<T>(*this) -= a);
    }

    Matrix<T> operator*(const Matrix<T> &a)
    {
        return (Matrix<T>(*this) *= a);
    }

    Matrix<T> operator^(const Matrix<T> &a)
    {
        return (Matrix<T>(*this) ^= a);
    }

    const std::vector<T> &operator[](int i) const
    {
        return a[i];
    }

    vector<T> &operator[](int i)
    {
        return a[i];
    }
};


int main() {
    ll N;
    cin >> N;
    Matrix<Mint>A(2, 2);
    A[0][0] = A[1][0] = A[0][1] = 1;
    A ^= N;
    A[0][0] -= 1;
    cout << A[0][0].val << endl;
    return 0;
}
0