結果

問題 No.426 往復漸化式
ユーザー ei1333333ei1333333
提出日時 2016-09-22 23:25:14
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,994 bytes
コンパイル時間 1,385 ms
コンパイル使用メモリ 162,016 KB
実行使用メモリ 17,536 KB
最終ジャッジ日時 2024-04-28 19:57:50
合計ジャッジ時間 17,278 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 11 ms
5,376 KB
testcase_04 AC 12 ms
5,376 KB
testcase_05 AC 383 ms
5,376 KB
testcase_06 AC 374 ms
5,376 KB
testcase_07 AC 4,076 ms
17,416 KB
testcase_08 AC 4,305 ms
17,536 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

typedef long long int64;
const int mod = 1e9 + 7;

int N, Q;

int64 A[100001][3][3];
int64 B[100001][2][2];
int64 a[100001][3];
int64 b[100001][2];

void nextA(int i)
{
  a[i + 1][0] = A[i][0][0] * a[i][0] + A[i][0][1] * a[i][1] + A[i][0][2] * a[i][2];
  a[i + 1][1] = A[i][1][0] * a[i][0] + A[i][1][1] * a[i][1] + A[i][1][2] * a[i][2];
  a[i + 1][2] = A[i][2][0] * a[i][0] + A[i][2][1] * a[i][1] + A[i][2][2] * a[i][2];
  a[i + 1][0] %= mod;
  a[i + 1][1] %= mod;
  a[i + 1][2] %= mod;
}

void prevB(int i)
{
  b[i - 1][0] = B[i][0][0] * b[i][0] + B[i][0][1] * b[i][1];
  b[i - 1][1] = B[i][1][0] * b[i][0] + B[i][1][1] * b[i][1];
  b[i - 1][0] += (6 * i + 0) * a[i][0] + (6 * i + 1) * a[i][1] + (6 * i + 2) * a[i][2];
  b[i - 1][1] += (6 * i + 3) * a[i][0] + (6 * i + 4) * a[i][1] + (6 * i + 5) * a[i][2];
  b[i - 1][0] %= mod;
  b[i - 1][1] %= mod;
}


int main()
{
  cin >> N;
  for(int i = 0; i < 3; i++) cin >> a[0][i];
  for(int i = 0; i < 2; i++) cin >> b[N][i];
  for(int i = 0; i <= N; i++) for(int j = 0; j < 3; j++) A[i][j][j] = 1;
  for(int i = 0; i <= N; i++) for(int j = 0; j < 2; j++) B[i][j][j] = 1;
  for(int i = 0; i < N; i++) nextA(i);
  for(int i = N; i > 0; i--) prevB(i);

  cin >> Q;
  while(Q--) {
    string type;
    cin >> type;
    if(type == "a") {
      int idx;
      cin >> idx;
      for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) cin >> A[idx][i][j];
      }
      for(int i = 0; i < N; i++) nextA(i);
      for(int i = N; i > 0; i--) prevB(i);
    } else if(type == "b") {
      int idx;
      cin >> idx;
      for(int i = 0; i < 2; i++) {
        for(int j = 0; j < 2; j++) cin >> B[idx][i][j];
      }
      for(int i = N; i > 0; i--) prevB(i);
    } else if(type == "ga") {
      int idx;
      cin >> idx;
      cout << a[idx][0] << " " << a[idx][1] << " " << a[idx][2] << endl;
    } else {
      int idx;
      cin >> idx;
      cout << b[idx][0] << " " << b[idx][1] << endl;
    }
  }
}
0