結果

問題 No.492 IOI数列
ユーザー はまやんはまやん
提出日時 2017-03-10 23:17:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,921 bytes
コンパイル時間 1,705 ms
コンパイル使用メモリ 169,872 KB
実行使用メモリ 500,436 KB
最終ジャッジ日時 2024-06-24 08:40:28
合計ジャッジ時間 4,029 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 1 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

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(int 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;
string s = "1";
rep(i, 0, N - 1) s += "01";
int mag = 21;
if (s.length() < 21) {
cout << s << endl;
return 0;
}
if (s.length() % 21 == 0) {
cout << 0 << endl;
return 0;
}
if (s.length() % 22 == 0) {
cout << 0 << endl;
return 0;
}
int cnt = s.length() / 22 * 22;
string sa = s.substr(cnt);
cout << sa << endl;
//101010101010101010101
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0