結果

問題 No.492 IOI数列
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-03-11 01:15:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,875 bytes
コンパイル時間 1,708 ms
コンパイル使用メモリ 170,224 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 15:03:03
合計ジャッジ時間 2,622 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)


typedef long long ll;
#define mod1 1000000007LL
struct Mat1 { // by MrDindows
	using T = ll;
	T a[2][2];
	Mat1() {
		memset(a, 0, sizeof(a));
	}
	static Mat1 One() {
		Mat1 r;
		r[0][0] = r[1][1] = 1;
		return r;
	}
	T* operator[](int idx) {
		return a[idx];
	}
	const T* operator[](int idx) const {
		return a[idx];
	}
	Mat1 operator+(const Mat1& b) {
		Mat1 r;
		rep(i, 0, 2) rep(j, 0, 2) {
			r[i][j] = a[i][j] + b[i][j];
			if (r[i][j] >= mod1) {
				r[i][j] -= mod1;
			}
		}
		return r;
	}
	Mat1& operator*=(const Mat1& b) {
		return *this = *this * b;
	}
	Mat1 operator*(const Mat1& b) {
		Mat1 r;
		rep(i, 0, 2) rep(j, 0, 2) {
			rep(k, 0, 2) {
				r[i][j] += a[i][k] * b[k][j];
			}
			r[i][j] %= mod1;
		}
		return r;
	}
	Mat1 power(ll n) {
		if (n == 0) return Mat1::One();
		if (n == 1) return *this;
		Mat1 t = power(n / 2);
		t = t * t;
		if (n % 2) {
			t = t * *this;
		}
		return t;
	}
	void print() {
		rep(i, 0, 2) {
			cout << "[" << a[i][0] << ", " << a[i][1] << "]" << endl;
		}
		cout << endl;
	}
	bool empty() {
		return a[0][0] == 1 && a[0][1] == 0 && a[1][0] == 0 && a[1][1] == 1;
	}
	void clear() {
		*this = Mat1::One();
	}
};
//-----------------------------------------------------------------
ll solA(ll N) {
	Mat1 m;
	m.a[0][0] = 100;
	m.a[0][1] = 1;
	m.a[1][0] = 0;
	m.a[1][1] = 1;

	m = m.power(N - 1);

	return (m.a[0][0] + m.a[0][1]) % mod1;
}
//-----------------------------------------------------------------
string solB(ll N) {
	N %= 11;

	if (N == 0) return "0";

	ll n = 1 + (N - 1) * 2;

	string sa = "";
	rep(i, 0, n) {
		if (i % 2 == 0) sa = sa + "1";
		else sa = sa + "0";
	}
	return sa;
}
//-----------------------------------------------------------------
int main() {
	ll N;
	cin >> N;

	cout << solA(N) << endl;
	cout << solB(N) << endl;
}
0