結果

問題 No.147 試験監督(2)
ユーザー latte0119latte0119
提出日時 2016-05-25 23:59:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,048 bytes
コンパイル時間 881 ms
コンパイル使用メモリ 90,428 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 16:48:39
合計ジャッジ時間 2,721 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 335 ms
5,248 KB
testcase_01 AC 333 ms
5,376 KB
testcase_02 AC 338 ms
5,376 KB
testcase_03 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:93:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   93 |         scanf("%d", &N);
      |         ~~~~~^~~~~~~~~~
main.cpp:99:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   99 |                 scanf("%lld%s", &C, D);
      |                 ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<cstdio>
#include<algorithm>
#include<vector>
#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<sstream>
#include<bitset>
#include<numeric>
#include<climits>
#include<cassert>
#include<complex>
#include<functional>
using namespace std;

typedef long long ll;
template<typename A,typename B>inline void chmin(A &a, B b) { if (a > b)a = b; }
template<typename A,typename B>inline void chmax(A &a, B b) { if (a < b)a = b; }

template<int MOD>
class kitamasa_hou {
	int K;
	vector<long long>A, D;

	vector<long long>advance(vector<long long>x) {
		rotate(x.begin(), x.end() - 1, x.end());
		for (int i = 1; i<x.size(); i++)x[i] = (x[i] + x[0] * D[i]) % MOD;
		return x;
	}

	vector<long long>advance2(vector<long long>x) {
		vector<long long>y = x, z(K, 0);
		for (int i = 0; i<K; i++) {
			for (int j = 0; j<K; j++)z[j] = (z[j] + x[j] * y[i]) % MOD;
			x = advance(x);
		}
		return z;
	}

public:
	kitamasa_hou(int K, vector<long long>A, vector<long long>D)
		:K(K), A(A.begin(), A.end()), D(D.begin(), D.end()) {}

	ll query(ll N) {
		assert(K);
		vector<long long>x = D;
		if (N<K)return A[N];

		ll n = K;
		int p;
		[&]() {
			for (;; n++) {
				for (p = 0; N >> p; p++)if ((N >> p) == n)return;
				x = advance(x);
			}
		}();

		for (p--; p >= 0; p--) {
			x = advance2(x);
			if (N >> p & 1)x = advance(x);
		}


		ll ret = 0;
		for (int i = 0; i<K; i++)ret = (ret + x[i] * A[i]) % MOD;
		return ret;
	}
};


const int mod = 1000000007;

ll modpow(ll n,ll m){
	n %= mod;
	ll ret = 1;
	while (m) {
		if (m & 1)ret = ret*n%mod;
		n = n*n%mod;
		m >>= 1;
	}
	return ret;
}

int main() {
	ll ans = 1;
	int N;
	scanf("%d", &N);
	kitamasa_hou<mod>fib(2, { 1,2 }, { 1,1 });

	for (int i = 0; i < N;i++) {
		ll C;
		char D[210];
		scanf("%lld%s", &C, D);
		ll d = 0;
		for (int j = 0; D[j]; j++)d = (d * 10 + D[j] - '0') % (mod-1);
		ans = ans*modpow(fib.query(C), d) % mod;
	}

	cout << ans << endl;
	return 0;
}
0