#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <unordered_set> #include <queue> using namespace std; string c; int main(){ int n = 0; int r[3]; string s[3]; unordered_set<string> wynik; queue<string> Q; cin >> n; for(int i = 0; i <3; ++i){ cin >> r[i]; cin >> s[i]; } for(int i = 0; i <3; ++i){ Q.push(s[i]); Q.push("LEVEL"); wynik.insert(s[i]); int step=0; while(!Q.empty()){ string tmp = Q.front(); Q.pop(); //cout << "step: " << step << "\n"; if(tmp == "LEVEL" && step < r[i]){ step++; Q.push("LEVEL"); continue; }else{ if(step < r[i]){ for(int k = 0; k < n; ++k){ string twin = tmp; if(tmp[k]=='0'){ twin[k]='1'; }else{ twin[k]='0'; } //cout << twin << "\n"; if(wynik.find(twin) == wynik.end()){ //cout << twin << "wlozono" << "\n"; wynik.insert(twin); Q.push(twin); } } } } } } cout << wynik.size() << "\n"; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <unordered_set> #include <queue> using namespace std; string c; int main(){ int n = 0; int r[3]; string s[3]; unordered_set<string> wynik; queue<string> Q; cin >> n; for(int i = 0; i <3; ++i){ cin >> r[i]; cin >> s[i]; } for(int i = 0; i <3; ++i){ Q.push(s[i]); Q.push("LEVEL"); wynik.insert(s[i]); int step=0; while(!Q.empty()){ string tmp = Q.front(); Q.pop(); //cout << "step: " << step << "\n"; if(tmp == "LEVEL" && step < r[i]){ step++; Q.push("LEVEL"); continue; }else{ if(step < r[i]){ for(int k = 0; k < n; ++k){ string twin = tmp; if(tmp[k]=='0'){ twin[k]='1'; }else{ twin[k]='0'; } //cout << twin << "\n"; if(wynik.find(twin) == wynik.end()){ //cout << twin << "wlozono" << "\n"; wynik.insert(twin); Q.push(twin); } } } } } } cout << wynik.size() << "\n"; return 0; } |