이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "vision.h"
#include <bits/stdc++.h>
using namespace std;
int h, w, k;
void construct_network(int H, int W, int K) {
h = H; w = W; k = K;
if (k == h + w - 2) {
add_or({add_and({0, h * w - 1}), add_and({w - 1, (h - 1) * w})});
return;
}
map<int, vector<int> > diag1, diag2;
map<int, int> rep1, rep2;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
diag1[i - j].push_back(i * w + j);
diag2[i + j].push_back(i * w + j);
}
}
for (auto &p : diag1) rep1[p.first] = add_or(p.second);
for (auto &p : diag2) rep2[p.first] = add_or(p.second);
vector<int> vx(h + w - 1), vy(h + w - 1);
map<int, vector<int> > diag_grp1, diag_grp2;
map<int, map<int, pair<int, int> > > mp1, mp2;
for (int d = h + w - 2; d >= k; d--) {
bool multiple = false;
for (int dd = 2 * d; dd <= h + w - 2; dd += d) {
multiple = true;
vector<int> v1, v2;
for (auto &p : rep1) {
if (p.first >= rep1.begin()->first + d) break;
vector<int> tmp_or, tmp_xor;
for (int i = p.first; ; i += d) {
if (i >= rep1.begin()->first + dd) break;
tmp_or.push_back(mp1[dd][i].first);
tmp_xor.push_back(mp1[dd][i].second);
}
pair<int, int> added;
if ((int) tmp_or.size() > 1) added = {add_or(tmp_or), add_xor(tmp_xor)};
else added = {p.second, p.second};
mp1[d][p.first] = added;
v1.push_back(add_xor({added.first, added.second}));
}
for (auto &p : rep2) {
if (p.first >= rep2.begin()->first + d) break;
vector<int> tmp_or, tmp_xor;
for (int i = p.first; ; i += d) {
if (i >= rep2.begin()->first + dd) break;
tmp_or.push_back(mp2[dd][i].first);
tmp_xor.push_back(mp2[dd][i].second);
}
pair<int, int> added;
if ((int) tmp_or.size() > 1) added = {add_or(tmp_or), add_xor(tmp_xor)};
else added = {p.second, p.second};
mp2[d][p.first] = added;
v2.push_back(add_xor({added.first, added.second}));
}
vx[d] = add_or(v1);
vy[d] = add_or(v2);
}
if (multiple) continue;
vector<int> v1, v2;
for (auto &p : rep1) {
if (p.first >= rep1.begin()->first + d) break;
vector<int> tmp;
for (int i = p.first; ; i += d) {
if (!rep1.count(i)) break;
tmp.push_back(rep1[i]);
}
pair<int, int> added;
if ((int) tmp.size() > 1) added = make_pair(add_or(tmp), add_xor(tmp));
else added = make_pair(p.second, p.second);
mp1[d][p.first] = added;
v1.push_back(add_xor({added.first, added.second}));
}
for (auto &p : rep2) {
if (p.first >= rep2.begin()->first + d) break;
vector<int> tmp;
for (int i = p.first; ; i += d) {
if (!rep2.count(i)) break;
tmp.push_back(rep2[i]);
}
pair<int, int> added;
if ((int) tmp.size() > 1) added = make_pair(add_or(tmp), add_xor(tmp));
else added = make_pair(p.second, p.second);
mp2[d][p.first] = added;
v2.push_back(add_xor({added.first, added.second}));
}
vx[d] = add_or(v1);
vy[d] = add_or(v2);
}
vector<int> tmp;
for (int d = h + w - 2; d > k; d--) {
tmp.push_back(vx[d]);
tmp.push_back(vy[d]);
}
int a = add_or(tmp);
tmp.push_back(vx[k]); tmp.push_back(vy[k]);
int b = add_or(tmp);
add_xor({a, b});
}
# | 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... |