QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#623869 | #7687. Randias Permutation Task | hjxddl | RE | 0ms | 0kb | C++20 | 2.6kb | 2024-10-09 14:15:43 | 2024-10-09 14:15:43 |
answer
// Coded by hjxddl
#include <bits/stdc++.h>
#define ll long long
#define db double
const int N = 2e5 + 5;
int n, m;
int lowbit(int x) {
return x & -x;
}
std::vector<int> plus(const std::vector<int> &a, const std::vector<int> &b) {
std::vector<int> c;
for (int i = 0; i < n; i++) {
// std::cerr << i << " " << a[i] << " " << b[i] << " " << b[a[i] - 1] << '\n';
c.push_back(b[a[i] - 1]);
}
return c;
}
void solve1() {
std::vector<std::vector<int>> val(m + 5);
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
int x;
std::cin >> x;
val[i].push_back(x);
// std::cerr << i << " " << x << '\n';
}
}
int maxn = (1 << m) - 1;
// std::cerr << maxn << '\n';
std::vector<std::vector<int>> ans(maxn + 5);
std::map<std::vector<int>, bool> mp;
for (int i = 1, j = 1; i <= m; i++, j <<= 1) {
ans[j] = val[i];
// for (int y : ans[j]) {
// std::cerr << j << " " << y << '\n';
// }
mp[ans[j]] = 1;
}
for (int i = 1, j = 2; i < m; i++, j <<= 1) {
int maxn = j - 1;
for (int k = 1; k <= maxn; k++) {
// std::cerr << j << " " << k << "ssss" << '\n';
ans[j + k] = plus(ans[j], ans[k]);
mp[ans[j + k]] = 1;
}
}
// for (auto [it, v] : mp) {
// for (auto x : it) {
// std::cout << x << " ";
// }
// std::cout << '\n';
// }
std::cout << mp.size() << '\n';
}
void solve2() {
std::map<std::vector<int>, int> mp, tmp;
std::vector<std::vector<int>> val(m + 5);
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
int x;
std::cin >> x;
val[i].push_back(x);
}
mp[val[i]] = i;
}
for (int i = 1; i <= m; i++) {
for (auto &[x, y] : mp) {
if (y >= i) continue;
tmp[plus(val[i], x)] = i;
}
for (auto &[x, y] : tmp) {
if (mp.count(x))
mp[x] = std::min(mp[x], y);
else
mp[x] = y;
}
tmp.clear();
}
std::cout << mp.size() << '\n';
}
void solve() {
std::cin >> n >> m;
if (m <= 20)
solve1();
else
solve2();
}
int main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0), std::cout.tie(0);
int t = 1;
// std::cin >> t;
while (t--) {
solve();
}
std::cout << std::flush;
system("pause");
}
詳細信息
Test #1:
score: 0
Dangerous Syscalls
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