Solve nezzar-and-lucky-number

This commit is contained in:
2026-09-24 17:06:59 +01:00
parent 25ba615045
commit fe0b8be533
2 changed files with 34 additions and 3 deletions
@@ -14,6 +14,7 @@ typedef vector<int> vi;
#define STDIO(filename) FASTIO; string filenamee(filename); STDIN((filenamee + ".in").c_str()); STDOUT((filenamee + ".out").c_str()) #define STDIO(filename) FASTIO; string filenamee(filename); STDIN((filenamee + ".in").c_str()); STDOUT((filenamee + ".out").c_str())
#define NL '\n' #define NL '\n'
#define CM ", " #define CM ", "
#define SP " "
// ----- FOR LOOPS ----- // ----- FOR LOOPS -----
#define F(i,L,R) for (int i = L; i < R; i++) #define F(i,L,R) for (int i = L; i < R; i++)
@@ -56,8 +57,38 @@ typedef vector<int> vi;
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end()) #define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
#define pb push_back #define pb push_back
int main() { int main() {
STDIO("nezzar-and-lucky-number"); FASTIO;
takeI(n); takeI(t);
DBG(n); while (t--) {
takeII(n, d);
takeV(a, n);
bool dp[100];
memset(dp, false, sizeof(dp));
dp[d] = true;
dp[10*d] = true;
for (int i = 0; i < 10; i++) {
dp[10*i + d] = true;
}
for (int i = 0; i < 100; i++) {
for (int j = i; j < 100; j++) {
if (dp[i] && dp[j-i]) dp[j] = true;
}
}
for (auto x : a) {
int res = true;
int r = x % d;
// If x % d == 0 then x = d + d + d .. + d k times
if (r == 0) goto fin;
// Use 10*d + r, then x + (10* d + r) % d = r - r = 0
if (x >= 10*d + r) goto fin;
res = dp[x];
fin:
YESNO(res);
}
}
} }