Submission #1453889
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
//int dxy[5] = {0, 1, 0, -1, 0};
// assign avl ncm dij geo2 kruskal graph uf lca BIT
typedef unsigned long long Num;
struct Matrix {
vector< vector< Num > > v, w;
Matrix() {}
Matrix(int n, int m) :v(n, vector<Num>(m)) { }
inline int height()const { return (int)v.size(); }
inline int width()const { return (int)v[0].size(); }
inline Num& at(int i, int j) { return v[i][j]; }
inline const Num& at(int i, int j)const { return v[i][j]; }
static Matrix identity(int n) {
Matrix A(n, n);
for (int i = 0; i < n; i++) A.at(i, i) = ~0U;
return A;
}
inline static Matrix identity(const Matrix& A) { return identity(A.height()); }
Matrix &operator*=(const Matrix& B) {
int n = height(), m = B.width(), p = B.height();
assert(p == width());
w.assign(n, vector<Num>(m, 0));
for (int i = 0; i < n; i++)for (int j = 0; j < m; j++) {
Num x = 0;
for (int k = 0; k < p; k++)
x ^= at(i, k) & B.at(k, j);
w[i][j] = x;
}
v.swap(w);
return *this;
}
};
Matrix operator^(const Matrix &m, long long exponent) {
Matrix A = m, B = Matrix::identity(m);
while (exponent) {
if (exponent & 1) B *= A;
A *= A;
exponent >>= 1;
}
return B;
}
signed main() {
int2(k, m);
vi a(k), c(k);
rep(i, k) cin >> a[i];
rep(i, k) cin >> c[i];
Matrix funami(k, k);
rep(i, k) {
funami.at(0, i) = c[i];
}
rep(i, k-1) {
funami.at(i+1, i) = ~0U;
}
Matrix toshino(k, 1);
rep(i, k) {
toshino.at(i, 0) = a[k-1-i];
}
if (m - k > 0) {
funami = funami ^ (m - k);
funami *= toshino;
std::cout << funami.at(0, 0) << std::endl;
} else {
std::cout << a[m-1] << std::endl;
}
return 0;
}
Submission Info
Submission Time |
|
Task |
D - 漸化式 |
User |
Ti11192916 |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
2572 Byte |
Status |
AC |
Exec Time |
42 ms |
Memory |
640 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:23:56: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
^
./Main.cpp:74:5: note: in expansion of macro ‘int2’
int2(k, m);
^
Judge Result
Set Name |
All |
Score / Max Score |
100 / 100 |
Status |
|
Set Name |
Test Cases |
All |
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, sample_1.txt, sample_2.txt, sample_3.txt, small_1.txt, small_2.txt |
Case Name |
Status |
Exec Time |
Memory |
random_01.txt |
AC |
1 ms |
256 KB |
random_02.txt |
AC |
1 ms |
256 KB |
random_03.txt |
AC |
1 ms |
256 KB |
random_04.txt |
AC |
1 ms |
256 KB |
random_05.txt |
AC |
1 ms |
256 KB |
random_06.txt |
AC |
1 ms |
256 KB |
random_07.txt |
AC |
3 ms |
256 KB |
random_08.txt |
AC |
7 ms |
384 KB |
random_09.txt |
AC |
40 ms |
640 KB |
random_10.txt |
AC |
42 ms |
640 KB |
random_11.txt |
AC |
41 ms |
640 KB |
random_12.txt |
AC |
41 ms |
640 KB |
random_13.txt |
AC |
41 ms |
640 KB |
random_14.txt |
AC |
41 ms |
640 KB |
random_15.txt |
AC |
39 ms |
640 KB |
sample_1.txt |
AC |
1 ms |
256 KB |
sample_2.txt |
AC |
1 ms |
256 KB |
sample_3.txt |
AC |
2 ms |
256 KB |
small_1.txt |
AC |
1 ms |
256 KB |
small_2.txt |
AC |
1 ms |
256 KB |