Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <bitset>
- using namespace std;
- #define all(v) v.begin(), v.end()
- int real_value(int byte, int number, int n) {
- if(byte == 1) {
- return number;
- } else {
- return n + number;
- }
- }
- int main() {
- int n; cin >> n;
- vector<vector<int>>x;
- for (int i = 0; i < (1 << n); i++) {
- string s; cin >> s; int val; cin >> val;
- if(val) {
- vector<int>cur;
- for (int j = 0; j < n; j++) {
- cur.push_back(s[j] - '0');
- }
- x.push_back(cur);
- }
- }
- if(x.empty()) {
- cout << n + 2 << endl;
- cout << "1 1" << endl;
- cout << "2 1 " << n + 1 << endl;
- return 0;
- }
- cout << 2 * n + (n - 1) * x.size() + x.size() - 1 << endl;
- for (int i = n; i < 2 * n; i++) {
- cout << "1 " << i - n + 1 << endl;
- }
- int cnt = 2 * n; /// -1
- vector<int>indexes;
- for (int i = 0; i < x.size(); i++) { // {101, 110, 111}
- for (int j = 1; j < x[i].size(); j++) { // {101}
- if(j == 1) {
- cout << "2 " << real_value(x[i][j - 1], j - 1, n) + 1 << " " << real_value(x[i][j], j, n) + 1 << endl;
- } else {
- cout << "2 " << cnt << " " << real_value(x[i][j], j, n) + 1 << endl;
- }
- cnt++;
- }
- indexes.push_back(cnt - 1);
- }
- for (int i = 1; i < indexes.size(); i++) {
- if(i == 1) {
- cout << "3 " << indexes[i - 1] + 1 << " " << indexes[i] + 1 << endl;
- } else {
- cout << "3 " << cnt << " " << indexes[i] + 1 << endl;
- }
- cnt++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement