QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#225621 | #5176. 多控制反转 | hos_lyric# | 55 | 4ms | 4216kb | C++14 | 3.7kb | 2023-10-24 21:16:15 | 2024-07-04 02:21:30 |
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: 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 main() {
for (; ~scanf("%d%d%d%d", &N, &M, &Q, &C); ) {
ops.clear();
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);
}
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(0);
#endif
}
return 0;
}
详细
Subtask #1:
score: 15
Accepted
Test #1:
score: 15
Accepted
time: 0ms
memory: 3960kb
input:
0 2 1 1
output:
1 1 0
result:
ok OK.
Test #2:
score: 0
Accepted
time: 1ms
memory: 3908kb
input:
13 28 105 1
output:
23 3 0 1 14 3 14 2 15 3 15 3 16 3 16 4 17 3 17 5 18 3 18 6 19 3 19 7 20 3 20 8 21 3 21 9 22 3 22 10 23 3 23 11 24 3 24 12 13 3 23 11 24 3 22 10 23 3 21 9 22 3 20 8 21 3 19 7 20 3 18 6 19 3 17 5 18 3 16 4 17 3 15 3 16 3 14 2 15 3 0 1 14
result:
ok OK.
Test #3:
score: 0
Accepted
time: 1ms
memory: 3888kb
input:
5 12 41 1
output:
7 3 0 1 6 3 6 2 7 3 7 3 8 3 8 4 5 3 7 3 8 3 6 2 7 3 0 1 6
result:
ok OK.
Test #4:
score: 0
Accepted
time: 1ms
memory: 3912kb
input:
20 42 161 1
output:
37 3 0 1 21 3 21 2 22 3 22 3 23 3 23 4 24 3 24 5 25 3 25 6 26 3 26 7 27 3 27 8 28 3 28 9 29 3 29 10 30 3 30 11 31 3 31 12 32 3 32 13 33 3 33 14 34 3 34 15 35 3 35 16 36 3 36 17 37 3 37 18 38 3 38 19 20 3 37 18 38 3 36 17 37 3 35 16 36 3 34 15 35 3 33 14 34 3 32 13 33 3 31 12 32 3 30 11 31 3 29 10 30...
result:
ok OK.
Subtask #2:
score: 10
Accepted
Dependency #1:
100%
Accepted
Test #5:
score: 10
Accepted
time: 0ms
memory: 3900kb
input:
48 98 385 2
output:
93 3 0 1 49 3 49 2 50 3 50 3 51 3 51 4 52 3 52 5 53 3 53 6 54 3 54 7 55 3 55 8 56 3 56 9 57 3 57 10 58 3 58 11 59 3 59 12 60 3 60 13 61 3 61 14 62 3 62 15 63 3 63 16 64 3 64 17 65 3 65 18 66 3 66 19 67 3 67 20 68 3 68 21 69 3 69 22 70 3 70 23 71 3 71 24 72 3 72 25 73 3 73 26 74 3 74 27 75 3 75 28 76...
result:
ok OK.
Test #6:
score: 0
Accepted
time: 1ms
memory: 3924kb
input:
41 84 329 2
output:
79 3 0 1 42 3 42 2 43 3 43 3 44 3 44 4 45 3 45 5 46 3 46 6 47 3 47 7 48 3 48 8 49 3 49 9 50 3 50 10 51 3 51 11 52 3 52 12 53 3 53 13 54 3 54 14 55 3 55 15 56 3 56 16 57 3 57 17 58 3 58 18 59 3 59 19 60 3 60 20 61 3 61 21 62 3 62 22 63 3 63 23 64 3 64 24 65 3 65 25 66 3 66 26 67 3 67 27 68 3 68 28 69...
result:
ok OK.
Test #7:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
50 102 401 2
output:
97 3 0 1 51 3 51 2 52 3 52 3 53 3 53 4 54 3 54 5 55 3 55 6 56 3 56 7 57 3 57 8 58 3 58 9 59 3 59 10 60 3 60 11 61 3 61 12 62 3 62 13 63 3 63 14 64 3 64 15 65 3 65 16 66 3 66 17 67 3 67 18 68 3 68 19 69 3 69 20 70 3 70 21 71 3 71 22 72 3 72 23 73 3 73 24 74 3 74 25 75 3 75 26 76 3 76 27 77 3 77 28 78...
result:
ok OK.
Subtask #3:
score: 0
Wrong Answer
Dependency #2:
100%
Accepted
Test #8:
score: 10
Accepted
time: 1ms
memory: 3768kb
input:
0 2 1 3
output:
1 1 0
result:
ok OK.
Test #9:
score: -10
Wrong Answer
time: 1ms
memory: 4120kb
input:
19 40 153 3
output:
336 3 0 1 19 3 2 19 20 3 0 1 19 3 2 19 20 3 3 4 18 3 20 18 19 3 3 4 18 3 20 18 19 3 0 1 19 3 2 19 20 3 0 1 19 3 2 19 20 3 3 4 18 3 20 18 19 3 3 4 18 3 20 18 19 3 5 6 20 3 7 20 18 3 5 6 20 3 7 20 18 3 19 18 20 3 8 9 18 3 18 17 20 3 8 9 18 3 19 18 17 3 8 9 18 3 18 17 20 3 8 9 18 3 19 18 17 3 5 6 20 3 ...
result:
wrong answer Integer 336 violates the range [0, 153]
Subtask #4:
score: 10
Accepted
Test #13:
score: 10
Accepted
time: 1ms
memory: 3832kb
input:
0 2 1 4
output:
1 1 0
result:
ok OK.
Test #14:
score: 0
Accepted
time: 1ms
memory: 3808kb
input:
18 20 325 4
output:
296 3 0 1 18 3 2 18 19 3 0 1 18 3 2 18 19 3 3 4 17 3 19 17 18 3 3 4 17 3 19 17 18 3 0 1 18 3 2 18 19 3 0 1 18 3 2 18 19 3 3 4 17 3 19 17 18 3 3 4 17 3 19 17 18 3 5 6 19 3 7 19 17 3 5 6 19 3 7 19 17 3 8 18 16 3 17 16 19 3 8 18 16 3 17 16 19 3 5 6 19 3 7 19 17 3 5 6 19 3 7 19 17 3 8 18 16 3 17 16 19 3...
result:
ok OK.
Test #15:
score: 0
Accepted
time: 1ms
memory: 4108kb
input:
14 16 197 4
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 #16:
score: 0
Accepted
time: 1ms
memory: 3848kb
input:
20 22 401 4
output:
376 3 0 1 20 3 2 20 21 3 0 1 20 3 2 20 21 3 3 4 19 3 21 19 20 3 3 4 19 3 21 19 20 3 0 1 20 3 2 20 21 3 0 1 20 3 2 20 21 3 3 4 19 3 21 19 20 3 3 4 19 3 21 19 20 3 5 6 21 3 7 21 19 3 5 6 21 3 7 21 19 3 20 19 21 3 8 9 19 3 19 18 21 3 8 9 19 3 20 19 18 3 8 9 19 3 19 18 21 3 8 9 19 3 20 19 18 3 5 6 21 3 ...
result:
ok OK.
Subtask #5:
score: 20
Accepted
Dependency #4:
100%
Accepted
Test #17:
score: 20
Accepted
time: 1ms
memory: 3812kb
input:
18 20 325 5
output:
296 3 0 1 18 3 2 18 19 3 0 1 18 3 2 18 19 3 3 4 17 3 19 17 18 3 3 4 17 3 19 17 18 3 0 1 18 3 2 18 19 3 0 1 18 3 2 18 19 3 3 4 17 3 19 17 18 3 3 4 17 3 19 17 18 3 5 6 19 3 7 19 17 3 5 6 19 3 7 19 17 3 8 18 16 3 17 16 19 3 8 18 16 3 17 16 19 3 5 6 19 3 7 19 17 3 5 6 19 3 7 19 17 3 8 18 16 3 17 16 19 3...
result:
ok OK.
Test #18:
score: 0
Accepted
time: 1ms
memory: 3808kb
input:
17 19 290 5
output:
256 3 0 1 17 3 2 17 18 3 0 1 17 3 2 17 18 3 3 4 16 3 18 16 17 3 3 4 16 3 18 16 17 3 0 1 17 3 2 17 18 3 0 1 17 3 2 17 18 3 3 4 16 3 18 16 17 3 3 4 16 3 18 16 17 3 5 6 18 3 7 18 16 3 5 6 18 3 7 18 16 3 8 17 15 3 16 15 18 3 8 17 15 3 16 15 18 3 5 6 18 3 7 18 16 3 5 6 18 3 7 18 16 3 8 17 15 3 16 15 18 3...
result:
ok OK.
Test #19:
score: 0
Accepted
time: 2ms
memory: 3760kb
input:
20 22 401 5
output:
376 3 0 1 20 3 2 20 21 3 0 1 20 3 2 20 21 3 3 4 19 3 21 19 20 3 3 4 19 3 21 19 20 3 0 1 20 3 2 20 21 3 0 1 20 3 2 20 21 3 3 4 19 3 21 19 20 3 3 4 19 3 21 19 20 3 5 6 21 3 7 21 19 3 5 6 21 3 7 21 19 3 20 19 21 3 8 9 19 3 19 18 21 3 8 9 19 3 20 19 18 3 8 9 19 3 19 18 21 3 8 9 19 3 20 19 18 3 5 6 21 3 ...
result:
ok OK.
Subtask #6:
score: 0
Wrong Answer
Test #20:
score: 10
Accepted
time: 1ms
memory: 3816kb
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: -10
Wrong Answer
time: 1ms
memory: 3800kb
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
Wrong Answer
Dependency #2:
100%
Accepted
Dependency #4:
100%
Accepted
Test #24:
score: 0
Wrong Answer
time: 4ms
memory: 4216kb
input:
93 95 745 7
output:
8576 3 0 1 93 3 2 93 94 3 0 1 93 3 2 93 94 3 5 94 93 3 3 4 94 3 94 92 93 3 3 4 94 3 5 94 92 3 3 4 94 3 94 92 93 3 3 4 94 3 5 94 92 3 0 1 93 3 2 93 94 3 0 1 93 3 2 93 94 3 5 94 93 3 3 4 94 3 94 92 93 3 3 4 94 3 5 94 92 3 3 4 94 3 94 92 93 3 3 4 94 3 5 94 92 3 8 9 92 3 6 7 9 3 9 94 92 3 6 7 9 3 8 9 94...
result:
wrong answer Integer 8576 violates the range [0, 745]
Subtask #8:
score: 0
Skipped
Dependency #3:
0%