QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#225666 | #5176. 多控制反转 | hos_lyric# | 0 | 1ms | 3812kb | C++14 | 5.1kb | 2023-10-24 22:36:40 | 2024-07-04 02:21:30 |
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(int t) {
for (int p = 0; p < 1 << (t ? M : (N + 1)); ++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: r ^= (r >> op.x & 1) << op.y; break;
case 3: r ^= (r >> op.x & r >> op.y & 1) << op.z; break;
default: assert(false);
}
}
for (int i = 0; i < M; ++i) cerr << (r >> i & 1);
cerr << endl;
}
assert(q == r);
}
}
void solve(const vector<int> &us, int tar) {
const int usLen = us.size();
if (usLen == 0) {
oper(tar);
} else if (usLen == 1) {
oper(us[0], tar);
} else if (usLen == 2) {
oper(us[0], us[1], tar);
} else if (usLen == 4) {
// ?
__int128 used = 0;
for (const int u : us) used |= (__int128)1 << u;
used |= (__int128)1 << tar;
int lot = N + 1;
for (; used >> lot & 1; --lot) {}
oper(us[2], us[3], tar);
oper(us[0], us[1], us[3]);
oper(us[3], lot, tar);
oper(us[0], us[1], us[3]);
oper(us[2], us[3], lot);
oper(us[0], us[1], us[3]);
oper(us[3], lot, tar);
oper(us[0], us[1], us[3]);
oper(us[2], us[3], lot);
} else {
__int128 used = 0;
for (const int u : us) used |= (__int128)1 << u;
used |= (__int128)1 << tar;
int lot = N + 1;
for (; used >> lot & 1; --lot) {}
const int half = (usLen + 1) / 2;
vector<int> vs0, vs1;
for (int i = 0; i < half; ++i) vs0.push_back(us[i]);
for (int i = half; i < usLen; ++i) vs1.push_back(us[i]);
vs1.push_back(lot);
solve(vs0, lot);
solve(vs1, tar);
solve(vs0, lot);
solve(vs1, tar);
}
}
int main() {
for (; ~scanf("%d%d%d%d", &N, &M, &Q, &C); ) {
ops.clear();
if (Q == 1 || Q == 2) {
if (N == 0) {
oper(0);
} else if (N == 1) {
oper(0, 1);
} else if (N == 2) {
oper(0, 1, 2);
} else {
oper(0, 1, N + 1);
for (int i = 2; i < N - 1; ++i) oper(N + i - 1, i, N + i);
oper(N + N - 2, N - 1, N);
for (int i = N - 1; --i >= 2; ) oper(N + i - 1, i, N + i);
oper(0, 1, N + 1);
}
} else {
vector<int> us(N);
for (int u = 0; u < N; ++u) us[u] = u;
solve(us, 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(1);
#endif
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3652kb
input:
0 2 1 1
output:
result:
wrong output format Unexpected end of file - int32 expected
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 0ms
memory: 3536kb
input:
0 2 1 4
output:
result:
wrong output format Unexpected end of file - int32 expected
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Wrong Answer
Test #20:
score: 10
Accepted
time: 1ms
memory: 3812kb
input:
14 16 393 6
output:
172 3 2 3 14 3 0 1 3 3 3 15 14 3 0 1 3 3 2 3 15 3 0 1 3 3 3 15 14 3 0 1 3 3 2 3 15 3 6 14 15 3 4 5 14 3 14 13 15 3 4 5 14 3 6 14 13 3 4 5 14 3 14 13 15 3 4 5 14 3 6 14 13 3 2 3 14 3 0 1 3 3 3 15 14 3 0 1 3 3 2 3 15 3 0 1 3 3 3 15 14 3 0 1 3 3 2 3 15 3 6 14 15 3 4 5 14 3 14 13 15 3 4 5 14 3 6 14 13 3...
result:
ok OK.
Test #21:
score: 0
Wrong Answer
time: 0ms
memory: 3768kb
input:
39 41 1093 6
output:
1504 3 0 1 40 3 2 40 39 3 0 1 40 3 2 40 39 3 3 4 38 3 39 38 40 3 3 4 38 3 39 38 40 3 0 1 40 3 2 40 39 3 0 1 40 3 2 40 39 3 3 4 38 3 39 38 40 3 3 4 38 3 39 38 40 3 5 6 40 3 7 40 38 3 5 6 40 3 7 40 38 3 40 38 39 3 8 9 38 3 38 37 39 3 8 9 38 3 40 38 37 3 8 9 38 3 38 37 39 3 8 9 38 3 40 38 37 3 5 6 40 3...
result:
wrong answer Integer 1504 violates the range [0, 1093]
Subtask #7:
score: 0
Skipped
Dependency #2:
0%
Subtask #8:
score: 0
Skipped
Dependency #3:
0%