This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#ifndef local
#include "vision.h"
#endif
using namespace std;
int k,H,W;
int get_id(int i,int j) {
return i*W+j;
}
void smallCase() {
vector<pii> s;
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
for (int a = i; a < H; a++)
for (int b = 0; b < W; b++) {
if (abs(i-a)+abs(j-b) == k) s.pb({get_id(i,j),get_id(a,b)});
}
int a = 0;
for (auto i : s) {
vector<int> v = {i.first,i.second};
a|=add_and(v);
}
int x = s.size();
vi v;
for (int i = H*W; i < H*W + x;i++)
v.pb(i);
if (v.size() == 0) {
add_and({0,1,2});
return;
}
add_or(v);
}
void SMALL() {
int cnt = 0;
for (int i = 0;i < H; i++)
for (int j = 0;j < W; j++) {
vector<int> s;
for (int a = 0; a < H; a++)
for (int b = 0; b < W; b++) {
if (abs(i-a)+abs(j-b) == k) s.pb(get_id(a,b));
}
if (s.size()) {
add_or(s);
cnt++;
}
else {
add_and({0,1,2});
cnt++;
}
}
int st = H*W;
int en = H*W*2;
for (int i = H*W;i < 2*H*W; i++) {
add_and({i,i - H*W});
en++;
}
vi v;
for (int i = H*W*2;i < H*W*3;i++)
v.pb(i);
add_or(v);
}
void construct_network(int H1, int W1, int k1) {
k = k1;
H = H1, W = W1;
vector<pii> s;
if (max(H,W) <= 10 || min(H,W) == 1) {
smallCase();
return;
}
if (max(H,W) <= 30) {
SMALL();
return;
}
vector<int> v;
int cnt = 0;
for (int i = 0; i < H;i++)
for (int j = 0;j < W; j++)
if (i + j == k) {
add_and({0,get_id(i,j)});
cnt++;
}
for (int i = H*W; i < H*W + cnt; i++)
v.pb(i);
add_or(v);
}
Compilation message (stderr)
vision.cpp: In function 'void SMALL()':
vision.cpp:54:6: warning: unused variable 'st' [-Wunused-variable]
int st = H*W;
^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |