QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#243955#7687. Randias Permutation TaskinvadedRE 1ms3608kbC++173.9kb2023-11-08 19:38:492023-11-08 19:38:50

Judging History

你现在查看的是最新测评结果

  • [2023-11-08 19:38:50]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3608kb
  • [2023-11-08 19:38:49]
  • 提交

answer

#include<bits/stdc++.h>
#ifndef xxx
#define dbg(...) ;
#endif
using namespace std;
template<class T> ostream &operator<<(ostream &o, const vector <T> &v) { bool f=false; for(T i:v) { f?o<<' ':o; o<<(i); f=true; } return o; }
template<class T> void sort(T &v) { std::sort(v.begin(), v.end()); }
template<class T, class C> void sort(T &v, C c) { std::sort(v.begin(), v.end(), c); }
template<class T> void reverse(T &v) { std::reverse(v.begin(), v.end()); }
template<class T> bool is_sorted(T &v) { return std::is_sorted(v.begin(), v.end()); }
template<class T> inline void _min(T &x, const T &y) { x>y?x=y:x; }
template<class T> inline void _max(T &x, const T &y) { x<y?x=y:x; }
istream &operator>>(istream &i, __int128_t &x) { x=0; short f=1; char c=0; while(!isdigit(c)) { if(c=='-')f=-1; c=i.get(); } while(isdigit(c))x=x*10+c-'0', c=i.get(); x*=f; return i; }
ostream &operator<<(ostream &o, __int128_t x) { if(x==0) { o<<0; return o; } bool f=false; string s; if(x<0)f=true, x=-x; while(x)s+=x%10+'0', x/=10; reverse(s); if(f)o<<'-'; o<<s; return o; }
mt19937 mt(time(0));
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
constexpr int maxn=180+5;
constexpr int mod=1e9+7;
constexpr int inf=0x3f3f3f3f;
constexpr ll INF=0x3f3f3f3f3f3f3f3fll;
constexpr double pi=acos(-1.0);
constexpr double eps=1e-9;
vector<vector<int>>e;
vector<int>composition(const vector<int> &a, const vector<int> &b)
{
	if(!a.size())return b;
	vector<int>ans;
	for(int i=1; i<=a.size(); i++)
	{
		ans.push_back(a[b[i-1]-1]);
	}
	return ans;
}
int main()//MARK: main
{
#ifndef xxx
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#endif
	cout<<fixed<<setprecision(10);
	int n, m;
	cin>>n>>m;
	for(int i=1; i<=m; i++)
	{
		vector<int>vec(n);
		for(int &x:vec)
		{
			cin>>x;
		}
		e.push_back(vec);
	}
	function<void(int, int, vector<int> &, map<vector<int>, bool> &)>dfs=[&](int step, int lim, vector<int> &now, map<vector<int>, bool> &mp)
	{
		if(step==lim+1)
		{
			mp[now]=true;
			return;
		}
		vector<int> nex=composition(now, e[step]);
		dfs(step+1, lim, nex, mp);
		dfs(step+1, lim, now, mp);
	};
	auto getans=[&]()->int
	{
		int ans=0;
		if(n==1)
		{
			return 1;
		}
		else if(n==2)
		{
			const vector<int>v1={1, 2};
			const vector<int>v2={2, 1};
			if(find(e.begin(), e.end(), v1)!=e.end()&&find(e.begin(), e.end(), v2)!=e.end())
			{
				return 2;
			}
			else if(count(e.begin(), e.end(), v2)>=2)
			{
				return 2;
			}
			return 1;
		}
		if(e.size()<=20)
		{
			map<vector<int>, bool>mp;
			vector<int>now;
			dfs(0, e.size()-1, now, mp);
			ans=mp.size()-1;
		}
		else if(e.size()<=36)
		{
			map<vector<int>, bool>mp1, mp2, mp;
			vector<int>now1, now2;
			int mid=e.size()/2;
			dfs(0, mid, now1, mp1);
			dfs(mid+1, e.size()-1, now2, mp2);
			mp=mp1;
			for(auto &p:mp2)
				mp.insert(p);
			for(const auto &[a, f1]:mp1)
			{
				for(const auto &[b, f2]:mp2)
				{
					mp[composition(a, b)]=true;
				}
			}
			ans=mp.size()-1;
		}
		else
		{
			map<vector<int>, bool>mp1, mp2, mp3, mp4, mp;
			vector<int>now1, now2, now3, now4;
			int l1=e.size()/4;
			int l2=2*l1;
			int l3=3*l1;
			dfs(0, l1, now1, mp1);
			dfs(l1+1, l2, now2, mp2);
			dfs(l2+1, l3, now3, mp3);
			dfs(l3+1, e.size()-1, now4, mp4);
			mp=mp1;
			for(auto &p:mp2)
				mp.insert(p);
			for(auto &p:mp3)
				mp.insert(p);
			for(auto &p:mp4)
				mp.insert(p);
			for(const auto &[a, f1]:mp1)
			{
				for(const auto &[b, f2]:mp2)
					for(const auto &[c, f3]:mp3)
						for(const auto &[d, f4]:mp4)
						{
							auto comp1=composition(a, b);
							auto comp2=composition(comp1, c);
							auto comp3=composition(comp2, d);
							mp[comp3]=true;
						}
			}
			ans=mp.size()-1;
		}
		return ans;
	};
	cout<<getans()<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3488kb

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: 0ms
memory: 3564kb

input:

2 1
2 1

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3576kb

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: 0
Accepted
time: 1ms
memory: 3608kb

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:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3576kb

input:

2 90
1 2
1 2
1 2
1 2
2 1
2 1
2 1
2 1
1 2
2 1
1 2
1 2
1 2
2 1
2 1
2 1
2 1
1 2
1 2
1 2
1 2
2 1
1 2
2 1
1 2
1 2
1 2
2 1
2 1
1 2
2 1
1 2
2 1
1 2
1 2
2 1
1 2
2 1
2 1
2 1
2 1
1 2
2 1
2 1
2 1
2 1
1 2
1 2
2 1
2 1
1 2
1 2
1 2
2 1
1 2
2 1
2 1
1 2
2 1
2 1
2 1
2 1
2 1
2 1
2 1
1 2
1 2
1 2
2 1
1 2
1 2
2 1
1 2
1 2...

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 0
Accepted
time: 1ms
memory: 3488kb

input:

90 2
43 44 28 69 66 18 5 23 87 8 24 89 31 29 81 1 68 2 78 53 49 54 4 13 77 61 33 57 63 85 55 79 46 35 45 64 65 42 30 6 19 74 82 80 17 26 32 59 7 72 16 3 47 73 39 36 25 34 56 86 71 62 84 40 41 11 50 27 20 14 37 12 38 58 48 83 76 70 51 88 22 90 21 9 10 60 15 52 75 67
9 73 52 51 81 16 71 77 6 57 11 75 ...

output:

3

result:

ok 1 number(s): "3"

Test #7:

score: -100
Runtime Error

input:

3 60
2 1 3
3 1 2
3 2 1
1 2 3
1 2 3
3 2 1
3 1 2
2 3 1
2 1 3
3 1 2
2 3 1
2 3 1
2 1 3
3 2 1
3 1 2
3 2 1
1 2 3
2 1 3
2 1 3
2 1 3
2 3 1
2 3 1
2 3 1
3 1 2
1 2 3
3 1 2
2 3 1
2 3 1
2 1 3
1 2 3
3 1 2
2 1 3
2 3 1
2 3 1
2 3 1
3 1 2
2 3 1
1 2 3
1 2 3
3 2 1
3 1 2
3 1 2
2 3 1
1 3 2
3 1 2
1 3 2
1 2 3
1 3 2
1 3 2
3...

output:


result: