結果

問題 No.675 ドットちゃんたち
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2018-04-13 23:02:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 3,269 bytes
コンパイル時間 1,953 ms
コンパイル使用メモリ 177,820 KB
実行使用メモリ 5,940 KB
最終ジャッジ日時 2023-09-09 04:45:52
合計ジャッジ時間 3,871 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 86 ms
5,544 KB
testcase_06 AC 97 ms
5,872 KB
testcase_07 AC 88 ms
5,704 KB
testcase_08 AC 93 ms
5,860 KB
testcase_09 AC 98 ms
5,876 KB
testcase_10 AC 98 ms
5,940 KB
testcase_11 AC 96 ms
5,852 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 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     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/




int N, PX, PY, A[101010], B[101010];
ll ansx[101010], ansy[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> PX >> PY;
    rep(i, 0, N) {
        cin >> A[i];
        if (A[i] != 3) cin >> B[i];
    }

    Mat m(3, Vec(3, 0));
    rep(i, 0, 3) m[i][i] = 1;

    rrep(i, N - 1, 0) {
        Vec v(3, 0);
        v[0] = PX;
        v[1] = PY;
        v[2] = 1;

        Mat mm(3, Vec(3, 0));
        if (A[i] == 1) {
            mm[0][0] = 1;
            mm[0][2] = B[i];
            mm[1][1] = 1;
            mm[2][2] = 1;
        }
        else if (A[i] == 2) {
            mm[0][0] = 1;
            mm[1][1] = 1;
            mm[1][2] = B[i];
            mm[2][2] = 1;
        }
        else {
            mm[0][0] = 0;
            mm[0][1] = 1;
            mm[1][0] = -1;
            mm[1][1] = 0;
            mm[2][2] = 1;
        }

        m = mulMatMat(m, mm);
        v = mulMatVec(m, v);

        ansx[i] = v[0];
        ansy[i] = v[1];
    }

    rep(i, 0, N) printf("%lld %lld\n", ansx[i], ansy[i]);
}
0