結果

問題 No.675 ドットちゃんたち
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2017-03-08 20:49:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 2,286 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 100,544 KB
実行使用メモリ 8,072 KB
最終ジャッジ日時 2023-09-06 00:34:31
合計ジャッジ時間 4,067 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 236 ms
7,700 KB
testcase_06 AC 268 ms
7,756 KB
testcase_07 AC 236 ms
7,492 KB
testcase_08 AC 247 ms
8,072 KB
testcase_09 AC 257 ms
7,736 KB
testcase_10 AC 264 ms
7,752 KB
testcase_11 AC 256 ms
7,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

vector<vector<ll> > mul9x9(vector<vector<ll> > a, vector<vector<ll> > b){
  vector<vector<ll> > ret(3,vector<ll>(3,0));
  rep(i,0,3){
    rep(j,0,3){
      rep(k,0,3){
        ret[i][j] += a[i][k] * b[k][j];
      }
    }
  }
  return ret;
}

vector<vector<ll> > mul9x3(vector<vector<ll> > a, vector<vector<ll> > b){
  vector<vector<ll> > ret(3,vector<ll>(1,0));
  rep(i,0,3){
    rep(j,0,1){
      rep(k,0,3){
        ret[i][j] += a[i][k] * b[k][j];
      }
    }
  }
  return ret;
}

int main() {
	ll n,ax,ay;
  cin>>n>>ax>>ay;
  vector<vector<ll> > p(3,vector<ll>(1,0));
  p[0][0] = ax;
  p[1][0] = ay;
  p[2][0] = 1;
  vector<pair<ll,ll> > v;
  rep(i,0,n){
    ll a;
    cin>>a;
    if(a==3){
      v.pb(mp(a,0));
    }
    else{
      ll b;
      cin>>b;
      v.pb(mp(a,b));
    }
  }
  reverse(all(v));
  vector<pair<ll,ll> > ans;
  vector<vector<ll> > mat(3,vector<ll>(3,0));
  mat[0][0] = 1;
  mat[1][1] = 1;
  mat[2][2] = 1;
  rep(i,0,v.sz){
    vector<vector<ll> > vv(3,vector<ll>(3,0));
    if(v[i].fi == 1){
      vv[0][2] = v[i].se;
      vv[0][0] = 1;
      vv[1][1] = 1;
      vv[2][2] = 1;
    }
    else if(v[i].fi == 2){
      vv[1][2] = v[i].se;
      vv[0][0] = 1;
      vv[1][1] = 1;
      vv[2][2] = 1;
    }
    else{
      vv[0][1] = 1;
      vv[1][0] = -1;
      vv[2][2] = 1;
    }
    mat = mul9x9(mat,vv);
    vector<vector<ll> > res = mul9x3(mat,p);
    ans.pb(mp(res[0][0],res[1][0]));
  }
  reverse(all(ans));
  rep(i,0,ans.sz){
    cout << ans[i].fi << " " << ans[i].se << endl;
  }
	return 0;
}
0