ProgMe

Untitled

Jan 20th, 2021
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int int64_t
  3.  
  4. using namespace std;
  5. vector<vector<string>> s;
  6.  
  7. int32_t main() {
  8. int n, k;
  9. cin >> n >> k;
  10. s.resize(n + 1);
  11. bool dp[1<<k][n + 1];
  12. for(int i = 0; i <= (1<<k) - 1; i++)
  13. for(int j = 1; j <= n; j++)
  14. dp[i][j] = true;
  15. for(int i = 1; i <= n; i++){
  16. string cur;
  17. cin >> cur;
  18. s[i].push_back(cur);
  19. if(cur == "begin" || cur == "end")
  20. continue;
  21. if(cur != "not"){
  22. cin >> cur;
  23. s[i].push_back(cur);
  24. }
  25. cin >> cur;
  26. s[i].push_back(cur);
  27. }
  28. for(int j = n - 1; j >= 1; j--){
  29. for(int i = 0; i <= (1<<k) - 1; i++){
  30. if(s[j].front() == "jump") {
  31. if(j < stoi(s[j][2]))
  32. dp[i][j] = dp[i][stoi(s[j][2])];
  33. else {
  34. if (i >> stoi(s[j][1]) & 1)
  35. dp[i][j] = false;
  36. }
  37. continue;
  38. }
  39. int cur = i;
  40. if(s[j].front() == "and"){
  41. if((i>>stoi(s[j][1]) & 1) && (i>>stoi(s[j][2]) & 1))
  42. cur|= 1<<stoi(s[j][1]);
  43. else
  44. cur &= ~(1<<stoi(s[j][1]));
  45. }
  46. if(s[j].front() == "or"){
  47. if((i>>stoi(s[j][1]) & 1) || (i>>stoi(s[j][2]) & 1))
  48. cur|= 1<<stoi(s[j][1]);
  49. else
  50. cur &= ~(1<<stoi(s[j][1]));
  51. }
  52. if(s[j].front() == "xor"){
  53. if((i>>stoi(s[j][1]) & 1) ^ (i>>stoi(s[j][2]) & 1))
  54. cur|= 1<<stoi(s[j][1]);
  55. else
  56. cur &= ~(1<<stoi(s[j][1]));
  57. }
  58. if(s[j].front() == "not")
  59. cur ^= 1<<stoi(s[j][1]);
  60. if(s[j].front() == "move"){
  61. cout << s[j][2] << '\n';
  62. if(i>>stoi(s[j][2]) & 1)
  63. cur |= 1<<stoi(s[j][1]);
  64. else
  65. cur &= ~(1<<stoi(s[j][1]));
  66. }
  67. if(s[j].front() == "set"){
  68. if(stoi(s[j][2]))
  69. cur |= 1<<stoi(s[j][1]);
  70. else
  71. cur &= ~(1<<stoi(s[j][1]));
  72. }
  73. dp[i][j] = dp[cur][j + 1];
  74. }
  75. }
  76. for(int i = 0; i < 1<<k; i++) {
  77. for (int j = 1; j <= n; j++)
  78. cout << dp[i][j] << ' ';
  79. cout << '\n';
  80. }
  81. for(int i = 0; i <= (1<<k) - 1; i++){
  82. if(!dp[i][1]){
  83. cout << "No\n";
  84. vector<int> ans;
  85. int pw = 1<<(k - 1), cur = i;
  86. while(pw > 0){
  87. if(cur >= pw) {
  88. ans.push_back(1);
  89. cur -= pw;
  90. }
  91. else
  92. ans.push_back(0);
  93. pw >>= 1;
  94. }
  95. reverse(ans.begin(), ans.end());
  96. for(auto j: ans)
  97. cout << j;
  98. return 0;
  99. }
  100. }
  101. cout << "Yes\n";
  102. }
Advertisement
Add Comment
Please, Sign In to add comment