QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#139657#5407. 基础图论练习题1kri#0 702ms105644kbC++142.2kb2023-08-14 09:33:062024-07-04 01:41:42

Judging History

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

  • [2024-07-04 01:41:42]
  • 评测
  • 测评结果:0
  • 用时:702ms
  • 内存:105644kb
  • [2023-08-14 09:33:06]
  • 提交

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];
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 get_ans(){
	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];
		if (ch[i]==0)ans++;
	}
	return ans;
} 
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]++;
		}
		int sum=0;
		for (int i=1;i<=n;i++)
			for (int j=1;j<i;j++){
//				int x=pos[i],y=pos[j];
				int t=pow_2[(i-2)*(i-1)/2+j-1];
				a[i][j]^=1,a[j][i]^=1;
				sum=(sum+1ll*t*get_ans())%mod;
				a[i][j]^=1,a[j][i]^=1;
//				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
Runtime Error

Test #1:

score: 20
Accepted
time: 696ms
memory: 105644kb

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
285212672
371842543
84
0
1983
2
268505087
268435455
719476515
32785
2
719476771
123
2621567
2523
0
719476275
371842543
2097159
41087
34815
3113984
719478307
502774846
719476267
719476259
719476259
65224
268697613
719477283
36863
2171007
719476259
371842543
120
84
219
5769215
268435455
1...

result:

ok 10000 numbers

Test #2:

score: 0
Accepted
time: 702ms
memory: 104892kb

input:

10000
100
0
2
1
8
41
F2
30
30
F60
7D2
605
024
E910
45F3
3CB0
3B88
0FE21
A7DF3
3B162
70D7A
70B9C1
DFB731
883B33
930FC6
4F8BEC1
CC73551
1A344F3
88966C9
3879FE20
93839630
B6C3FF85
F6D5F7B1
F757DCB20
63C3512A3
9BFD99935
ED1E4F248
ECAB4DA041
EA5CE54511
EA07C72263
F8ADE1FD8C
B220226E1F0
34F274277A0
4A1A14...

output:

281603732
2097151
0
144
268443647
32767
2097151
2
19
903009902
0
268435455
1103
1099
268501119
719476259
17
574715508
0
268435455
321515202
1023
745417303
84
2097151
371842543
301989887
272629791
268435455
153406
0
719476531
2
3368
132695
0
402653183
268435455
371842543
0
0
17
719476259
371842543
23...

result:

ok 10000 numbers

Test #3:

score: -20
Runtime Error

input:

10000
100
1
0
3
7
11
C1
71
1A
C01
E43
237
9B5
33C1
0DE3
7C74
B042
38E60
65480
1D103
862A7
B2DA80
C63273
CF8AD3
AFBDC2
2816D11
1B12351
1869CC5
6BC6DB3
50E5FAB1
4E291CB2
4DF82716
0D410C3E
FD4B31250
8BF2C54A0
1266235D1
757755C58
724DFD1960
F6D1285122
281CDE0BB1
5EF924A6A9
786A08B90C1
BE8C674EE52
B9EFA2...

output:


result:


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%