Submission #678492

# Submission time Handle Problem Language Result Execution time Memory
678492 2023-01-06T04:46:15 Z cig32 Vision Program (IOI19_vision) C++17
100 / 100
43 ms 3600 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
    }
  }
  if(cond2.size()) 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:24:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   for(int i=0; i<by_sum.size(); i++) {
      |                ~^~~~~~~~~~~~~~
vision.cpp:25:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     if(i + K < by_sum.size()) {
      |        ~~~~~~^~~~~~~~~~~~~~~
vision.cpp:30:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   for(int i=0; i<by_diff.size(); i++) {
      |                ~^~~~~~~~~~~~~~~
vision.cpp:31:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     if(i + K < by_diff.size()) {
      |        ~~~~~~^~~~~~~~~~~~~~~~
vision.cpp:41:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for(int i=0; i<by_sum.size(); i++) {
      |                ~^~~~~~~~~~~~~~
vision.cpp:42:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     if(i + 2 + K < by_sum.size()) {
      |        ~~~~~~~~~~^~~~~~~~~~~~~~~
vision.cpp:51:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |       for(int j=i+1+K; j<by_sum.size(); j++) all_nxt.push_back(by_sum[j]);
      |                        ~^~~~~~~~~~~~~~
vision.cpp:56:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for(int i=0; i<by_diff.size(); i++) {
      |                ~^~~~~~~~~~~~~~~
vision.cpp:57:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     if(i + 2 + K < by_diff.size()) {
      |        ~~~~~~~~~~^~~~~~~~~~~~~~~~
vision.cpp:66:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |       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 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 296 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 296 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 304 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 296 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 304 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 8 ms 1108 KB Output is correct
39 Correct 4 ms 468 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 8 ms 724 KB Output is correct
42 Correct 3 ms 468 KB Output is correct
43 Correct 11 ms 1136 KB Output is correct
44 Correct 12 ms 1108 KB Output is correct
45 Correct 7 ms 920 KB Output is correct
46 Correct 6 ms 808 KB Output is correct
47 Correct 4 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 832 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Correct 4 ms 680 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 4 ms 688 KB Output is correct
7 Correct 3 ms 556 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 6 ms 808 KB Output is correct
10 Correct 7 ms 812 KB Output is correct
11 Correct 4 ms 684 KB Output is correct
12 Correct 4 ms 596 KB Output is correct
13 Correct 2 ms 556 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 8 ms 900 KB Output is correct
16 Correct 8 ms 852 KB Output is correct
17 Correct 4 ms 596 KB Output is correct
18 Correct 6 ms 596 KB Output is correct
19 Correct 3 ms 468 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 296 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 684 KB Output is correct
4 Correct 4 ms 556 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 2 ms 432 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 6 ms 940 KB Output is correct
9 Correct 7 ms 852 KB Output is correct
10 Correct 5 ms 812 KB Output is correct
11 Correct 4 ms 596 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 7 ms 852 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 6 ms 852 KB Output is correct
18 Correct 4 ms 684 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 17 ms 2068 KB Output is correct
21 Correct 16 ms 1940 KB Output is correct
22 Correct 16 ms 1456 KB Output is correct
23 Correct 6 ms 980 KB Output is correct
24 Correct 16 ms 2116 KB Output is correct
25 Correct 21 ms 1736 KB Output is correct
26 Correct 7 ms 980 KB Output is correct
27 Correct 28 ms 3548 KB Output is correct
28 Correct 34 ms 3320 KB Output is correct
29 Correct 27 ms 2964 KB Output is correct
30 Correct 18 ms 2380 KB Output is correct
31 Correct 15 ms 1616 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 3584 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 596 KB Output is correct
4 Correct 7 ms 980 KB Output is correct
5 Correct 7 ms 852 KB Output is correct
6 Correct 5 ms 852 KB Output is correct
7 Correct 20 ms 2084 KB Output is correct
8 Correct 16 ms 2132 KB Output is correct
9 Correct 28 ms 3544 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 296 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 304 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 8 ms 1108 KB Output is correct
39 Correct 4 ms 468 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 8 ms 724 KB Output is correct
42 Correct 3 ms 468 KB Output is correct
43 Correct 11 ms 1136 KB Output is correct
44 Correct 12 ms 1108 KB Output is correct
45 Correct 7 ms 920 KB Output is correct
46 Correct 6 ms 808 KB Output is correct
47 Correct 4 ms 596 KB Output is correct
48 Correct 5 ms 832 KB Output is correct
49 Correct 4 ms 596 KB Output is correct
50 Correct 4 ms 680 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 5 ms 852 KB Output is correct
53 Correct 4 ms 688 KB Output is correct
54 Correct 3 ms 556 KB Output is correct
55 Correct 2 ms 340 KB Output is correct
56 Correct 6 ms 808 KB Output is correct
57 Correct 7 ms 812 KB Output is correct
58 Correct 4 ms 684 KB Output is correct
59 Correct 4 ms 596 KB Output is correct
60 Correct 2 ms 556 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 8 ms 900 KB Output is correct
63 Correct 8 ms 852 KB Output is correct
64 Correct 4 ms 596 KB Output is correct
65 Correct 6 ms 596 KB Output is correct
66 Correct 3 ms 468 KB Output is correct
67 Correct 1 ms 300 KB Output is correct
68 Correct 1 ms 296 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 4 ms 684 KB Output is correct
73 Correct 4 ms 556 KB Output is correct
74 Correct 3 ms 468 KB Output is correct
75 Correct 2 ms 432 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 6 ms 940 KB Output is correct
78 Correct 7 ms 852 KB Output is correct
79 Correct 5 ms 812 KB Output is correct
80 Correct 4 ms 596 KB Output is correct
81 Correct 2 ms 468 KB Output is correct
82 Correct 7 ms 852 KB Output is correct
83 Correct 7 ms 852 KB Output is correct
84 Correct 3 ms 596 KB Output is correct
85 Correct 1 ms 340 KB Output is correct
86 Correct 6 ms 852 KB Output is correct
87 Correct 4 ms 684 KB Output is correct
88 Correct 1 ms 304 KB Output is correct
89 Correct 17 ms 2068 KB Output is correct
90 Correct 16 ms 1940 KB Output is correct
91 Correct 16 ms 1456 KB Output is correct
92 Correct 6 ms 980 KB Output is correct
93 Correct 16 ms 2116 KB Output is correct
94 Correct 21 ms 1736 KB Output is correct
95 Correct 7 ms 980 KB Output is correct
96 Correct 28 ms 3548 KB Output is correct
97 Correct 34 ms 3320 KB Output is correct
98 Correct 27 ms 2964 KB Output is correct
99 Correct 18 ms 2380 KB Output is correct
100 Correct 15 ms 1616 KB Output is correct
101 Correct 1 ms 212 KB Output is correct
102 Correct 1 ms 212 KB Output is correct
103 Correct 34 ms 3584 KB Output is correct
104 Correct 1 ms 212 KB Output is correct
105 Correct 4 ms 596 KB Output is correct
106 Correct 7 ms 980 KB Output is correct
107 Correct 7 ms 852 KB Output is correct
108 Correct 5 ms 852 KB Output is correct
109 Correct 20 ms 2084 KB Output is correct
110 Correct 16 ms 2132 KB Output is correct
111 Correct 28 ms 3544 KB Output is correct
112 Correct 0 ms 212 KB Output is correct
113 Correct 1 ms 328 KB Output is correct
114 Correct 26 ms 3304 KB Output is correct
115 Correct 1 ms 340 KB Output is correct
116 Correct 6 ms 852 KB Output is correct
117 Correct 12 ms 1204 KB Output is correct
118 Correct 16 ms 2004 KB Output is correct
119 Correct 33 ms 2992 KB Output is correct
120 Correct 24 ms 2892 KB Output is correct
121 Correct 32 ms 3016 KB Output is correct
122 Correct 33 ms 2892 KB Output is correct
123 Correct 32 ms 3600 KB Output is correct
124 Correct 43 ms 3352 KB Output is correct
125 Correct 25 ms 2904 KB Output is correct
126 Correct 39 ms 2892 KB Output is correct
127 Correct 21 ms 2348 KB Output is correct
128 Correct 12 ms 1572 KB Output is correct