結果

問題 No.675 ドットちゃんたち
ユーザー TamuoTamuoTamuoTamuoTamuoTamuo
提出日時 2019-06-22 23:51:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 280 ms / 2,000 ms
コード長 2,305 bytes
コンパイル時間 1,081 ms
コンパイル使用メモリ 88,320 KB
実行使用メモリ 9,608 KB
最終ジャッジ日時 2023-08-27 03:20:30
合計ジャッジ時間 4,325 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 247 ms
9,416 KB
testcase_06 AC 280 ms
9,332 KB
testcase_07 AC 241 ms
8,616 KB
testcase_08 AC 260 ms
9,464 KB
testcase_09 AC 270 ms
9,344 KB
testcase_10 AC 274 ms
9,608 KB
testcase_11 AC 265 ms
9,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<list>

#define REP(i,a,n) for(ll i=a;i<n;i++)

typedef long long ll;
using namespace std;

vector<vector<ll>> mul_matrix(vector<vector<ll>> A,vector<vector<ll>> B){
    vector<vector<ll>> result(A.size(),vector<ll>(B[0].size()));
    REP(i,0,A.size()){
        REP(j,0,B[0].size()){
            REP(k,0,A[0].size()){
                result[i][j]+=A[i][k]*B[k][j];
            }
        }
    }
    return result;
}

int main(){
    vector<vector<ll>> input(3,vector<ll>(1));
    vector<vector<ll>> output(3,vector<ll>(1));
    vector<vector<ll>> command_matrix(3,vector<ll>(3));
    vector<vector<ll>> stack_matrix(3,vector<ll>(3));
    vector<pair<ll,ll>> inputlist;
    list<pair<ll,ll>> anslist;
    ll n,x,y,command,d;

    cin >> n >> x >> y;
    input[0][0]=1;
    input[1][0]=x;
    input[2][0]=y;
    stack_matrix={
        {1,0,0},
        {0,1,0},
        {0,0,1}};

    //inputの列を格納
    REP(i,0,n){
        cin >> command;
        d=0;
        if(command!=3) cin >> d;
        inputlist.push_back(make_pair(command,d));
    }

    //行列計算
    for(int i=n-1;i>=0;i--){
        //cout<< i << endl;
        command=inputlist[i].first;
        d=inputlist[i].second;
        switch(command){
            case 1:
                command_matrix={
                    {1,0,0},
                    {d,1,0},
                    {0,0,1}};
                break;
            case 2:
                command_matrix={
                    {1,0,0},
                    {0,1,0},
                    {d,0,1}};
                break;
            case 3:
                command_matrix={
                    {1,0,0},
                    {0,0,1},
                    {0,-1,0}};
                break;
        }
        /**
        REP(i,0,command_matrix.size()){
            REP(j,0,command_matrix[0].size()){
                cout << command_matrix[i][j] << " ";
        }
            cout << endl;
        }
        **/
        stack_matrix=mul_matrix(stack_matrix,command_matrix);
        output = mul_matrix(stack_matrix,input);
        anslist.push_front(make_pair(output[1][0],output[2][0]));
    }
    for(auto itr=anslist.begin();itr!=anslist.end();itr++){
        cout << (*itr).first << " " <<(*itr).second << endl;
    }
}
0