Untitled
unknown
c_cpp
2 years ago
786 B
5
Indexable
void dfs(int i, int a, int b, int n, string& s, vector<vector<int>>& ans){ if(i == s.size()){ if(a + b == n) ans.push_back({a, b}); return; } if(s[i] == '0'){ dfs(i + 1, a, b, n, s, ans); dfs(i + 1, a + (1 << (31 - i)), b + (1 << (31 - i)), n, s, ans); } else{ dfs(i + 1, a, b + (1 << (31 - i)), n, s, ans); dfs(i + 1, a + (1 << (31 - i)), b, n, s, ans); } } vector<vector<int>> solve(int n){ if(n%2 == 1){ return {{-1, -1}}; } vector<vector<int>> ans; vector<vector<int>> temp; n = n/2; string s = bitset<32>(n).to_string(); string s2 = bitset<32>(100).to_string(); string s3 = bitset<32>(44).to_string(); int i = 0; while(i < 32){ if(s[i] == '1') break; i++; } dfs(i, 0, 0, 2*n, s, ans); if(ans.size() == 0) return {{-1, -1}}; return ans; }
Editor is loading...
Leave a Comment