Submission #19676965
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
#define ALL(x) std::begin(x), std::end(x)
using namespace std;
// @title 行列
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
template< class T >
struct Matrix {
size_t H, W;
vector< vector< T > > A;
Matrix() {}
Matrix(size_t n, size_t m) : H(n), W(m), A(H, vector< T >(W, 0)) {}
Matrix(size_t n) : H(n), W(n), A(H, vector< T >(W, 0)) {};
Matrix(const vector<vector<T>>& a) : A(a) {
H = a.size();
assert(H > 0);
W = a[0].size();
}
size_t height() const { return H; }
size_t width() const { return W; }
inline const vector< T > &operator[](int k) const { return (A.at(k)); }
inline vector< T > &operator[](int k) { return (A.at(k)); }
static Matrix I(size_t n) {
Matrix mat(n);
for(int i = 0; i < n; i++) mat[i][i] = 1;
return (mat);
}
Matrix &operator+=(const Matrix &B) {
assert(H == B.H && W == B.W);
for(int i = 0; i < H; i++)
for(int j = 0; j < W; j++)
(*this)[i][j] += B[i][j];
return (*this);
}
Matrix &operator-=(const Matrix &B) {
assert(H == B.H && W == B.W);
for(int i = 0; i < H; i++)
for(int j = 0; j < W; j++)
(*this)[i][j] -= B[i][j];
return (*this);
}
Matrix &operator*=(const Matrix &B) {
assert(W == B.H);
vector< vector< T > > C(H, vector< T >(B.W, 0));
for(int i = 0; i < H; i++)
for(int j = 0; j < B.W; j++)
for(int k = 0; k < W; k++)
C[i][j] += ((*this)[i][k] * B[k][j]);
A.swap(C);
return (*this);
}
Matrix &operator^=(long long k) {
Matrix B = Matrix::I(H);
while(k > 0) {
if(k & 1) B *= *this;
*this *= *this;
k >>= 1LL;
}
A.swap(B.A);
return (*this);
}
vector<T> operator*(const vector<T> &v) {
assert(W == v.size());
vector<T> ret(H, 0);
for(int i = 0; i < H; i++)
for(int j = 0; j < W; j++)
ret[i] += ((*this)[i][j] * v[j]);
return ret;
}
Matrix operator+(const Matrix &B) const { return (Matrix(*this) += B); }
Matrix operator-(const Matrix &B) const { return (Matrix(*this) -= B); }
Matrix operator*(const Matrix &B) const { return (Matrix(*this) *= B); }
Matrix operator^(const long long k) const { return (Matrix(*this) ^= k); }
friend ostream &operator<<(ostream &os, Matrix &p) {
for(int i = 0; i < p.H; i++) {
for(int j = 0; j < p.W; j++) {
os << p[i][j] << (j + 1 == p.W ? "\n" : " ");
}
}
return (os);
}
};
using ll = long long;
using matrix = Matrix<ll>;
matrix l1({
{0, 1, 0},
{-1, 0, 0},
{0, 0, 1}
});
matrix l2({
{0, -1, 0},
{1, 0, 0},
{0, 0, 1}
});
struct Pos { int x, y; };
int main() {
int n; cin >> n;
vector<Pos> pos;
for (int i = 0; i < n; ++i) {
int x, y; cin >> x >> y;
pos.push_back((Pos){x, y});
}
vector<matrix> mat;
mat.push_back(matrix({
{1, 0, 0},
{0, 1, 0},
{0, 0, 1}
}));
int m; cin >> m;
for (int i = 0; i < m; ++i) {
int op; cin >> op;
int p;
if (op >= 3) cin >> p;
matrix &b = mat.back();
if (op == 1) {
mat.push_back(l1*b);
}
else if (op == 2) {
mat.push_back(l2*b);
}
else if (op == 3) {
matrix l3({
{-1, 0, 2*p},
{0, 1, 0},
{0, 0, 1}
});
mat.push_back(l3*b);
}
else {
matrix l4({
{1, 0, 0},
{0, -1, 2*p},
{0, 0, 1}
});
mat.push_back(l4*b);
}
}
int q; cin >> q;
for (int i = 0; i < q; ++i) {
int a, b; cin >> a >> b;
Pos p = pos[b-1];
vector<ll> l = {p.x, p.y, 1};
vector<ll> ans = mat[a]*l;
cout << ans[0] << " " << ans[1] << endl;
}
return 0;
}
Submission Info
Submission Time
2021-01-24 13:29:50
Task
E - Rotate and Flip
User
sash
Language
C++ (GCC 9.2.1)
Score
500
Code Size
4068 Byte
Status
AC
Exec Time
759 ms
Memory
49536 KB
Compile Error
./Main.cpp: In instantiation of ‘std::vector<_Tp> Matrix<T>::operator*(const std::vector<_Tp>&) [with T = long long int]’:
./Main.cpp:156:33: required from here
./Main.cpp:74:22: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
74 | for(int i = 0; i < H; i++)
| ~~^~~
./Main.cpp:75:24: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
75 | for(int j = 0; j < W; j++)
| ~~^~~
./Main.cpp: In instantiation of ‘Matrix<T>& Matrix<T>::operator*=(const Matrix<T>&) [with T = long long int]’:
./Main.cpp:82:67: required from ‘Matrix<T> Matrix<T>::operator*(const Matrix<T>&) const [with T = long long int]’
./Main.cpp:129:30: required from here
./Main.cpp:52:22: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
52 | for(int i = 0; i < H; i++)
| ~~^~~
./Main.cpp:53:24: warning: comparison of integer expressions of different signedness: ‘int’ and ‘const size_t’ {aka ‘const long unsigned int’} [-Wsign-compare]
53 | for(int j = 0; j < B.W; j++)
| ~~^~~~~
./Main.cpp:54:26: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
54 | for(int k = 0; k < W; k++)
| ~~^~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
500 / 500
Status
Set Name
Test Cases
Sample
sample_01.txt, sample_02.txt
All
max_01.txt, max_02.txt, max_03.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, sample_01.txt, sample_02.txt
Case Name
Status
Exec Time
Memory
max_01.txt
AC
686 ms
49512 KB
max_02.txt
AC
676 ms
49468 KB
max_03.txt
AC
234 ms
45372 KB
random_01.txt
AC
3 ms
3460 KB
random_02.txt
AC
3 ms
3376 KB
random_03.txt
AC
3 ms
3604 KB
random_04.txt
AC
4 ms
3404 KB
random_05.txt
AC
3 ms
3552 KB
random_06.txt
AC
2 ms
3564 KB
random_07.txt
AC
3 ms
3628 KB
random_08.txt
AC
2 ms
3560 KB
random_09.txt
AC
3 ms
3600 KB
random_10.txt
AC
2 ms
3424 KB
random_11.txt
AC
3 ms
3488 KB
random_12.txt
AC
6 ms
3584 KB
random_13.txt
AC
3 ms
3376 KB
random_14.txt
AC
3 ms
3576 KB
random_15.txt
AC
3 ms
3628 KB
random_16.txt
AC
3 ms
3556 KB
random_17.txt
AC
2 ms
3588 KB
random_18.txt
AC
3 ms
3592 KB
random_19.txt
AC
4 ms
3452 KB
random_20.txt
AC
4 ms
3404 KB
random_21.txt
AC
377 ms
24956 KB
random_22.txt
AC
757 ms
49512 KB
random_23.txt
AC
759 ms
49536 KB
sample_01.txt
AC
6 ms
3464 KB
sample_02.txt
AC
3 ms
3364 KB