fork download
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3. using ll = long long;
  4.  
  5. #ifdef JASPER
  6. #include "debug.h"
  7. #else
  8. #define debug(...) 166
  9. #endif
  10.  
  11. const int N = 3e5 + 10;
  12. ll v[N], c[N];
  13.  
  14. string solve() {
  15. ll a, b, n;
  16.  
  17. string s;
  18. cin >> n >> a >> b >> s;
  19.  
  20. ll on = 0, off = 0;
  21.  
  22. for (auto x : s) {
  23. if (x == '0') off++; else
  24. on++;
  25. }
  26.  
  27. vector <bool> dp(101, 0);
  28.  
  29. dp[off] = 1;
  30.  
  31. queue <int> q;
  32. q.push(off);
  33.  
  34. while (q.size()) {
  35. int t = q.front();
  36. q.pop();
  37. for (int i = a; i <= b; i++) {
  38. for (int j = 0; j <= i; j++) {
  39. if (j <= t && i - j <= n - t) {
  40. int nx = t - j + (i - j);
  41. if (dp[nx])
  42. continue;
  43. dp[nx] = 1;
  44. q.push(nx);
  45. }
  46. }
  47. }
  48. }
  49.  
  50. for (int i = a; i <= b; i++)
  51. if (dp[i])
  52. return "YES";
  53.  
  54. return "NO";
  55. }
  56.  
  57. signed main(){
  58. ios_base::sync_with_stdio(false);
  59. cin.tie(NULL);
  60. cout.tie(NULL);
  61.  
  62. int t = 1;
  63. cin >> t;
  64.  
  65.  
  66. while (t--) {
  67. //solve();
  68. cout << solve() << "\n";
  69. }
  70. }
  71.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
NO