Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int int64_t
- using namespace std;
- vector<vector<string>> s;
- int32_t main() {
- int n, k;
- cin >> n >> k;
- s.resize(n + 1);
- bool dp[1<<k][n + 1];
- for(int i = 0; i <= (1<<k) - 1; i++)
- for(int j = 1; j <= n; j++)
- dp[i][j] = true;
- for(int i = 1; i <= n; i++){
- string cur;
- cin >> cur;
- s[i].push_back(cur);
- if(cur == "begin" || cur == "end")
- continue;
- if(cur != "not"){
- cin >> cur;
- s[i].push_back(cur);
- }
- cin >> cur;
- s[i].push_back(cur);
- }
- for(int j = n - 1; j >= 1; j--){
- for(int i = 0; i <= (1<<k) - 1; i++){
- if(s[j].front() == "jump") {
- if(j < stoi(s[j][2]))
- dp[i][j] = dp[i][stoi(s[j][2])];
- else {
- if (i >> stoi(s[j][1]) & 1)
- dp[i][j] = false;
- }
- continue;
- }
- int cur = i;
- if(s[j].front() == "and"){
- if((i>>stoi(s[j][1]) & 1) && (i>>stoi(s[j][2]) & 1))
- cur|= 1<<stoi(s[j][1]);
- else
- cur &= ~(1<<stoi(s[j][1]));
- }
- if(s[j].front() == "or"){
- if((i>>stoi(s[j][1]) & 1) || (i>>stoi(s[j][2]) & 1))
- cur|= 1<<stoi(s[j][1]);
- else
- cur &= ~(1<<stoi(s[j][1]));
- }
- if(s[j].front() == "xor"){
- if((i>>stoi(s[j][1]) & 1) ^ (i>>stoi(s[j][2]) & 1))
- cur|= 1<<stoi(s[j][1]);
- else
- cur &= ~(1<<stoi(s[j][1]));
- }
- if(s[j].front() == "not")
- cur ^= 1<<stoi(s[j][1]);
- if(s[j].front() == "move"){
- cout << s[j][2] << '\n';
- if(i>>stoi(s[j][2]) & 1)
- cur |= 1<<stoi(s[j][1]);
- else
- cur &= ~(1<<stoi(s[j][1]));
- }
- if(s[j].front() == "set"){
- if(stoi(s[j][2]))
- cur |= 1<<stoi(s[j][1]);
- else
- cur &= ~(1<<stoi(s[j][1]));
- }
- dp[i][j] = dp[cur][j + 1];
- }
- }
- for(int i = 0; i < 1<<k; i++) {
- for (int j = 1; j <= n; j++)
- cout << dp[i][j] << ' ';
- cout << '\n';
- }
- for(int i = 0; i <= (1<<k) - 1; i++){
- if(!dp[i][1]){
- cout << "No\n";
- vector<int> ans;
- int pw = 1<<(k - 1), cur = i;
- while(pw > 0){
- if(cur >= pw) {
- ans.push_back(1);
- cur -= pw;
- }
- else
- ans.push_back(0);
- pw >>= 1;
- }
- reverse(ans.begin(), ans.end());
- for(auto j: ans)
- cout << j;
- return 0;
- }
- }
- cout << "Yes\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment