Submission #761530

# Submission time Handle Problem Language Result Execution time Memory
761530 2023-06-19T22:24:39 Z radoslav11 Vision Program (IOI19_vision) C++17
0 / 100
8 ms 1260 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include "vision.h"
// #include "grader.cpp"

using namespace std;

vector<int> only_first_set(vector<int> nums) {
    vector<int> ans, pref;
    pref.push_back(nums[0]);
    ans.push_back(nums[0]);
    for(int i = 1; i < (int)nums.size(); i++) {
        pref.push_back(add_or({pref.back(), nums[i]}));
        ans.push_back(add_and({add_not(pref[i - 1]), nums[i]}));
    }

    return ans;
}

vector<int> to_binary(vector<int> unary) {
    vector<int> ans;
    for(int i = 0; ; i++) {
        vector<int> Ns;
        for(int j = 0; j < (int)unary.size(); j++) {
            if((j >> i) & 1) {
                Ns.push_back(unary[j]);
            }
        }

        if(Ns.empty()) {
            break;
        }

        ans.push_back(add_or(Ns));
    }

    return ans;
}

vector<int> binary_add(vector<int> a, vector<int> b) {
	if(a.empty()) {
		return b;
	}

	if(b.empty()) {
		return a;
	}

	cout << "binary_add" << endl;
	cout << "a: ";
	for (int i = 0; i < a.size(); i++) {
		cout << a[i] << " ";
	}
	cout << endl;
	cout << "b: ";
	for (int i = 0; i < b.size(); i++) {
		cout << b[i] << " ";
	}
	cout << endl;

    vector<int> ans;
    int carry = -1;
    for(int i = 0; i < (int)a.size() || i < (int)b.size(); i++) {
        vector<int> Ns;
        if(i < (int)a.size()) {
            Ns.push_back(a[i]);
        }
        if(i < (int)b.size()) {
            Ns.push_back(b[i]);
        }
        if(carry != -1) {
            Ns.push_back(carry);
        }

        ans.push_back(add_xor(Ns));

        // 2 set for carry
        vector<int> Ns2;
        for(int p1 = 0; p1 < (int)Ns.size(); p1++) {
            for(int p2 = p1 + 1; p2 < (int)Ns.size(); p2++) {
                Ns2.push_back(add_and({Ns[p1], Ns[p2]}));
            }
        }

        carry = add_or(Ns2);
    }

    ans.push_back(carry);
    return ans;
}

void construct_network(int H, int W, int K) {
    K = H + W - K - 2;

    vector<int> nums_unary[4];
    for(int i = 0; i < H; i++) {
        vector<int> Ns;
        for(int j = 0; j < W; j++) {
            Ns.push_back(i * W + j);
        }

        nums_unary[0].push_back(add_or(Ns));
    }
    nums_unary[1] = nums_unary[0];
    reverse(nums_unary[1].begin(), nums_unary[1].end());

    for(int j = 0; j < W; j++) {
        vector<int> Ns;
        for(int i = 0; i < H; i++) {
            Ns.push_back(i * W + j);
        }

        nums_unary[2].push_back(add_or(Ns));
    }
    nums_unary[3] = nums_unary[2];
    reverse(nums_unary[3].begin(), nums_unary[3].end());

    for(int i = 0; i < 4; i++) {
        nums_unary[i] = only_first_set(nums_unary[i]);
        nums_unary[i] = to_binary(nums_unary[i]);
    }

    vector<int> ans = nums_unary[0];
    for(int i = 1; i < 4; i++) {
        ans = binary_add(ans, nums_unary[i]);
    }	

    vector<int> Ns_check;
    for(int i = 0; i < (int)ans.size(); i++) {
        if((K >> i) & 1) {
            Ns_check.push_back(ans[i]);
        } else {
            Ns_check.push_back(add_not(ans[i]));
        }
    }

    add_and(Ns_check);
}

Compilation message

vision.cpp: In function 'std::vector<int> binary_add(std::vector<int>, std::vector<int>)':
vision.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for (int i = 0; i < a.size(); i++) {
      |                  ~~^~~~~~~~~~
vision.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for (int i = 0; i < b.size(); i++) {
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB secret mismatch
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB secret mismatch
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB secret mismatch
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB secret mismatch
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB secret mismatch
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB secret mismatch
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 1260 KB secret mismatch
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB secret mismatch
2 Halted 0 ms 0 KB -