QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#182982#5407. 基础图论练习题lovely_ckj0 106ms104864kbC++142.3kb2023-09-18 20:11:152023-09-18 20:11:16

Judging History

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

  • [2023-09-18 20:11:16]
  • 评测
  • 测评结果:0
  • 用时:106ms
  • 内存:104864kb
  • [2023-09-18 20:11:15]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

const int S=5005,p=1000000007;

int pw2[S*S];
int n;
char tmp[S];
int f[S][S],a[S];
int id[S],pos[S],lb[S],rb[S];
int b[S],sm0[S],sm1[S],sm2[S];

inline void add(int &x,int y)
{
	x+=y;
	if(x>=p) x-=p;
}

inline void slove()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
		scanf("%s",tmp+1);
		for(int j=1;j<=(i-1)/4+!!((i-1)%4);j++)
		{
			if(tmp[j]>='A'&&tmp[j]<='F') tmp[j]=tmp[j]-'A'+10;
			else tmp[j]-='0';
			f[i][j*4-3+0]=tmp[j]&1,tmp[j]>>=1;
			f[i][j*4-3+1]=tmp[j]&1,tmp[j]>>=1;
			f[i][j*4-3+2]=tmp[j]&1,tmp[j]>>=1;
			f[i][j*4-3+3]=tmp[j]&1,tmp[j]>>=1;
		}
		// for(int j=1;j<=i-1;j++)
		// {
			// if(f[i][j]==1) printf("%d -> %d\n",i,j);
			// else printf("%d -> %d\n",j,i);
		// }
	}
	for(int i=1;i<=n;i++) a[i]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=i-1;j++) a[i]+=f[i][j];
		for(int j=i+1;j<=n;j++) a[i]+=1-f[j][i];
	}
	for(int i=1;i<=n;i++) id[i]=i;
	sort(id+1,id+n+1,[&](int x,int y){return a[x]<a[y];});
	for(int i=1;i<=n;i++) pos[id[i]]=i;
	for(int i=1;i<=n;i++)
	{
		if(i>1&&a[id[i]]==a[id[i-1]]) lb[i]=lb[i-1];
		else lb[i]=i;
	}
	for(int i=n;i>=1;i--)
	{
		if(i<n&&a[id[i]]==a[id[i+1]]) rb[i]=rb[i+1];
		else rb[i]=i;
	}
	for(int i=1;i<=n;i++) b[i]=b[i-1]+a[id[i]];
	for(int i=1;i<=n;i++) b[i]-=i*(i-1)/2;
	for(int i=1;i<=n;i++)
	{
		sm0[i]=sm0[i-1]+(b[i]==0);
		sm1[i]=sm1[i-1]+(b[i]==1);
		sm2[i]=sm2[i-1]+(b[i]==-1);
	}
	// for(int i=1;i<=n;i++) printf("%d %d %d\n",id[i],a[id[i]],b[i]);
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=i-1;j++)
		{
			int pre;
			if(abs(a[i]-a[j])==1) pre=sm0[n];
			else
			{
				int l,r; // l:-1  r:+1
				if(f[i][j]==1) l=lb[pos[i]],r=rb[pos[j]];
				else r=rb[pos[i]],l=lb[pos[j]];
				if(l<r)
				{
					r--;
					// printf("- [%d %d]\n",l,r);
					pre=sm0[n]-(sm0[r]-sm0[l-1])+(sm1[r]-sm1[l-1]);
				}
				else
				{
					swap(l,r);
					r--;
					// printf("+ [%d %d]\n",l,r);
					pre=sm0[n]-(sm0[r]-sm0[l-1])+(sm2[r]-sm2[l-1]);
				}
			}
			// printf("%d %d %d\n",j,i,pre);
			add(ans,1ll*pre*pw2[(i-2)*(i-1)/2+j-1]%p);
		}
	}
	printf("%d\n",ans);
}

int main()
{
	pw2[0]=1;
	for(int i=1;i<=S*S-3;i++) pw2[i]=2ll*pw2[i-1]%p;
	int T;
	scanf("%d",&T);
	while(T-->0) slove();
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 106ms
memory: 104864kb

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:

281603732
13
285212671
371842543
81
0
1983
2
268505087
268435455
719476515
32767
2
719476771
75
2621439
2523
0
719476259
371842543
2097159
32767
32767
3113984
719476259
502774846
719476259
719476259
719476259
64456
268435469
719477283
32767
2105471
719476259
371842543
96
81
219
5244927
268435455
13
...

result:

wrong answer 3rd numbers differ - expected: '285212672', found: '285212671'

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%