結果

問題 No.675 ドットちゃんたち
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-06-22 15:07:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 3,218 bytes
コンパイル時間 4,005 ms
コンパイル使用メモリ 177,768 KB
実行使用メモリ 24,676 KB
最終ジャッジ日時 2023-08-27 02:50:22
合計ジャッジ時間 5,194 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,008 KB
testcase_01 AC 3 ms
5,760 KB
testcase_02 AC 3 ms
6,008 KB
testcase_03 AC 4 ms
6,008 KB
testcase_04 AC 4 ms
6,012 KB
testcase_05 AC 117 ms
23,688 KB
testcase_06 AC 128 ms
24,596 KB
testcase_07 AC 115 ms
22,604 KB
testcase_08 AC 123 ms
24,512 KB
testcase_09 AC 128 ms
24,668 KB
testcase_10 AC 127 ms
24,676 KB
testcase_11 AC 128 ms
24,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
using TN = ll; using Vec = vector<TN>; using Mat = vector<Vec>;
Vec mulMatVec(Mat a, Vec b) {
    int n = b.size(); Vec ret(n, 0);
    rep(i, 0, n) rep(j, 0, n) ret[i] = ret[i] + a[i][j] * b[j];
    return ret;
}
Vec mulVecMat(Vec a, Mat b) {
    int n = b.size(); Vec ret(n, 0);
    rep(i, 0, n) rep(j, 0, n) ret[i] = ret[i] + a[j] * b[j][i];
    return ret;
}
Mat identityMat(int n) {
	Mat m(n, Vec(n, 0));
	rep(i, 0, n) m[i][i] = 1;
	return m;
}
Mat mulMatMat(Mat a, Mat b) {
    int n = a.size(); Mat ret(n, Vec(n, 0));
    rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) ret[i][j] = ret[i][j] + a[i][k] * b[k][j];
    return ret;
}
Mat fastpow(Mat x, ll n) {
    Mat ret(x.size(), Vec(x.size(), 0));
    rep(i, 0, x.size()) ret[i][i] = 1;
    while (0 < n) { if ((n % 2) == 0) { x = mulMatMat(x, x); n >>= 1; } else { ret = mulMatMat(ret, x); --n; } }
    return ret;
}
void printVec(Vec a) { cout << "[\t"; rep(i, 0, a.size()) cout << a[i] << "\t"; cout << "]" << endl; }
void printMat(Mat a) { rep(i, 0, a.size()) printVec(a[i]); }
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/










ll N, Px, Py, T[101010], X[101010];
Mat ms[101010];
//---------------------------------------------------------------------------------------------------
Mat command1(ll dx) {
	return {
		{1, 0, dx}, 
		{0, 1, 0}, 
		{0, 0, 1}
	};
}
Mat command2(ll dy) {
	return {
		{1, 0, 0},
		{0, 1, dy},
		{0, 0, 1}
	};
}
Mat command3() {
	return {
		{0, 1, 0}, // cos(-90), -sin(-90)
		{-1, 0, 0},  // sin(-90), cos(-90)
		{0, 0, 1}
	};
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> Px >> Py;
	rep(i, 0, N) {
		cin >> T[i];
		if (T[i] != 3) cin >> X[i];
	}

	ms[N] = identityMat(3);

	rrep(i, N - 1, 0) {
		Mat m;
		if (T[i] == 1) m = command1(X[i]);
		else if (T[i] == 2) m = command2(X[i]);
		else m = command3();

		ms[i] = mulMatMat(ms[i + 1], m);
	}

	rep(i, 0, N) {
		Vec v = { Px, Py, 1 };
		v = mulMatVec(ms[i], v);
		printf("%lld %lld\n", v[0], v[1]);
	}
}
0