Solve nezzar-and-lucky-number
This commit is contained in:
@@ -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 NL '\n'
|
||||
#define CM ", "
|
||||
#define SP " "
|
||||
|
||||
// ----- FOR LOOPS -----
|
||||
#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 pb push_back
|
||||
|
||||
|
||||
int main() {
|
||||
STDIO("nezzar-and-lucky-number");
|
||||
takeI(n);
|
||||
DBG(n);
|
||||
FASTIO;
|
||||
takeI(t);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user