QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#658558#7011. Rikka with Sorting NetworksFork512HzWA 0ms3708kbC++202.5kb2024-10-19 17:02:352024-10-19 17:02:38

Judging History

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

  • [2024-10-19 17:02:38]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3708kb
  • [2024-10-19 17:02:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vll;
//#define DEBUG
#ifdef DEBUG
const ll N = 60;
#endif
#ifndef DEBUG
const ll N = 60;
#endif
ll n, k, M, nframe;
bool isFrame[N];
pii swapper[15];
vll frames;
ll id[N][N];

ll dfs(vll &target, ll depth)
{
	if(depth == k) return 1;
	if(target[swapper[depth].first] > target[swapper[depth].second]) return 0;
	
	ll ans  = dfs(target, depth+1);
	swap(target[swapper[depth].first], target[swapper[depth].second]);
	ans = (ans + dfs(target, depth+1)) % M;
	swap(target[swapper[depth].first], target[swapper[depth].second]);
	
	return ans;
}



ll g(vll target)
{
	return dfs(target, 0);
	
}
ll f(ll pos, ll jmp)
{
	if(jmp > pos)
	{
		ll u = (jmp == nframe-1? n: frames[jmp+1]); 
		ll d = frames[jmp];
		return id[pos][u-1] - id[pos][d-1];
	}
	else if(jmp < pos)
	{
		ll u = frames[jmp];
		ll d = (jmp == 0? -1: frames[jmp-1]);
		return id[pos][u] - (d == -1? 0 :id[pos][d]);
	}
	else
	{
		ll u = (jmp == nframe-1? n: frames[jmp+1]); 
		ll d = (jmp == 0? -1: frames[jmp-1]);
		return id[pos][u-1] - (d == -1? 0: id[pos][d]);
	}
}
ll calc(ll pos, ll jmp)
{
	vll target(nframe);
	target[pos] = jmp;
	ll val = 0;
	for(ll i=0; i<nframe; i++)
	{
		if(i == pos) continue;
		if(val == jmp) val++;
		target[i] = val;
		val++;
	}
	return g(target) * f(pos, jmp) % M;
}
int main()
{
	#ifdef DEBUG
	freopen("1.txt", "r", stdin);
	#endif
	#ifndef DEBUG
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	#endif
	ll z;
	cin >> z;
	for(ll i=0; i<=50; i++)
		for(ll j=0; j<=50; j++)
			id[i][j] = 1;
	for(ll i=1; i<=50; i++)
	{
		id[i][i] = 0;
		id[i][i-1] = 0;
	}
	for(ll i=0; i<=50; i++)
		for(ll j=1; j<=50; j++)
			id[i][j] += id[i][j-1];
	while(z--)
	{
		cin >> n >> k >> M;
		memset(isFrame, 0, n+5);
		frames.clear();
		for(ll i=0; i<k; i++)
		{
			ll u, v;
			cin >> u >> v;
			u--, v--;
			isFrame[u] = 1;
			isFrame[v] = 1;
			swapper[i] = {u, v};
		}
		nframe = 0;
		for(ll i=0; i<n; i++) if(isFrame[i])
		{
			nframe++;
			frames.push_back(i);
		}
		ll ans = 0;
		for(ll i=0; i<nframe; i++)
			for(ll j=0; j<nframe; j++)
			{
				if(j == i || j == i-1) continue;
				ans = (ans + calc(i, j)) % M;
			}
		ll same = 0;
		for(ll i=0; i<nframe; i++) same += f(i, i);
		for(ll i=0; i<n; i++) if(!isFrame[i])
			same += id[i][n-1];
		vll target(nframe);
		for(ll i=0; i<nframe; i++) target[i] = i;
		ans = (ans + same*g(target)) % M;
		cout << ans << '\n';
	}
	return 0;
}//

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3708kb

input:

4
4 0 998244353
4 1 998244353
1 2
4 3 998244353
1 2
2 3
1 2
4 6 998244353
1 2
2 3
1 2
3 4
2 3
1 2

output:

10
14
24
24

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3644kb

input:

100
14 0 332974091
7 0 860384617
38 0 721801273
20 0 905563207
15 0 665595113
19 0 315971339
37 10 381449743
20 25
20 25
20 25
20 25
20 25
20 25
20 25
20 25
20 25
20 25
33 7 891399043
7 17
6 16
25 32
25 31
16 25
25 32
17 30
35 0 134186387
43 4 344440849
14 26
26 29
14 26
14 29
44 3 520502371
5 8
5 8...

output:

170
37
1370
362
197
325
1311744
0
1157
0
3698
32
2532
0
785
0
0
1233920
64
89664
232
72120
0
0
0
842
0
0
0
362
0
0
0
0
0
0
1765
0
0
8
3490
18648
0
0
1024
0
0
0
34880
0
0
0
3526
3500
6984
882
2210
0
328
12
6644
0
0
2117
0
0
677
0
0
0
0
3072
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4608
0
0
0
137736
0
0
0
...

result:

wrong answer 7th lines differ - expected: '2528', found: '1311744'