QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232573#1277. Permutationle6666WA 1ms3548kbC++144.5kb2023-10-30 16:43:222023-10-30 16:43:22

Judging History

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

  • [2023-10-30 16:43:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3548kb
  • [2023-10-30 16:43:22]
  • 提交

answer

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define int long long

char *p1,*p2,buf[100000];
#define nc() (p1==p2 && (p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
int read()
{
	int x=0,f=1;
	char ch=nc();
	while(ch<48||ch>57)
	{
		if(ch=='-')
			f=-1;
		ch=nc();
	}
	while(ch>=48&&ch<=57)
		x=x*10+ch-48,ch=nc();
	return x*f;
}

void write(int x)
{
	if(x<0)
		putchar('-'),x=-x;
	if(x>9)
		write(x/10);
	putchar(x%10+'0');
	return;
}

const ll MOD = 1e9 + 7;
const int MAXN = 50 + 5;
int T, n, a[MAXN], W;
ll pow2[MAXN];
unordered_map<ll, ll> f;
//map<ll, ll> f;
unordered_map<ll, ll> rev;
//map<ll, ll> rev;
//queue<ll> q;
struct Queue {
	int l = 1, r = 0;
	ll a[4000000];
	void clear() { l = 1, r = 0; }
	bool empty() { return l == r + 1; }
	void pop() { l++; }
	void push(ll x) { a[++r] = x; }
	ll front() { return a[l]; }
} q;

ll cut(ll x, int l, int r) {
	return ((x & (pow2[l + 1] - 1)) >> r);
}

bool check(ll x, int k) {
	ll y = rev[x]; int len;
	if ((x >> k) & 1) return false;
	if (k <= n / 2) len = k - 1;
	else len = n - k;
	return cut(x, k + len, k - len) == cut(y, n - k + len, n - k - len);
}

signed main() {
	pow2[0] = 1;
	for (int i = 1; i <= 51; i++)
		pow2[i] = pow2[i - 1] * 2;
//	T = 1;
	T = read();
	while (T--) {
//		W = 0;
		n = 50;
		n = read();
//		for (int i = 1; i <= n; i++) a[i] = 0;
		for (int i = 1; i <= n; i++) a[i] = read();
//		while (!q.empty()) q.pop();
		q.clear();
		f.clear(), rev.clear();
		f[0] = 1, rev[0] = 0, q.push(0);
		while (!q.empty()) {
			ll x = q.front(); q.pop();
			int p = __popcount(x);
//			printf("x = %lld, p = %d\n", x, p);
			if (p == n) break;
			if (a[p + 1]) {
				if (check(x, a[p + 1])) {
					ll nxt = x | pow2[a[p + 1]];
					if (f.find(nxt) == f.end()) {
						q.push(nxt);
						rev[nxt] = rev[x] | pow2[n - a[p + 1]];
//						W++;
					}
//					printf("nxt = %lld\n", nxt);
					f[nxt] = (f[nxt] + f[x]) % MOD;
				}
			}
			else {
				for (int i = 1; i <= n; i++) {
					if (check(x, i)) {
						ll nxt = x | pow2[i];
						if (f.find(nxt) == f.end()) {
							q.push(nxt);
							rev[nxt] = rev[x] | pow2[n - i];
//							W++;
						}
//						printf("nxt = %lld\n", nxt);
						f[nxt] = (f[nxt] + f[x]) % MOD;
					}
				}
			}
		}
		int cnt = 0;
		for (int i = 1; i <= n; i++) if (!a[i]) cnt++;
		ll jc = 1;
		for (int i = 1; i <= cnt; i++) jc = jc * i % MOD;
		write((jc - f[pow2[n + 1] - 2] + MOD) % MOD);
//		printf("W = %d\n", W);
	}
	return 0;
}
/*

2
3
0 0 0
7
1 0 3 0 0 6 0

1
50
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1
10
0 0 0 0 0 0 0 0 0 0

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3548kb

input:

2
3
0 0 0
7
1 0 3 0 0 6 0

output:

221

result:

wrong answer 1st words differ - expected: '2', found: '221'