-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
20240306 tsreaper's submission (#125)
- Loading branch information
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
daily_problems/2024/03/0306/personal_submission/cf1194d_tsreaper.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
52 changes: 52 additions & 0 deletions
52
daily_problems/2024/03/0306/personal_submission/cf621e_tsreaper.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters