QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#221881 | #7606. Digital Nim | ucup-team180# | ML | 0ms | 0kb | C++17 | 1.4kb | 2023-10-21 14:57:50 | 2023-10-21 14:57:51 |
answer
#include <bits/stdc++.h>
using namespace std;
const int B = 10;
const int MAX = 100000;
int digit_sum(int x){
int ans = 0;
while (x > 0){
ans += x % B;
x /= B;
}
return ans;
}
int main(){
vector<vector<vector<int>>> dp(18, vector<vector<int>>(163, vector<int>(1 << 17, 0)));
for (int i = 0; i < 163; i++){
for (int j = 0; j < (1 << 17); j++){
int j2 = (j << 1) & ((1 << 17) - 1);
for (int k = 0; k < (i + 1) / 10; k++){
if ((j >> k & 1) == 0){
j2 |= 1;
}
}
dp[1][i][j] = j2;
}
}
for (int i = 2; i < 18; i++){
for (int j = 0; j < 163 - 9; j++){
for (int k = 0; k < 17; k++){
int p = j;
for (int l = 0; l < 10; l++){
p = dp[i - 1][j + l][p];
}
dp[i][j][k] = p;
}
}
}
int t;
cin >> t;
for (int i = 0; i < t; i++){
long long n;
cin >> n;
if (n % 10 != 0){
cout << "Algosia" << endl;
} else {
string s = to_string(n);
int L = s.size();
int dsum = 0, p = (1 << 17) - 2;
for (int j = L - 1; j >= 1; j--){
int d = s[L - 1 - j] - '0';
for (int k = 0; k < d; k++){
p = dp[j][dsum][p];
dsum++;
}
}
if ((p & 1) == 0){
cout << "Bajtek" << endl;
} else {
cout << "Algosia" << endl;
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
input:
4 1 10 42 190
output:
Algosia Bajtek Algosia Algosia