結果
| 問題 |
No.675 ドットちゃんたち
|
| コンテスト | |
| ユーザー |
TamuoTamuoTamuo
|
| 提出日時 | 2019-06-22 23:51:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 277 ms / 2,000 ms |
| コード長 | 2,305 bytes |
| コンパイル時間 | 1,249 ms |
| コンパイル使用メモリ | 88,796 KB |
| 実行使用メモリ | 9,552 KB |
| 最終ジャッジ日時 | 2024-12-26 10:18:43 |
| 合計ジャッジ時間 | 4,455 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 8 |
ソースコード
#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;
}
}
TamuoTamuoTamuo