結果

問題 No.492 IOI数列
ユーザー naimonon77naimonon77
提出日時 2017-03-12 22:24:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 4,927 bytes
コンパイル時間 2,146 ms
コンパイル使用メモリ 187,968 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-30 00:35:49
合計ジャッジ時間 2,953 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 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
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#include <random>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=b;--i)
#define range(i,a,b,c) for(int i=a;\
                    c>0?i<b:\
                    i>b;\
                    i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep) {
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

template<class InputIterator>
int sum(InputIterator begin, InputIterator end) {
	return accumulate(begin, end, 0ll);
}

string reverse_res(string s) {
	reverse(all(s));
	return s;
}

template<typename T>
class Matrix {
private:
	vector<vector<T>> data;
	size_t row_n;
	size_t column_n;
public:
	Matrix(int a, int b) {
		data.resize(a);
		for (int i = 0; i < a; i++) data[i].resize(b);
		row_n = a;
		column_n = b;
	}

	Matrix(vector<vector<T>> a) {
		row_n = a.size();
		column_n = a[0].size();
		assert(row_n != 0);
		data.resize(a.size());
		for (int i = 0; i < a.size(); i++) {
			assert(a[i].size() == column_n);
			data[i] = a[i];
		}
	}

	const size_t row_size() const {
		return row_n;
	}

	const size_t column_size() const {
		return column_n;
	}

	vector<T>& operator [] (size_t a) {
		return data[a];
	}

	const vector<T> operator [] (size_t a) const {
		return data[a];
	}

	template<typename U>
	Matrix<T>& operator %= (const U& b) {
		Matrix mat = (*this) % b;
		this->data = mat.data;
		return *this;
	}
};

template<typename T>
bool operator == (const Matrix<T>& a, const Matrix<T>& b) {
	if (a.row_size() != b.row_size()) return false;
	if (a.column_size() != b.column_size()) return false;
	rep(i, a.row_size()) {
		rep(j, a.column_size()) {
			if (a[i][j] != b[i][j]) return false;
		}
	}
	return true;
}

template<typename T>
bool operator != (const Matrix<T>& a, const Matrix<T>& b) {
	return not (a == b);
}

template<typename T>
Matrix<T> operator * (const Matrix<T>& a, const Matrix<T>& b) {
	if (a.column_size() != b.row_size()) {
		cerr << "MAT operator *(MAT &,MAT &):Invailed matrix size." << endl;
		abort();
	}
	int n = a.column_size();
	Matrix<T> c(a.row_size(), b.column_size());
	rep(i, c.row_size()) {
		rep(j, c.column_size()) {
			c[i][j] = 0;
			rep(k, n) {
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	return c;
}

template<typename T>
vector<T> operator * (const Matrix<T>& a, const vector<T>& x) {
	if (a.column_size() != x.size()) {
		cerr << "MAT operator *(MAT &,MAT &):Invailed matrix size." << endl;
		abort();
	}
	int n = a.column_size();
	vector<T> y(a.row_size());
	rep(i, y.size()) {
		y[i] = 0;
		// cout << "!";
		rep(j, n) {
			y[i] += a[i][j] * x[j];
		}
	}
	return y;
}

template<typename T, typename U>
Matrix<T> operator % (const Matrix<T>& a, const U& b) {
	Matrix<T> res = a;
	rep(i, a.row_size()) rep(j, a.column_size()) {
		 T v = res[i][j] % b;
		 res[i][j] = v;
	}
	return res;
}

/* pow(x,n)はx^nを返すよ! */
template<typename T, class U>
Matrix<T> mod_pow(Matrix<T> x, U n) {
	if (n == 0) {
		assert(x.column_size() == x.row_size());
		int n = x.column_size();
		Matrix<T> res(n, n);
		rep(i, n) {
			res[i][i] = 1;
		}
		return res;
	}
	Matrix<T> res = x;
	n--;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		x %= mod;
		n >>= 1;
		res %= mod;
	}
	return res;
}

template<typename T>
void print(const Matrix<T>& a) {
	rep(i, a.row_size()) {
		rep(j, a.column_size()) {
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

int n;

void solve() {
	cin >> n;
	Matrix<int> A(vector<vector<int>>{
		{100, 1},
		{0, 1}
	}
	);
	auto B = mod_pow(A, n-1);
	//auto D = A * A;
	auto C = B * vector<int>{1, 1};
	cout << C[0] % mod << endl;

	int b = 0;
	for (int i = 0; i < n % 11; i++)b = b * 100 + 1;
	cout << b << endl;
}

signed main() {
	srand(time(NULL));
	int T = 100;
	cout << fixed << setprecision(15);
	rep(i, T) {
		char s[MAX];
		if (scanf("%s", s) == EOF) break;
		int n = strlen(s);
		for (int i = n - 1; i > -1; i--) {
			ungetc(s[i], stdin);
		}
		solve();
	}
	return 0;
}
0