QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#139683#5407. 基础图论练习题1kri#0 51ms105828kbC++142.7kb2023-08-14 10:24:462024-07-04 01:41:46

Judging History

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

  • [2024-07-04 01:41:46]
  • 评测
  • 测评结果:0
  • 用时:51ms
  • 内存:105828kb
  • [2023-08-14 10:24:46]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define mod 1000000007
using namespace std;
int pow_2[25000005]; 
int t,n,a[5005][5005];
char str[5005];
int pos[5005];
int ch[5005],s0[5005],s1[5005];
int pre[5005],nxt[5005];
vector<int> work(int l,int r){
	if (l==r){
		vector<int> ans;
		ans.push_back(l);
		return ans;
	}
	int mid=(l+r)/2;
	vector<int> cl=work(l,mid),cr=work(mid+1,r);
	vector<int> c;
	int i=0,j=0;
	while(i<(int)cl.size()&&j<(int)cr.size()){
		if (a[cl[i]][cr[j]]==1)c.push_back(cl[i++]);
		else c.push_back(cr[j++]);
	}
	while(i<(int)cl.size())c.push_back(cl[i++]);
	while(j<(int)cr.size())c.push_back(cr[j++]);
	return c;
}
int main(){
	pow_2[0]=1;
	for (int i=1;i<=25000000;i++)pow_2[i]=pow_2[i-1]*2%mod;
	cin>>t;
	while(t--){
		cin>>n;
		for (int i=1;i<n;i++){
			scanf("%s",str+1);
			for (int j=1;j<=(i+3)/4;j++){
				int x=0;
				if (str[j]>='0'&&str[j]<='9')x=str[j]-'0';
				else x=str[j]-'A'+10;
				for (int k=0;k<4&&4*j+k-3<=i;k++){
					a[i+1][4*j+k-3]=((x>>k)&1);
					a[4*j+k-3][i+1]=1-((x>>k)&1);
				}
			}
		}
		vector<int> c=work(1,n);
		for (int i=0;i<n;i++)pos[c[i]]=i;
		memset(ch,0,sizeof(ch));
		for (int i=1;i<=n;i++)
			for (int j=1;j<=n;j++)
				if (a[i][j]==1&&pos[i]>pos[j]){
					ch[pos[j]+1]++;
					ch[pos[i]+1]--;
				}
		int ans=1;
		for (int i=1;i<n;i++){
			ch[i]+=ch[i-1];
			s0[i]=s0[i-1],s1[i]=s1[i-1];
			if (ch[i]==0)s0[i]++,ans++;
			if (ch[i]==1)s1[i]++;
		}
		for (int i=0;i<n;i++){
			pre[i]=nxt[i]=i;
			for (int j=0;j<n;j++){
				if (a[c[i]][c[j]]==1)pre[i]=min(pre[i],j);
				if (a[c[j]][c[i]]==1)nxt[i]=max(nxt[i],j);
			}
		}
		int sum=0;
		for (int i=1;i<=n;i++)
			for (int j=1;j<i;j++){
				int x=pos[i],y=pos[j];
				if (a[i][j]==0)swap(x,y);
				int t=pow_2[(i-2)*(i-1)/2+j-1];
				if (y==x+1){
					int cnt=0;
					int p=x+1;
					int l=-1,r=-1;
					for (int i=x;i>=0;i--){
						if (i<p){
							if (i<x&&l==-1)l=p;
							cnt++;
						}
						p=min(p,pre[i]);
					}
					if (l==-1)l=0;
					p=y-1;
					for (int i=y;i<n;i++){
						if (i>p){
							if (i>y&&r==-1)r=p;
							cnt++;
						}
						p=max(p,nxt[i]);
					}
					if (r==-1)r=n-1;
					int fg=0;
					p=n;
					for (int i=l;i<=x;i++)
						for (int j=y;j<n;j++)
							if ((i!=x||j!=y)&&a[c[i]][c[j]]==1){
								if (j<=r)fg=1;
								p=min(p,j);
							}
					for (int i=p;i<n;i++)
						if (pre[i]<=x)fg=1;
					if (fg==0)sum=(sum+1ll*t*cnt)%mod;
					else sum=(sum+1ll*t*(ans-(s0[y]-s0[x])))%mod;
				}
				else{
					if (x<y)sum=(sum+1ll*t*(ans-(s0[y]-s0[x])))%mod;
					else sum=(sum+1ll*t*(ans+(s1[x]-s1[y])))%mod;
				}
			}
		cout<<sum<<endl;
	}
	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: 51ms
memory: 105828kb

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
352321535
371842543
88
0
1983
2
268439551
268435455
719476515
32847
2
719477283
123
2621567
2523
0
719476259
371842543
2097159
41087
34815
3113988
719478307
502774846
719476275
719476259
719476259
65224
269484043
719477283
36863
2236543
719476259
371842543
183
116
219
5249023
268435455
...

result:

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

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%