QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#93790 | #6189. Full Clue Problem | Andycipation | AC ✓ | 3ms | 3472kb | C++17 | 3.0kb | 2023-04-02 14:30:11 | 2023-04-02 14:30:14 |
Judging History
answer
/*
* author: ADMathNoob
* created: 04/02/23 01:59:36
* problem: no source provided
*/
/*
Comments about problem:
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "../.cp/algorithms/debug/debug.h"
#else
#define debug(...) 42
#endif
template <typename T>
void Print2d(const vector<vector<T>>& a) {
for (const auto& row : a) {
for (int i = 0; i < (int) row.size(); i++) {
if (i > 0) cout << ' ';
cout << row[i];
}
cout << '\n';
}
}
template <typename T>
class Matrix : public vector<vector<T>> {
public:
int n, m;
// initialization order is the order the values are defined
// in the class, not the order we write the initializations
Matrix(int n_, int m_) : vector<vector<T>>(n_, vector<T>(m_)), n(n_), m(m_) {
assert(n > 0 && m > 0);
}
Matrix(const vector<vector<T>>& v) {
n = static_cast<int>(v.size());
assert(n > 0);
m = static_cast<int>(v[0].size());
for (int i = 1; i < n; i++) {
assert(static_cast<int>(v[i].size()) == m);
}
this->resize(n);
for (int i = 0; i < n; i++) {
(*this)[i].resize(m);
for (int j = 0; j < m; j++) {
(*this)[i][j] = v[i][j];
}
}
}
Matrix t() const {
Matrix res(m, n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
res[j][i] = (*this)[i][j];
}
}
return res;
}
};
template <typename T>
Matrix<T> Identity(int n) {
Matrix<T> res(n, n);
for (int i = 0; i < n; i++) {
res[i][i] = 1;
}
return res;
}
template <typename T>
Matrix<T> operator*(const Matrix<T>& a, const Matrix<T>& b) {
assert(a.m == b.n);
Matrix<T> res(a.n, b.m);
for (int i = 0; i < a.n; i++) {
for (int j = 0; j < b.m; j++) {
for (int k = 0; k < a.m; k++) {
res[i][j] += a[i][k] * b[k][j];
}
}
}
return res;
}
template <typename T>
Matrix<T> power(Matrix<T> a, long long b) {
assert(a.n == a.m);
Matrix<T> res = Identity<T>(a.n);
while (b > 0) {
if (b & 1) {
res = res * a;
}
a = a * a;
b >>= 1;
}
return res;
}
using Mat = Matrix<int>;
// for vectors, just declare an n-by-1 Mat
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<vector<int>> c(n, vector<int>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == 0 && j == 0) {
c[i][j] = 3;
continue;
}
if (i == n - 1 && j == n - 1) {
c[i][j] = 3;
continue;
}
if (abs(i - j) <= 1) {
c[i][j] = 2;
continue;
}
if (abs(i - j) == 2) {
c[i][j] = 1;
continue;
}
c[i][j] = 0;
}
}
Mat a(n, n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) {
a[i][j] = 1;
continue;
}
if (i % 2 == 0 && abs(i - j) == 1) {
a[i][j] = 1;
continue;
}
}
}
Mat b = a.t();
Print2d(c);
cout << '\n';
Print2d(a);
cout << '\n';
Print2d(b);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 3460kb
input:
5
output:
3 2 1 0 0 2 2 2 1 0 1 2 2 2 1 0 1 2 2 2 0 0 1 2 3 1 1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 1
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3464kb
input:
2
output:
3 2 2 3 1 1 0 1 1 0 1 1
result:
ok ok
Test #3:
score: 0
Accepted
time: 3ms
memory: 3392kb
input:
3
output:
3 2 1 2 2 2 1 2 3 1 1 0 0 1 0 0 1 1 1 0 0 1 1 1 0 0 1
result:
ok ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 3372kb
input:
4
output:
3 2 1 0 2 2 2 1 1 2 2 2 0 1 2 3 1 1 0 0 0 1 0 0 0 1 1 1 0 0 0 1 1 0 0 0 1 1 1 0 0 0 1 0 0 0 1 1
result:
ok ok
Test #5:
score: 0
Accepted
time: 1ms
memory: 3472kb
input:
10
output:
3 2 1 0 0 0 0 0 0 0 2 2 2 1 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 1 2 2 2 0 0 0 0 0 0 0 1 2 3 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0...
result:
ok ok
Test #6:
score: 0
Accepted
time: 2ms
memory: 3420kb
input:
19
output:
3 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 0 ...
result:
ok ok
Test #7:
score: 0
Accepted
time: 2ms
memory: 3472kb
input:
20
output:
3 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 2 1 ...
result:
ok ok