結果

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

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

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

int N, Q;

int64 A[100000][3][3];
int64 B[100000][2][2];
int64 a[100000][3];
int64 b[100000][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 + 2][1] %= mod;
  a[i + 3][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