QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212114#5407. 基础图论练习题BINYU0 10ms9948kbC++141.9kb2023-10-13 09:12:302023-10-13 09:12:30

Judging History

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

  • [2023-10-13 09:12:30]
  • 评测
  • 测评结果:0
  • 用时:10ms
  • 内存:9948kb
  • [2023-10-13 09:12:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1e9 + 7;
int t,n,e[5005][5005],out[5005];
int sum[5005],en[5005],cnt1[5005],cnt[5005],ans[5005][5005];
ll Ans;
char s[5005];
struct node
{
	int out,id;
}a[5005];
bool cmp(node a,node b)
{
	return a.out < b.out;
}
ll ksm(ll a,ll b)
{
	ll res = 1;
	while(b > 0)
	{
		if(b & 1)(res *= a) %= mod;
		b >>= 1;
		(a *= a) %= mod;
	}
	return res;
}
int main()
{
	ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		for(int i = 1;i <= n;i++)
			a[i].out = out[i] = 0,a[i].id = i;
		for(int i = 2;i <= n;i++)
		{
			cin>>s;
			for(int j = 1;j < i;j++)
			{
				e[i][j] = e[j][i] = 0;
				int now;
				if(s[(j - 1) / 4] >= 'A')
					now = s[(j - 1) / 4] - 'A' + 10;
				else now = s[(j - 1) / 4] - '0';
				if(now & (1 << ((j - 1) % 4)))
					e[i][j] = 1,a[i].out++,out[i]++;
				else 
					e[j][i] = 1,a[j].out++,out[j]++;
			}
		}
		sort(a + 1,a + n + 1,cmp);
		for(int i = 1;i <= n;i++)
		{
			for(int j = a[i - 1].out;j < a[i].out;j++)
				en[j] = i - 1;
			sum[i] = sum[i - 1] + a[i].out;
			if(sum[i] == i * (i - 1) / 2)
				cnt[i] = cnt[i - 1] + 1;
			else cnt[i] = cnt[i - 1];
			if(sum[i] == i * (i - 1) / 2 + 1)
				cnt1[i] = cnt1[i - 1];
			else cnt1[i] = cnt1[i - 1];
		}
		for(int i = 1;i <= n;i++)
			for(int j = 1;j <= n;j++)
			{
				if(!e[i][j])continue;
				if(out[i] > out[j] + 1)
					ans[j][i] = ans[i][j] = cnt[n] - (cnt[en[out[i] - 1]] - cnt[en[out[j]] - 1]);
				else if(out[i] <= out[j])
					ans[j][i] = ans[i][j] = cnt[n] + (cnt1[en[out[j]] - 1] - cnt1[en[out[i] - 1]]);
				else ans[j][i] = ans[i][j] = cnt[n];
			}
		Ans = 0;
		for(int i = 2;i <= n;i++)
			for(int j = 1;j < i;j++)
				(Ans += ksm(2,(i - 2) * (i - 1) / 2 + j - 1) * ans[i][j] % mod) % mod;
		cout<<Ans<<endl;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 10ms
memory: 9948kb

input:

10000
100
1
2
2
8
C0
F0
27
78
AE1
C01
511
D87
EF20
3873
2742
73D0
DC9B0
FB2A3
9C011
9B4E0
95DC00
A7B980
F43531
6A6245
5347BE0
1A6C8A1
88E46D6
64CF3AE
D25F63C1
C894E4C3
1C0AFD73
EC1C3F9A
087CE17C0
22149A380
B28038AF1
B9CA21C7F
D78F5307C1
49045489A2
72C4DE6FD1
7713F40D05
EEE8878EEC1
310E62812B1
DA9D5B...

output:

2544281621540
13
268435455
6371842585
63
0
1983
2
268435455
268435455
2719476273
32767
2
2719476273
63
2097151
2509
0
2719476273
6371842585
2097151
32767
32767
3113982
2719476273
502774846
2719476273
2719476273
2719476273
64360
268435455
2719476273
32767
2097151
2719476273
6371842585
63
63
115
20971...

result:

wrong answer 1st numbers differ - expected: '281603732', found: '2544281621540'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%