QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#244299 | #7687. Randias Permutation Task | ucup-team2432# | TL | 1ms | 3492kb | C++20 | 1.7kb | 2023-11-08 23:00:14 | 2023-11-08 23:00:16 |
Judging History
answer
#include<bits/stdc++.h>
using LL = long long;
const LL inf = 1e9;
const LL P[2] = {1000000007,1000000009};
const LL K = 7653524;
std::array<LL,2> hash(const std::vector<LL> &vec) {
std::array<LL,2> res = {0,0},unit = {1,1};
int n = vec.size() - 1;
for (int i = n-1; i >= 0; --i) {
for (int j = 0; j < 2; ++j) {
res[j] = (res[j] + unit[j] * vec[i]) % P[j];
unit[j] = unit[j] * K % P[j];
}
}
return res;
}
void solve() {
std::mt19937 rnd(std::random_device{}());
int n,m;std::cin >> n >> m;
std::vector pmt(m,std::vector<LL>(n+1));
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
std::cin >> pmt[i][j];
}
}
std::shuffle(pmt.begin(),pmt.end(),rnd);
std::map<std::array<LL,2>,int> mp;
std::priority_queue<std::pair<int,std::vector<LL>>,std::vector<std::pair<int,std::vector<LL>>>,std::greater<>> q;
for (int i = 0; i < m; ++i) {
pmt[i][n] = i;
q.emplace(i+1,pmt[i]);
}
LL ans = 0;
while (!q.empty()) {
auto [point,vec] = q.top();q.pop();
auto hsh = hash(vec);
if (!mp.count(hsh)) {
mp[hsh] = vec.back();
ans ++;
} else {
if (mp[hsh]+15 < vec.back()) {
continue;
}
}
if (point == m) continue;
q.emplace(point+1,vec);
for (int i = 0; i < n; ++i) {
vec[i] = pmt[point][vec[i] - 1];
}
vec[n] = point;
q.emplace(point+1,vec);
}
std::cout << ans % P[0];
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
// clock_t st = clock();
// std::cout << std::fixed << std::setprecision(12);
// freopen("test.in", "r", stdin);
// freopen("test.out", "w", stdout);
int T = 1;
// std::cin >> T;
while (T --) {
solve();
}
// std::cout << (double)(clock()-st)/CLOCKS_PER_SEC;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3420kb
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: 3492kb
input:
2 1 2 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: -100
Time Limit Exceeded
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 ...