QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#86628#5407. 基础图论练习题themoon0 6ms1668kbC++143.4kb2023-03-10 14:32:432023-03-10 14:32:47

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-10 14:32:47]
  • 评测
  • 测评结果:0
  • 用时:6ms
  • 内存:1668kb
  • [2023-03-10 14:32:43]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=5005;
const int Mod=1e9+7;
int n;
bool vis[N][N];
inline int Read(){
	char ch;
	int f=1;
	while((ch=getchar())<'0'||ch>'9')
		if(ch=='-') f=-1;
	int x=ch^48;
	while((ch=getchar())>='0'&&ch<='9')
		x=(x<<3)+(x<<1)+(ch^48);
	return x*f;
}
inline void print(int x){
	if(x>=10) print(x/10);
	putchar(x%10+48);
	return ;
}
inline void Print(int x,char ch='\n'){
	if(x<0){
		putchar('-');
		print(-x);
	}
	else print(x);
	putchar(ch);
	return ;
}
inline int Get(char ch){
	if(ch>='0'&&ch<='9') return ch-'0';
	if(ch>='A'&&ch<='F') return ch-'A'+10;
	return -1;
}
int deg[N];
inline void Init(){
	n=Read();
	for(int i=1;i<=n;i++)
		deg[i]=0;
	for(int i=2;i<=n;i++){
		for(int j=1;j<=(i-1+3)/4;j++){
			char ch;
			while((ch=getchar())&&Get(ch)==-1);
			for(int k=0;k<=3;k++){
				if(4*j+k-3>=i) break ;
				vis[i][4*j+k-3]=Get(ch)&(1<<k);
				vis[4*j+k-3][i]=vis[i][4*j+k-3]^1;
			}
		}
	}
	/*for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			printf("i=%d j=%d %d\n",i,j,vis[i][j]);*/
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(vis[i][j]) deg[j]++;
	return ;
}
inline int Max(int x,int y){
	return x>y?x:y;
}
inline int Min(int x,int y){
	return x<y?x:y;
}
inline void Cmax(int&x,int y){
	if(y>x) x=y;
	return ;
}
inline void Cmin(int&x,int y){
	if(y<x) x=y;
	return ;
}
int mn[N],mx[N],id[N];
int pre[N],suf[N];
int add[N],sub[N];
inline bool Cmp(int x,int y){
	return deg[x]<deg[y];
}
inline void GetAns(){
	for(int i=0;i<=n-1;i++)
		mn[i]=n+1,mx[i]=0;
	for(int i=1;i<=n;i++)
		id[i]=i;
	sort(id+1,id+n+1,Cmp);
	int tot=0,cnt=0;
	for(int i=1;i<=n;i++){
		Cmax(mx[deg[id[i]]],i);
		Cmin(mn[deg[id[i]]],i);
		tot+=deg[id[i]];
		cnt++;
		pre[i]=suf[i]=(tot==cnt*(cnt-1)/2);
		add[i]=(tot==cnt*(cnt-1)/2+1);
		sub[i]=(tot==cnt*(cnt-1)/2-1);
	}
	for(int i=1;i<=n;i++)
		pre[i]+=pre[i-1];
	suf[n+1]=0;
	for(int i=n;i;i--)
		suf[i]+=suf[i+1];
	for(int i=1;i<=n;i++){
		add[i]+=add[i-1];
		sub[i]+=sub[i-1];
	}
	return ;
}
inline int GetAdd(int ll,int rr){
	return add[rr]-add[ll-1];
}
inline int GetSub(int ll,int rr){
	return sub[rr]-sub[ll-1];
}
//u++,v--
inline int Query(int u,int v){
	if(deg[u]<=deg[v]){
		if(deg[u]+1==deg[v]) return pre[n];
		if(deg[u]==deg[v]){
			int idu=mx[deg[u]];
			int idv=mn[deg[v]];
			return pre[idv-1]+suf[idu]+GetSub(idv,idu-1);
		}
		int idu=mx[deg[u]];
		int idv=mn[deg[v]];
		return pre[idu-1]+suf[idv]+GetAdd(idu,idv-1);
	}
	else{
		int idu=mn[deg[u]];
		int idv=mx[deg[v]];
		return pre[idv-1]+suf[idu]+GetSub(idv,idu-1);
	}
}
inline int Quick_Pow(int a,int b){
	int ss=1;
	for(;b;b>>=1){
		if(b&1) ss=1ll*ss*a%Mod;
		a=1ll*a*a%Mod;
	}
	return ss;
}
int ans;
inline void Solve(){
	ans=0;
	GetAns();
	for(int u=1;u<=n;u++){
		int pw=Quick_Pow(2,(u-2)*(u-1)/2);
		for(int v=1;v<u;v++){
			int ss;
			if(vis[u][v]) ss=Query(u,v);
			else ss=Query(v,u);
			ss=1ll*ss*pw%Mod;
			ans=(ans+ss)%Mod;
			pw=2*pw%Mod;
		}
	}
	return Print(ans);
}
int T;
#include<ctime>
int main(){
	//freopen("tournament.in","r",stdin);
	//freopen("tournament.out","w",stdout);
	//#define LOCAL
	#ifdef LOCAL
	int st=clock();
	#endif
	for(T=Read();T;T--){
		Init();
		Solve();
	}
	#ifdef LOCAL
	int en=clock();
	printf("cost %d ms\n",en-st);
	#endif
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 1668kb

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
272968235
371842543
63
0
1983
2
408846484
268435455
48539328
33933
2
884007485
63
2656276
2509
0
736524363
371842543
2105903
54291
32916
3147839
723736248
502774846
884008005
719476259
719476259
105360
541412105
377590756
60415
7092655
719476259
371842543
63
63
115
2335281
268435455
13
...

result:

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

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%