QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#265826 | #7687. Randias Permutation Task | fishfishfriedfish# | RE | 1ms | 3412kb | C++14 | 1.4kb | 2023-11-25 21:28:39 | 2023-11-25 21:28:39 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define SZ(x) ((int)x.size()-1)
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define DF(i,a,b) for (int i=(a);i>=(b);--i)
//#define mp make_pair
//#define OO(x) fixed<<setprecision(x)
using namespace std;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int read(){
char ch=getchar(); int w=1,c=0;
for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
return w*c;
}
const int M=50;
int n,m;
#define per vector<int>
per a[M];
per operator *(per A,per B){
per C;
C.resize(n);
F(i,0,n-1) C[i]=A[B[i]];
return C;
}
map<per,int> hs,dp[222];
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
n=read(); m=read();
F(i,1,m){
F(j,1,n){
a[i].pb(read()-1);
}
}per I; I.resize(n);
F(i,0,n-1) I[i]=i;
if (m<=19){
F(i,1,(1<<m)-1){
per tmp=I;
F(j,1,m){
if (i>>(j-1)&1)
tmp=tmp*a[j];
}
hs[tmp]++;
}
cout<<hs.size()<<"\n";
}
else{
dp[0][I]=1;
F(i,1,m){
for (auto x:dp[i-1]){
dp[i][x.first]=1;
dp[i][x.first*a[i]]=1;
}
}
cout<<dp[m].size()<<"\n";
}
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3388kb
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: 3412kb
input:
2 1 2 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: -100
Runtime Error
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 ...