Submission #555018

# Submission time Handle Problem Language Result Execution time Memory
555018 2022-04-30T00:38:24 Z slime Vision Program (IOI19_vision) C++14
0 / 100
29 ms 3528 KB
#include <bits/stdc++.h>

#include "vision.h"
#include <map>

void construct_network(int H, int W, int K) {
	std::vector<int> Ns;
  std::vector<int> by_sum, by_diff;
  std::map<int, std::vector<int> > mp_sum, mp_diff;
  for(int i=0; i<H; i++) {
    for(int j=0; j<W; j++) {
      mp_sum[i + j].push_back(i*W + j);
      mp_diff[i - j].push_back(i*W + j);
    }
  }
  std::vector<int> analyze; // Necessary conditions, i.e. AND clause
  for(auto x: mp_sum) {
    by_sum.push_back(add_or(x.second));
  }
  for(auto x: mp_diff) {
    by_diff.push_back(add_or(x.second));
  }
  // Condition 1: at least one of these two arrays' 1s are exactly K cells apart
  std::vector<int> cond1;
  for(int i=0; i<by_sum.size(); i++) {
    if(i + K < by_sum.size()) {
      std::vector<int> uwu = {by_sum[i], by_sum[i + K]};
      cond1.push_back(add_and(uwu));
    }
  }
  for(int i=0; i<by_diff.size(); i++) {
    if(i + K < by_diff.size()) {
      std::vector<int> uwu = {by_diff[i], by_diff[i + K]};
      cond1.push_back(add_and(uwu));
    }
  }
  
  // Only one in cond1 array = 1 is necessary (but at least 1)!
  analyze.push_back(add_or(cond1));
  // condition 2: [1 + K 0s] + at least one 1 in the right should not appear in any of them
  std::vector<int> cond2;
  for(int i=0; i<by_sum.size(); i++) {
    if(i + 2 + K < by_sum.size()) {
      std::vector<int> patt; // does this subarray match the pattern?
      std::vector<int> uwu = {by_sum[i]};
      patt.push_back(add_and(uwu));
      uwu.clear();
      for(int j=i+1; j<i+1+K; j++) uwu.push_back(by_sum[j]);
      patt.push_back(add_not(add_or(uwu)));
      // Everything in patt = 1 iff by_sum[i] = 1 and all by_sum[i+1] to by_sum[i+K] = 0
      std::vector<int> all_nxt;
      for(int j=i+1+K; j<by_sum.size(); j++) all_nxt.push_back(by_sum[j]);
      patt.push_back(add_or(all_nxt));
      cond2.push_back(add_and(patt)); // = 1 if match pattern, = 0 otherwise
    }
  }
  for(int i=0; i<by_diff.size(); i++) {
    if(i + 2 + K < by_diff.size()) {
      std::vector<int> patt; // does this subarray match the pattern?
      std::vector<int> uwu = {by_diff[i]};
      patt.push_back(add_and(uwu));
      uwu.clear();
      for(int j=i+1; j<i+1+K; j++) uwu.push_back(by_diff[j]);
      patt.push_back(add_not(add_or(uwu)));
      // Everything in patt = 1 iff by_diff[i] = 1 and all by_diff[i+1] to by_diff[i+K] = 0
      std::vector<int> all_nxt;
      for(int j=i+1+K; j<by_diff.size(); j++) all_nxt.push_back(by_diff[j]);
      patt.push_back(add_or(all_nxt));
      cond2.push_back(add_and(patt)); // = 1 if match pattern, = 0 otherwise
    }
  }
  analyze.push_back(add_not(add_or(cond2))); // = 1 if all cond2 = 0, i.e. no pattern found
  add_and(analyze); // answer

}

Compilation message

vision.cpp: In function 'void construct_network(int, int, int)':
vision.cpp:25:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   for(int i=0; i<by_sum.size(); i++) {
      |                ~^~~~~~~~~~~~~~
vision.cpp:26:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     if(i + K < by_sum.size()) {
      |        ~~~~~~^~~~~~~~~~~~~~~
vision.cpp:31:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int i=0; i<by_diff.size(); i++) {
      |                ~^~~~~~~~~~~~~~~
vision.cpp:32:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     if(i + K < by_diff.size()) {
      |        ~~~~~~^~~~~~~~~~~~~~~~
vision.cpp:42:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for(int i=0; i<by_sum.size(); i++) {
      |                ~^~~~~~~~~~~~~~
vision.cpp:43:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     if(i + 2 + K < by_sum.size()) {
      |        ~~~~~~~~~~^~~~~~~~~~~~~~~
vision.cpp:52:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |       for(int j=i+1+K; j<by_sum.size(); j++) all_nxt.push_back(by_sum[j]);
      |                        ~^~~~~~~~~~~~~~
vision.cpp:57:17: 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<by_diff.size(); i++) {
      |                ~^~~~~~~~~~~~~~~
vision.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     if(i + 2 + K < by_diff.size()) {
      |        ~~~~~~~~~~^~~~~~~~~~~~~~~~
vision.cpp:67:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |       for(int j=i+1+K; j<by_diff.size(); j++) all_nxt.push_back(by_diff[j]);
      |                        ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB WA in grader: Instruction with no inputs
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB WA in grader: Instruction with no inputs
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB WA in grader: Instruction with no inputs
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB WA in grader: Instruction with no inputs
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 852 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Correct 4 ms 596 KB Output is correct
4 Incorrect 1 ms 340 KB WA in grader: Instruction with no inputs
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB WA in grader: Instruction with no inputs
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 3528 KB Output is correct
2 Incorrect 1 ms 212 KB WA in grader: Instruction with no inputs
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB WA in grader: Instruction with no inputs
2 Halted 0 ms 0 KB -