結果

問題 No.255 Splarrraaay スプラーレェーーイ
ユーザー pekempeypekempey
提出日時 2016-10-30 17:36:42
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,889 bytes
コンパイル時間 1,118 ms
コンパイル使用メモリ 160,972 KB
実行使用メモリ 10,140 KB
最終ジャッジ日時 2024-05-03 19:54:08
合計ジャッジ時間 25,134 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:80:19: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘int64_t*’ {aka ‘long int*’} [-Wformat=]
   80 |         scanf("%lld", &C);
      |                ~~~^   ~~
      |                   |   |
      |                   |   int64_t* {aka long int*}
      |                   long long int*
      |                %ld
main.cpp:80:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   80 |         scanf("%lld", &C);
      |         ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define getchar getchar_unlocked
#define putchar putchar_unlocked

typedef array<int, 2> F;

const int mod = 1e9 + 7;

const int B = 6;
F dub[60 / B][1 << B];

int mul(int x, int y) {
    return int64_t(x) * y % mod;
}

int add(int x, int y) {
    return (x += y) >= mod ? x - mod : x;
}

template<class... T>
int add(int x, T... y) {
    return add(x, add(y...));
}

void upd(int &x, int y) {
    x = add(x, y);
}

int pow(int a, int64_t b) {
    if (a == 0) return 0;
    int res = 1;
    while (b > 0) {
        if (b & 1) res = mul(res, a);
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}

F mul(F a, F b) {
    F res;
    res[0] = add(mul(a[0], b[0]), mul(a[1], b[1]));
    res[1] = add(mul(a[0], b[1]), mul(a[1], b[0]), mul(a[1], b[1]));
    return res;
}

F fib(int64_t n) {
    F f = { 1, 0 };
    for (int i = 0; n > 0; i++) {
        if (n % (1 << B) != 0) f = mul(f, dub[i][n % (1 << B)]);
        n >>= B;
    }
    return f;
}

void in(char *s) {
    int i = 0;
    char c;
    while ((c = getchar()) < '0') if (c == EOF) return;
    s[i++] = c;
    while ((c = getchar()) >= '0') s[i++] = c;
    s[i] = 0;
}

int main() {
    dub[0][1][1] = 1;
    for (int i = 0; i < 64 / B; i++) {
        if (i > 0) dub[i][1] = mul(dub[i - 1][(1 << B) - 1], dub[i - 1][1]);
        for (int j = 2; j < 1 << B; j++) {
            dub[i][j] = mul(dub[i][1], dub[i][j - 1]);
        }
    }
    int n;
    cin >> n;
    int ans = 1;
    while (n--) {
        int64_t C;
        scanf("%lld", &C);
        static char D[210];
        in(D);
        int64_t d = 0;
        for (int i = 0; D[i] != 0; i++) {
            d = d * 10 + D[i] - '0';
            if (d >= (int)1e17) d %= mod - 1;
        }
        d %= mod - 1;
        F f = fib(C);
        ans = mul(ans, pow(add(f[0], f[1], f[1]), d));
    }
    cout << ans << endl;
}
0