QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#225613 | #5176. 多控制反转 | hos_lyric# | 0 | 1ms | 4108kb | C++14 | 4.1kb | 2023-10-24 21:01:38 | 2024-07-04 02:21:29 |
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
struct Op {
int t, x, y, z;
friend ostream &operator<<(ostream &os, const Op &op) {
return os << "(" << op.t << "; " << op.x << "," << op.y << "," << op.z << ")";
}
};
int N, M, Q, C;
vector<Op> ops;
void oper(int x) {
assert(0 <= x); assert(x < M);
ops.push_back(Op{1, x, -1, -1});
}
void oper(int x, int y) {
assert(0 <= x); assert(x < M);
assert(0 <= y); assert(y < M);
assert(x != y);
ops.push_back(Op{2, x, y, -1});
}
void oper(int x, int y, int z) {
assert(0 <= x); assert(x < M);
assert(0 <= y); assert(y < M);
assert(0 <= z); assert(z < M);
assert(x != y); assert(x != z); assert(y != z);
ops.push_back(Op{3, x, y, z});
}
void judge() {
for (int p = 0; p < 1 << M; ++p) {
int q = p, r = p;
if (!(~q & ((1 << N) - 1))) q ^= 1 << N;
for (const auto &op : ops) {
switch (op.t) {
case 1: r ^= 1 << op.x; break;
case 2: if (r >> op.x & 1) r ^= 1 << op.y; break;
case 3: if ((r >> op.x & 1) && (r >> op.y & 1)) r ^= 1 << op.z; break;
default: assert(false);
}
}
if (q != r) {
cerr << "FAIL" << endl;
r = p;
for (const auto &op : ops) {
for (int i = 0; i < M; ++i) cerr << (r >> i & 1);
cerr << " " << op << endl;
switch (op.t) {
case 1: r ^= 1 << op.x; break;
case 2: if (r >> op.x & 1) r ^= 1 << op.y; break;
case 3: if ((r >> op.x & 1) && (r >> op.y & 1)) r ^= 1 << op.z; break;
default: assert(false);
}
}
for (int i = 0; i < M; ++i) cerr << (r >> i & 1);
cerr << endl;
}
assert(q == r);
}
}
int V;
map<pair<int, int>, int> cache;
void solve(int l, int r, int tar) {
if (r - l == 0) {
oper(tar);
} else if (r - l == 1) {
oper(l, tar);
} else if (r - l == 2) {
oper(l, l + 1, tar);
} else {
const int mid = (l + r) / 2;
int vL, vR;
auto it = cache.find(make_pair(l, r));
if (it != cache.end()) {
vL = it->second;
vR = vL + 1;
} else {
vL = V++;
vR = V++;
cache[make_pair(l, r)] = vL;
}
oper(vL, vR, tar); solve(l, mid, vL);
oper(vL, vR, tar); solve(mid, r, vR);
oper(vL, vR, tar); solve(l, mid, vL);
oper(vL, vR, tar); solve(mid, r, vR);
}
}
int main() {
for (; ~scanf("%d%d%d%d", &N, &M, &Q, &C); ) {
ops.clear();
V = N + 1;
vector<int> us(N);
for (int u = 0; u < N; ++u) {
us[u] = u;
}
solve(0, N, N);
printf("%d\n", (int)ops.size());
for (const auto &op : ops) {
switch (op.t) {
case 1: printf("1 %d\n", op.x); break;
case 2: printf("2 %d %d\n", op.x, op.y); break;
case 3: printf("3 %d %d %d\n", op.x, op.y, op.z); break;
default: assert(false);
}
}
#ifdef LOCAL
judge();
#endif
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 15
Accepted
time: 0ms
memory: 4096kb
input:
0 2 1 1
output:
1 1 0
result:
ok OK.
Test #2:
score: -15
Wrong Answer
time: 1ms
memory: 3820kb
input:
13 28 105 1
output:
148 3 14 15 13 3 16 17 14 3 18 19 16 2 0 18 3 18 19 16 3 1 2 19 3 18 19 16 2 0 18 3 18 19 16 3 1 2 19 3 16 17 14 3 20 21 17 2 3 20 3 20 21 17 3 4 5 21 3 20 21 17 2 3 20 3 20 21 17 3 4 5 21 3 16 17 14 3 18 19 16 2 0 18 3 18 19 16 3 1 2 19 3 18 19 16 2 0 18 3 18 19 16 3 1 2 19 3 16 17 14 3 20 21 17 2 ...
result:
wrong answer Integer 148 violates the range [0, 105]
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Runtime Error
Test #13:
score: 10
Accepted
time: 1ms
memory: 4108kb
input:
0 2 1 4
output:
1 1 0
result:
ok OK.
Test #14:
score: -10
Runtime Error
input:
18 20 325 4
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Runtime Error
Test #20:
score: 0
Runtime Error
input:
14 16 393 6
output:
result:
Subtask #7:
score: 0
Skipped
Dependency #2:
0%
Subtask #8:
score: 0
Skipped
Dependency #3:
0%