QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#615835 | #9444. Again Permutation Problem | ucup-team3586# | WA | 124ms | 4628kb | C++23 | 2.7kb | 2024-10-05 20:32:42 | 2024-10-05 20:32:43 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
const ll mod=998244353;
mt19937_64 rng(20210448);
using perm=vector<int>;
int n,m;
perm I;
perm inv(const perm &p)
{
vector<int> vec(n);
for(int i=0;i<n;i++)
vec[p[i]]=i;
return vec;
}
perm comp(const perm &p,const perm &q)
{
vector<int> vec(n);
for(int i=0;i<n;i++)
vec[i]=p[q[i]];
return vec;
}
perm P[33];
vector<perm> vect[33];
vector<perm> E;
vector<pii> G[33];
int flag[50500];
int vis[33];
perm ind[33];
int u[50500],v[50500];
void dfs(int u)
{
vis[u]=1;
for(auto pr:G[u])
if(!vis[pr.first])
{
flag[pr.second]=flag[pr.second^1]=1;
ind[pr.first]=comp(E[pr.second],ind[u]);
dfs(pr.first);
}
}
ll f[33][33];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++)
I.pb(i);
for(int i=1;i<=m;i++)
{
for(int j=0;j<n;j++)
{
int x;
cin>>x;
x--;
P[i].pb(x);
}
}
vector<perm> pool;
for(int i=1;i<=m;i++)
pool.pb(P[i]);
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
G[j].clear();
int tot=0;
E.clear();
for(auto p:pool)
for(int j=i;j<n;j++)
{
G[p[j]].pb(j,tot);
u[tot]=p[j];
v[tot]=j;
E.pb(inv(p));
tot++;
G[j].pb(p[j],tot);
E.pb(p);
tot++;
}
memset(vis,0,sizeof(vis));
memset(flag,0,sizeof(flag));
ind[i]=I;
dfs(i);
for(int j=i;j<n;j++)
if(vis[j])
vect[i].pb(ind[j]);
vector<perm> npool;
for(int j=0;j<tot;j+=2)
if(!flag[j]&&vis[u[j]])
npool.pb(comp(comp(inv(ind[v[j]]),E[j]),ind[u[j]]));
pool.clear();
for(int j=0;j<n+n;j++)
{
perm p=I;
for(int k=0;k<=sz(npool)*2;k++)
p=comp(p,npool[rng()%sz(npool)]);
pool.pb(p);
}
}
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
f[i][j]=1;
for(int i=n-1;i>=0;i--)
{
ll g[33][33];
memset(g,0,sizeof(g));
for(int a=0;a<n;a++)
for(int b=0;b<n;b++)
for(auto p:vect[i])
g[p[a]][p[b]]=(g[p[a]][p[b]]+f[a][b])%mod;
memcpy(f,g,sizeof(f));
}
ll ans=0;
for(int i=0;i<n;i++)
for(int j=0;j<i;j++)
ans=(ans+f[i][j])%mod;
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3776kb
input:
3 2 1 2 3 2 3 1
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3788kb
input:
5 2 3 4 5 1 2 1 5 4 3 2
output:
50
result:
ok 1 number(s): "50"
Test #3:
score: 0
Accepted
time: 124ms
memory: 4628kb
input:
30 12 1 2 9 4 5 6 7 8 3 10 11 12 19 14 15 25 17 18 20 26 21 22 23 24 16 29 27 28 13 30 9 2 27 4 5 10 7 8 1 25 11 12 24 14 15 16 17 18 19 20 21 22 23 28 6 26 3 13 29 30 1 5 3 29 2 6 7 8 9 10 11 12 13 16 15 18 17 14 19 20 21 22 28 27 25 26 24 23 4 30 7 2 3 25 5 6 1 28 21 15 11 12 13 14 10 17 16 18 19 ...
output:
701414999
result:
ok 1 number(s): "701414999"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3828kb
input:
1 1 1
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3760kb
input:
2 1 2 1
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 1ms
memory: 4048kb
input:
5 1 4 2 3 1 5
output:
5
result:
ok 1 number(s): "5"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3856kb
input:
6 3 4 2 3 6 5 1 1 4 3 2 6 5 1 2 4 3 5 6
output:
5400
result:
ok 1 number(s): "5400"
Test #8:
score: 0
Accepted
time: 1ms
memory: 3856kb
input:
6 1 1 5 3 4 2 6
output:
5
result:
ok 1 number(s): "5"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3852kb
input:
5 3 1 4 3 2 5 1 2 4 5 3 5 2 3 4 1
output:
600
result:
ok 1 number(s): "600"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3776kb
input:
6 2 2 1 3 4 5 6 1 2 3 4 5 6
output:
1
result:
ok 1 number(s): "1"
Test #11:
score: 0
Accepted
time: 1ms
memory: 3792kb
input:
6 4 1 6 3 4 5 2 2 1 4 3 5 6 2 6 5 4 3 1 2 1 6 3 5 4
output:
5400
result:
ok 1 number(s): "5400"
Test #12:
score: 0
Accepted
time: 1ms
memory: 3860kb
input:
5 2 3 2 1 4 5 1 5 3 2 4
output:
21
result:
ok 1 number(s): "21"
Test #13:
score: 0
Accepted
time: 1ms
memory: 3828kb
input:
3 3 1 3 2 3 1 2 1 3 2
output:
9
result:
ok 1 number(s): "9"
Test #14:
score: 0
Accepted
time: 1ms
memory: 3832kb
input:
4 2 3 1 4 2 4 2 1 3
output:
72
result:
ok 1 number(s): "72"
Test #15:
score: 0
Accepted
time: 0ms
memory: 4012kb
input:
3 1 2 3 1
output:
4
result:
ok 1 number(s): "4"
Test #16:
score: 0
Accepted
time: 1ms
memory: 3788kb
input:
5 1 2 4 3 5 1
output:
18
result:
ok 1 number(s): "18"
Test #17:
score: 0
Accepted
time: 1ms
memory: 3852kb
input:
5 4 3 5 2 4 1 1 2 5 4 3 5 4 3 2 1 4 2 3 1 5
output:
600
result:
ok 1 number(s): "600"
Test #18:
score: 0
Accepted
time: 1ms
memory: 3792kb
input:
5 1 1 5 3 4 2
output:
5
result:
ok 1 number(s): "5"
Test #19:
score: 0
Accepted
time: 1ms
memory: 3848kb
input:
5 1 5 2 3 4 1
output:
7
result:
ok 1 number(s): "7"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3764kb
input:
4 2 4 3 1 2 3 4 2 1
output:
12
result:
ok 1 number(s): "12"
Test #21:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
6 3 2 3 1 4 5 6 1 2 3 4 6 5 1 4 3 2 5 6
output:
168
result:
ok 1 number(s): "168"
Test #22:
score: 0
Accepted
time: 1ms
memory: 3864kb
input:
6 2 3 4 1 2 5 6 2 3 1 4 5 6
output:
36
result:
ok 1 number(s): "36"
Test #23:
score: 0
Accepted
time: 1ms
memory: 3768kb
input:
4 2 1 3 4 2 4 2 3 1
output:
72
result:
ok 1 number(s): "72"
Test #24:
score: -100
Wrong Answer
time: 0ms
memory: 3760kb
input:
3 2 2 1 3 2 3 1
output:
4
result:
wrong answer 1st numbers differ - expected: '9', found: '4'