QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#225750 | #5176. 多控制反转 | hos_lyric | 35 | 1ms | 4120kb | C++14 | 6.1kb | 2023-10-25 04:51:35 | 2023-10-25 04:51:35 |
Judging History
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);
}
}
/*
n=1
a0 b0
b0+a0
n=2
a0 a1 b0 b1
b1+a1b0
b0+a0
b1+a0a1
b0
n=2 another
a0 a1 b0 b1
b0+a0
b1+a0a1+a1b0
b0
b1+a0a1
n=3
a0 a1 a2 b0 b1 b2
b2+a2b1
b1+a1b0
b0+a0
b1+a0a1
b0
b2+a0a1a2
b0+a0
b1+a1b0
b0
b1
->
a0 a1 a2 b0 b1 b2
b2+a2b1
b1+a1b0
b0+a0
b1+a0a1
b2+a0a1a2
b1+a1b0
b0
b1
n=3 another
a0 a1 a2 b0 b1 b2
b1+a1b0
b0+a0
b1+a0a1
b2+a0a1a2+a2b1
b1+a1b0
b0
b1
b2+a0a1a2
n=4
a0 a1 a2 a3 b0 b1 b2 b3
b3+a3b2
b2+a2b1
b1+a1b0
b0+a0
b1+a0a1
b2+a0a1a2
b1+a1b0
b0
b1
b3+a0a1a2a3
b1+a1b0
b0+a0
b1+a0a1
b2+a2b1
b1+a1b0
b0
b1
b2
->
a0 a1 a2 a3 b0 b1 b2 b3
b3+a3b2
b2+a2b1
b1+a1b0
b0+a0
b1+a0a1
b2+a0a1a2
b3+a0a1a2a3
b2+a2b1
b1+a1b0
b0
b1
b2
*/
// tar += \prod us
void solve(const vector<int> &as, const vector<int> &bs, int tar) {
const int n = as.size();
if (n == 0) {
oper(tar);
} else if (n == 1) {
oper(as[0], tar);
} else {
assert((int)bs.size() >= n - 1);
for (int h = 0; h < 2; ++h) {
oper(as[n - 1], bs[n - 2], tar);
for (int j = n - 1; --j >= 1; ) oper(as[j], bs[j - 1], bs[j]);
oper(as[0], bs[0]);
for (int j = 1; j < n - 1; ++j) oper(as[j], bs[j - 1], bs[j]);
}
}
}
int main() {
for (; ~scanf("%d%d%d%d", &N, &M, &Q, &C); ) {
ops.clear();
vector<int> as, bs;
for (int u = 0; u < N; ++u) as.push_back(u);
for (int u = N + 1; u < M; ++u) bs.push_back(u);
solve(as, bs, 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;
}
詳細信息
Subtask #1:
score: 15
Accepted
Test #1:
score: 15
Accepted
time: 0ms
memory: 4116kb
input:
0 2 1 1
output:
1 1 0
result:
ok OK.
Test #2:
score: 0
Accepted
time: 1ms
memory: 3812kb
input:
13 28 105 1
output:
48 3 12 25 13 3 11 24 25 3 10 23 24 3 9 22 23 3 8 21 22 3 7 20 21 3 6 19 20 3 5 18 19 3 4 17 18 3 3 16 17 3 2 15 16 3 1 14 15 2 0 14 3 1 14 15 3 2 15 16 3 3 16 17 3 4 17 18 3 5 18 19 3 6 19 20 3 7 20 21 3 8 21 22 3 9 22 23 3 10 23 24 3 11 24 25 3 12 25 13 3 11 24 25 3 10 23 24 3 9 22 23 3 8 21 22 3 ...
result:
ok OK.
Test #3:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
5 12 41 1
output:
16 3 4 9 5 3 3 8 9 3 2 7 8 3 1 6 7 2 0 6 3 1 6 7 3 2 7 8 3 3 8 9 3 4 9 5 3 3 8 9 3 2 7 8 3 1 6 7 2 0 6 3 1 6 7 3 2 7 8 3 3 8 9
result:
ok OK.
Test #4:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
20 42 161 1
output:
76 3 19 39 20 3 18 38 39 3 17 37 38 3 16 36 37 3 15 35 36 3 14 34 35 3 13 33 34 3 12 32 33 3 11 31 32 3 10 30 31 3 9 29 30 3 8 28 29 3 7 27 28 3 6 26 27 3 5 25 26 3 4 24 25 3 3 23 24 3 2 22 23 3 1 21 22 2 0 21 3 1 21 22 3 2 22 23 3 3 23 24 3 4 24 25 3 5 25 26 3 6 26 27 3 7 27 28 3 8 28 29 3 9 29 30 ...
result:
ok OK.
Subtask #2:
score: 10
Accepted
Dependency #1:
100%
Accepted
Test #5:
score: 10
Accepted
time: 0ms
memory: 3780kb
input:
48 98 385 2
output:
188 3 47 95 48 3 46 94 95 3 45 93 94 3 44 92 93 3 43 91 92 3 42 90 91 3 41 89 90 3 40 88 89 3 39 87 88 3 38 86 87 3 37 85 86 3 36 84 85 3 35 83 84 3 34 82 83 3 33 81 82 3 32 80 81 3 31 79 80 3 30 78 79 3 29 77 78 3 28 76 77 3 27 75 76 3 26 74 75 3 25 73 74 3 24 72 73 3 23 71 72 3 22 70 71 3 21 69 70...
result:
ok OK.
Test #6:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
41 84 329 2
output:
160 3 40 81 41 3 39 80 81 3 38 79 80 3 37 78 79 3 36 77 78 3 35 76 77 3 34 75 76 3 33 74 75 3 32 73 74 3 31 72 73 3 30 71 72 3 29 70 71 3 28 69 70 3 27 68 69 3 26 67 68 3 25 66 67 3 24 65 66 3 23 64 65 3 22 63 64 3 21 62 63 3 20 61 62 3 19 60 61 3 18 59 60 3 17 58 59 3 16 57 58 3 15 56 57 3 14 55 56...
result:
ok OK.
Test #7:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
50 102 401 2
output:
196 3 49 99 50 3 48 98 99 3 47 97 98 3 46 96 97 3 45 95 96 3 44 94 95 3 43 93 94 3 42 92 93 3 41 91 92 3 40 90 91 3 39 89 90 3 38 88 89 3 37 87 88 3 36 86 87 3 35 85 86 3 34 84 85 3 33 83 84 3 32 82 83 3 31 81 82 3 30 80 81 3 29 79 80 3 28 78 79 3 27 77 78 3 26 76 77 3 25 75 76 3 24 74 75 3 23 73 74...
result:
ok OK.
Subtask #3:
score: 10
Accepted
Dependency #2:
100%
Accepted
Test #8:
score: 10
Accepted
time: 0ms
memory: 4112kb
input:
0 2 1 3
output:
1 1 0
result:
ok OK.
Test #9:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
19 40 153 3
output:
72 3 18 37 19 3 17 36 37 3 16 35 36 3 15 34 35 3 14 33 34 3 13 32 33 3 12 31 32 3 11 30 31 3 10 29 30 3 9 28 29 3 8 27 28 3 7 26 27 3 6 25 26 3 5 24 25 3 4 23 24 3 3 22 23 3 2 21 22 3 1 20 21 2 0 20 3 1 20 21 3 2 21 22 3 3 22 23 3 4 23 24 3 5 24 25 3 6 25 26 3 7 26 27 3 8 27 28 3 9 28 29 3 10 29 30 ...
result:
ok OK.
Test #10:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
47 96 377 3
output:
184 3 46 93 47 3 45 92 93 3 44 91 92 3 43 90 91 3 42 89 90 3 41 88 89 3 40 87 88 3 39 86 87 3 38 85 86 3 37 84 85 3 36 83 84 3 35 82 83 3 34 81 82 3 33 80 81 3 32 79 80 3 31 78 79 3 30 77 78 3 29 76 77 3 28 75 76 3 27 74 75 3 26 73 74 3 25 72 73 3 24 71 72 3 23 70 71 3 22 69 70 3 21 68 69 3 20 67 68...
result:
ok OK.
Test #11:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
25 52 201 3
output:
96 3 24 49 25 3 23 48 49 3 22 47 48 3 21 46 47 3 20 45 46 3 19 44 45 3 18 43 44 3 17 42 43 3 16 41 42 3 15 40 41 3 14 39 40 3 13 38 39 3 12 37 38 3 11 36 37 3 10 35 36 3 9 34 35 3 8 33 34 3 7 32 33 3 6 31 32 3 5 30 31 3 4 29 30 3 3 28 29 3 2 27 28 3 1 26 27 2 0 26 3 1 26 27 3 2 27 28 3 3 28 29 3 4 2...
result:
ok OK.
Test #12:
score: 0
Accepted
time: 0ms
memory: 4120kb
input:
50 102 401 3
output:
196 3 49 99 50 3 48 98 99 3 47 97 98 3 46 96 97 3 45 95 96 3 44 94 95 3 43 93 94 3 42 92 93 3 41 91 92 3 40 90 91 3 39 89 90 3 38 88 89 3 37 87 88 3 36 86 87 3 35 85 86 3 34 84 85 3 33 83 84 3 32 82 83 3 31 81 82 3 30 80 81 3 29 79 80 3 28 78 79 3 27 77 78 3 26 76 77 3 25 75 76 3 24 74 75 3 23 73 74...
result:
ok OK.
Subtask #4:
score: 0
Runtime Error
Test #13:
score: 10
Accepted
time: 0ms
memory: 3816kb
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:
100%
Accepted
Dependency #4:
0%
Subtask #8:
score: 0
Skipped
Dependency #3:
100%
Accepted
Dependency #5:
0%