結果

問題 No.492 IOI数列
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-03-10 23:29:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 2,013 bytes
コンパイル時間 1,672 ms
コンパイル使用メモリ 169,236 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 14:24:41
合計ジャッジ時間 2,462 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 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 N;
//-----------------------------------------------------------------
int main() {
	cin >> N;

	if (N == 1) {
		printf("1\n1\n");
		return 0;
	}

	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);

	ll ans = (m.a[0][0] + m.a[0][1]) % mod1;
	cout << ans << endl;

	

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

	int mag = 21;
	if (n < 21) {
		string s = "1";
		rep(i, 0, N - 1) s += "01";
		cout << s << endl;
		return 0;
	}
	else if (n == 21) {
		cout << 0 << endl;
		return 0;
	}

	if (22 < n && (n - 21) % 22 == 0) {
		cout << 0 << endl;
		return 0;
	}

	ll cnt = n / 22 * 22;
	ll oth = n - cnt;
	string sa = "";
	rep(i, 0, oth) {
		if (i % 2 == 0) sa = sa + "1";
		else sa = sa + "0";
	}
	cout << sa << endl;

	//101010101010101010101
}
0