結果

問題 No.492 IOI数列
ユーザー MisterMister
提出日時 2020-09-13 18:40:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 5,743 bytes
コンパイル時間 797 ms
コンパイル使用メモリ 71,808 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-13 04:23:05
合計ジャッジ時間 1,797 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <array>
#include <string>

template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }
    bool operator<(const ModInt& b) const { return val < b.val; }
    bool operator<=(const ModInt& b) const { return val <= b.val; }
    bool operator>(const ModInt& b) const { return val > b.val; }
    bool operator>=(const ModInt& b) const { return val >= b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept {
        lint v;
        is >> v;
        x = v;
        return is;
    }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

template <class T, int D>
struct Vector {
    using V = std::array<T, D>;

    V vec;

    // constructor
    Vector(T val = 0) { vec.fill(val); }

    // getter
    T& operator[](int i) { return vec[i]; }
    T operator[](int i) const { return vec[i]; }
    typename V::iterator begin() { return vec.begin(); }
    typename V::iterator end() { return vec.end(); }

    // arithmetic
    Vector operator+(const Vector& v) const { return Vector(*this) += v; }
    Vector operator-(const Vector& v) const { return Vector(*this) -= v; }
    T operator*(const Vector& v) const {
        T ret(0);
        for (int i = 0; i < D; ++i) ret += vec[i] * v[i];
        return ret;
    }

    // compound assignment
    Vector& operator+=(const Vector& v) {
        for (int i = 0; i < D; ++i) vec[i] += v[i];
        return *this;
    }
    Vector& operator-=(const Vector& v) {
        for (int i = 0; i < D; ++i) vec[i] -= v[i];
        return *this;
    }
};

template <class T, int D>
struct Matrix {
    using M = std::array<std::array<T, D>, D>;

    M mat;

    // constructor
    Matrix(T val = 0) {
        for (auto& v : mat) v.fill(val);
    }

    static Matrix id() {
        Matrix m;
        for (int i = 0; i < D; ++i) m[i][i] = 1;
        return m;
    }

    // getter
    std::array<T, D>& operator[](int i) { return mat[i]; }
    std::array<T, D> operator[](int i) const { return mat[i]; }
    typename M::iterator begin() { return mat.begin(); }
    typename M::iterator end() { return mat.end(); }

    // arithmetic
    Matrix operator+(const Matrix& m) const { return Matrix(*this) += m; }
    Matrix operator-(const Matrix& m) const { return Matrix(*this) -= m; }
    Matrix operator*(const Matrix& m) const { return Matrix(*this) *= m; }

    template <class U>
    Matrix pow(U k) {
        Matrix ret = id();
        Matrix a = *this;

        while (k > 0) {
            if (k & 1) ret *= a;
            a *= a;
            k >>= 1;
        }
        return ret;
    }

    // compound assignment
    Matrix& operator+=(const Matrix& m) {
        for (int i = 0; i < D; ++i) {
            for (int j = 0; j < D; ++j) {
                mat[i][j] += m[i][j];
            }
        }
        return *this;
    }
    Matrix& operator-=(const Matrix& m) {
        for (int i = 0; i < D; ++i) {
            for (int j = 0; j < D; ++j) {
                mat[i][j] -= m[i][j];
            }
        }
        return *this;
    }
    Matrix& operator*=(const Matrix& m) {
        M nmat;
        for (auto& v : nmat) v.fill(0);

        for (int i = 0; i < D; ++i) {
            for (int j = 0; j < D; ++j) {
                for (int k = 0; k < D; ++k) {
                    nmat[i][j] += mat[i][k] * m[k][j];
                }
            }
        }
        mat = nmat;
        return *this;
    }

    // arithmetic with vector
    using Vec = Vector<T, D>;
    Vec operator*(const Vec& v) {
        Vec ret;
        for (int i = 0; i < D; ++i) {
            for (int j = 0; j < D; ++j) {
                ret[i] += mat[i][j] * v[j];
            }
        }
        return ret;
    }
};

constexpr int MOD = 1000000007;
using mint = ModInt<MOD>;
using Mat = Matrix<mint, 2>;

using lint = long long;

void solve() {
    lint n;
    std::cin >> n;

    Mat m;
    m[0][0] = 100, m[0][1] = 1, m[1][1] = 1;
    m = m.pow(n);
    std::cout << m[0][1] << "\n";

    n %= 11;
    if (n == 0) {
        std::cout << "0\n";
    } else {
        std::cout << "1";
        --n;
        while (n--) std::cout << "01";
        std::cout << "\n";
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0