結果

問題 No.741 AscNumber(Easy)
ユーザー potoooooooopotoooooooo
提出日時 2018-12-12 23:25:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 6,356 bytes
コンパイル時間 1,823 ms
コンパイル使用メモリ 176,240 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 08:36:33
合計ジャッジ時間 4,260 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 3 ms
4,348 KB
testcase_47 AC 2 ms
4,348 KB
testcase_48 AC 2 ms
4,348 KB
testcase_49 AC 2 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 2 ms
4,348 KB
testcase_52 AC 2 ms
4,348 KB
testcase_53 AC 3 ms
4,348 KB
testcase_54 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define mod 1000000007

template<class Numeric> class matrix {
  protected:
    vector< vector<Numeric> > _mat;
    int _col, _row;
    const bool usingModulo = true;
    const Numeric modulo = 1000000007; // using modulo
    void resize(int col, int row) {
      _col = col; _row = row;
      _mat.assign(col, vector<Numeric>(row, 0));
    }
  public:
    matrix(int col, int row) : _col(col), _row(row) {
      _mat.assign(col, vector<Numeric>(row, 0));
    }
    matrix(int col, int row, int num) : _col(col), _row(row) {
      _mat.assign(col, vector<Numeric>(row, num));
    }
    int col() const { return _col; }
    int row() const { return _row; }
    vector<Numeric> &operator[](int i) { return _mat[i]; }
    Numeric &operator() (int i, int j) { return _mat[i][j]; }
    matrix<Numeric> operator+(matrix<Numeric> &x) {
      if (this->col() != x.col() || this->row() != x.row()) {
        cout << "matrices are different sizes .. ";
        this->size(false); cout << "+"; x.size(true);
        exit(0);
      }
      matrix<Numeric> ret(this->col(), this->row());
      for (int i = 0; i < this->col(); ++i) {
        for (int j = 0; j < this->row(); ++j) {
          ret[i][j] = _mat[i][j] + x[i][j];
          if (usingModulo) ret[i][j] %= modulo;
        }
      }
      return ret;
    }
    matrix<Numeric> &operator+=(matrix<Numeric> &x) {
      if (this->col() != x.col() || this->row() != x.row()) {
        cout << "matrices are different sizes .. ";
        this->size(false); cout << "+"; x.size(true);
        exit(0);
      }
      for (int i = 0; i < this->col(); ++i) {
        for (int j = 0; j < this->row(); ++j) {
          _mat[i][j] += x[i][j];
          if (usingModulo) _mat[i][j] %= modulo;
        }
      }
      return *this;
    }
    matrix<Numeric> operator-(matrix<Numeric> &x) {
      if (this->col() != x.col() || this->row() != x.row()) {
        cout << "matrices are different sizes .. ";
        this->size(false); cout << "-"; x.size(true);
        exit(0);
      }
      matrix<Numeric> ret(this->col(), this->row());
      for (int i = 0; i < this->col(); ++i) {
        for (int j = 0; j < this->row(); ++j) {
          ret[i][j] = _mat[i][j] - x[i][j];
          if (usingModulo) ret[i][j] %= modulo;
        }
      }
      return ret;
    }
    matrix<Numeric> &operator-=(matrix<Numeric> &x) {
      if (this->col() != x.col() || this->row() != x.row()) {
        cout << "matrices are different sizes .. ";
        this->size(false); cout << "-"; x.size(true);
        exit(0);
      }
      for (int i = 0; i < this->col(); ++i) {
        for (int j = 0; j < this->row(); ++j) {
          _mat[i][j] -= x[i][j];
          if (usingModulo) _mat[i][j] %= modulo;
        }
      }
      return *this;
    }
    matrix<Numeric> operator*(matrix<Numeric> &x) {
      if (this->row() != x.col()) {
        cout << "cannot multiply matrices .. ";
        this->size(false); cout << "*"; x.size(true);
        exit(0);
      }
      matrix<Numeric> ret(this->col(), x.row());
      for (int i = 0; i < this->col(); ++i) {
        for (int j = 0; j < x.row(); ++j) {
          for (int k = 0; k < this->row(); ++k) {
            ret[i][j] += _mat[i][k] * x[k][j];
            if (usingModulo) ret[i][j] %= modulo;
          }
        }
      }
      return ret;
    }
    matrix<Numeric> &operator*(Numeric k) {
      matrix<Numeric> ret(this->col(), this->row());
      for (int i = 0; i < this->col(); ++i) {
        for (int j = 0; j < this->row(); ++j) {
          ret(i, j) = _mat[i][j] * k;
          if (usingModulo) ret(i, j) %= modulo;
        }
      }
      return ret;
    }
    matrix<Numeric> &operator*=(matrix<Numeric> &x) {
      if (this->row() != x.col()) {
        cout << "cannot multiply matrices .. ";
        this->size(false); cout << "*"; x.size(true);
        exit(0);
      }
      matrix<Numeric> ret(this->col(), x.row());
      for (int i = 0; i < this->col(); ++i) {
        for (int j = 0; j < x.row(); ++j) {
          for (int k = 0; k < this->row(); ++k) {
            ret[i][j] += _mat[i][k] * x[k][j];
            if (usingModulo) ret[i][j] %= modulo;
          }
        }
      }
      this->resize(this->col(), x.row());
      for (int i = 0; i < this->col(); ++i) {
        for (int j = 0; j < x.row(); ++j) {
          _mat[i][j] = ret[i][j];
        }
      }
      return *this;
    }
    matrix<Numeric> &operator*=(Numeric k) {
      matrix<Numeric> ret(this->col(), this->row());
      for (int i = 0; i < this->col(); ++i) {
        for (int j = 0; j < this->row(); ++j) {
          _mat[i][j] *= k;
          if (usingModulo) _mat %= modulo;
        }
      }
      return *this;
    }
    void print() {
      cout << "-- print "; this->size(false); cout << " --" << endl;
      for (int i = 0; i < _col; ++i) {
        for (int j = 0; j < _row; ++j) {
          if (j != 0) cout << "\t";
          cout << _mat[i][j];
        }
        cout << endl;
      }
      cout << "------------------" << endl;
    }
    void print(string str) {
      cout << "-- print \"" << str << "\" "; this->size(false); cout << " --" << endl;
      for (int i = 0; i < _col; ++i) {
        for (int j = 0; j < _row; ++j) {
          if (j != 0) cout << "\t";
          cout << _mat[i][j];
        }
        cout << endl;
      }
      cout << "------------------" << endl;
    }
    void size (bool endline = true) const {
      cout << "(" << this->col() << ", " << this->row() << ")";
      if (endline) cout << endl;
    }
};

template<class Numeric> class squareMatrix : public matrix<Numeric> {
  private:
  public:
    squareMatrix(int col): matrix<Numeric>(col, col){
    }
    squareMatrix(int col, int num): matrix<Numeric>(col, col, num) {
    }
    squareMatrix(int col, bool identity): matrix<Numeric>(col, col) {
      if (identity) {
        for (int i = 0; i < col; ++i) {
          this->_mat[i][i] = 1;
        }
      }
    }
};


int main(){
	int n; cin >> n;
	matrix<long long> ans(1, 10, 0), mat(10, 10, 0);
	for (int i = 0; i < 10; ++i) {
		for (int j = i; j < 10; ++j) {
			mat[i][j] = 1;
		}
	}
	ans[0][0] = 1;
	while (n > 0) {
		if (n % 2 == 1) {
			ans *= mat;
		}
		n /= 2; mat *= mat;
	}
	long long sum = 0;
	for (int i = 0; i < 10; i++) {
		sum += ans[0][i]; sum %= mod;
	}
	cout << sum << endl;
}
0