제출 #1337476

#제출 시각아이디문제언어결과실행 시간메모리
1337476penguin133Struktura (COCI26_struktura)C++20
110 / 110
1 ms344 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, k, f[1000005];
const int mod = 1e9 + 7;

int exp(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res *= a, res %= mod;
		a *= a, a %= mod;
		b >>= 1 ;
	}
	return res;
}

vector <vector <int> > matmul(vector <vector <int>> a, vector <vector <int> > b) {
	vector <vector <int> > c;
	c.resize(a.size());
	for (int i = 0; i < (int)a.size(); i++) c[i].resize(a[i].size());
	for (int i = 0; i < (int)a.size(); i++) {
		for (int j = 0; j < (int)a[i].size(); j++) {
			for (int k = 0; k < (int)a[i].size(); k++) {
				c[i][j] += a[i][k] * b[k][j];
				c[i][j] %= mod;
			}
		}
	}
	return c;
}

vector <vector <int> > bs = {{1, 1}, {1, 0}};

vector <vector <int> > matexp(int x) {
	if (x == 1) return bs;
	vector <vector <int> > l = matexp(x / 2);
	l = matmul(l, l);
	if (x & 1) l = matmul(l, bs);
	return l;
}

void solve(){
	cin >> n >> k;
	if (k < n) {
		cout << "0\n";
		return;
	}
	/*
	f[1] = 1;
	f[2] = 2;
	for (int i = 3; i <= n; i++) f[i] = (f[i - 1] + f[i - 2]) % mod;
	*/
	vector <vector <int> > res = matexp(n);
	cout << res[0][0] * exp(exp(k, n), mod - 2) % mod;
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...