Skip to content

Commit

Permalink
20240306 tsreaper's submission (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsreaper authored Mar 6, 2024
1 parent 46f41d8 commit 5977ada
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <bits/stdc++.h>
using namespace std;

void solve() {
int n, K; scanf("%d%d", &n, &K);
if (K % 3) {
if (n % 3) printf("Alice\n");
else printf("Bob\n");
} else {
n %= K + 1;
if (n % 3 || n == K) printf("Alice\n");
else printf("Bob\n");
}
}

int main() {
int tcase; scanf("%d", &tcase);
while (tcase--) solve();
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <bits/stdc++.h>
#define MOD ((int) 1e9 + 7)
using namespace std;

int n, m, G, X, cnt[10];

struct Matrix {
int n, m;
long long V[100][100];

Matrix(int n, int m): n(n), m(m) {
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) V[i][j] = 0;
}

Matrix operator*(const Matrix &A) const {
Matrix B(n, A.m);
for (int i = 0; i < n; i++) for (int j = 0; j < A.m; j++) for (int k = 0; k < m; k++)
B.V[i][j] = (B.V[i][j] + V[i][k] * A.V[k][j]) % MOD;
return B;
}
};

Matrix power(Matrix &A, long long b) {
Matrix Y(A.n, A.n);
for (int i = 0; i < Y.n; i++) Y.V[i][i] = 1;
for (; b; b >>= 1) {
if (b & 1) Y = Y * A;
A = A * A;
}
return Y;
}

int main() {
scanf("%d%d%d%d", &n, &m, &G, &X);
for (int i = 1; i <= n; i++) {
int x; scanf("%d", &x);
cnt[x]++;
}

Matrix K(X, X);
for (int i = 0; i < X; i++) for (int j = 1; j <= 9; j++) {
int ii = (i * 10 + j) % X;
K.V[i][ii] = (K.V[i][ii] + cnt[j]) % MOD;
}
K = power(K, m);

Matrix A(1, X);
A.V[0][0] = 1;
A = A * K;
printf("%lld\n", A.V[0][G]);
return 0;
}
2 changes: 1 addition & 1 deletion records/202403.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Name, Days with Submissions, Total Submissions
Yawn_Sean,4,8
Arrogant_sword,4,5
TsReaper,4,8
TsReaper,5,10
retyrn,4,6
ncf,4,4
hum,4,8
Expand Down

0 comments on commit 5977ada

Please sign in to comment.