QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#236827 | #7687. Randias Permutation Task | ucup-team027# | WA | 1ms | 3560kb | C++23 | 1.9kb | 2023-11-04 10:55:54 | 2023-11-04 10:55:55 |
Judging History
answer
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
const int M = 1e9+7;
int permToInt(vi v) {
int use = 0, i = 0, r = 0;
for(int x:v) r = r * ++i + __builtin_popcount(use & -(1<<x)),
use |= 1 << x; // (note: minus, not ~!)
return r;
}
vector<int> apply(vector<int> &a, vector<int> &b) {
int n = a.size();
vector<int> c(n);
for (int i = 0; i < n; i++) {
c[i] = a[b[i]];
}
return c;
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
cin.exceptions(cin.failbit);
int n, m; cin >> n >> m;
vector<vector<int>> a(m, vector<int>(n));
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j]; a[i][j]--;
}
}
if (n <= 9) {
vector<bool> dp(362880);
vector<int> pr(n);
for (int i = 0; i < n; i++) {
pr[i] = i;
}
for (auto b: a) {
vector<bool> nxt = dp;
sort(pr.begin(), pr.end());
do {
int u = permToInt(pr);
if (dp[u]) {
int v = permToInt(apply(pr, b));
nxt[v] = 1;
}
} while (next_permutation(pr.begin(), pr.end()));
nxt[permToInt(b)] = 1;
swap(dp, nxt);
}
int ans = 0;
for (int i: dp) {
if (i) ans++;
}
cout << ans << '\n';
} else {
// m <= 20
set<vector<int>> st;
vector<int> pr(n);
for (int i = 0; i < n; i++) {
pr[i] = i;
}
for (int i = 0; i < (1 << m); i++) {
sort(pr.begin(), pr.end());
for (int j = 0; j < m; j++) {
if (i & (1 << j)) {
pr = apply(pr, a[j]);
}
}
st.insert(pr);
}
cout << st.size() << '\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3520kb
input:
5 4 1 2 3 4 5 5 1 3 4 2 3 4 1 5 2 5 2 4 1 3
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3516kb
input:
2 1 2 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
1 180 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3416kb
input:
180 1 52 71 167 89 165 102 119 125 9 128 180 24 48 172 108 22 164 28 159 111 30 91 67 51 136 97 126 133 177 65 115 157 114 11 171 178 23 127 163 103 99 18 56 94 176 77 44 1 124 74 61 87 4 40 63 92 169 84 146 6 88 55 152 49 10 90 43 174 70 50 69 154 73 147 110 20 82 59 112 12 64 143 16 138 5 170 155 ...
output:
2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'