QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#648777 | #5407. 基础图论练习题 | lifan | 0 | 10ms | 10400kb | C++14 | 1.5kb | 2024-10-17 20:22:01 | 2024-10-17 20:22:02 |
Judging History
answer
//
/*
https://www.cnblogs.com/xulongkai/p/18007142
*/
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5005,mod=1e9+7;
int T;
int n;
int g[N][N];
int d[N];
int get(char ch){
if('0'<=ch&&ch<='9'){
return ch-'0';
}
return ch-'A'+10;
}
int s[N],siz[N];
int sum[N][2];
int ans;
void solve(){
scanf("%lld",&n);
for(int i=1;i<=n;i++){
d[i]=siz[i]=0;
}
for(int i=2;i<=n;i++){
string s;
cin>>s;
for(int j=0;j<(i+3)/4;j++){
for(int k=0;k<4;k++){
if(j*4+k+1<i){
int x=get(s[j])>>k&1;
g[i][j*4+k+1]=x,g[j*4+k+1][i]=!x;
d[i]+=x,d[j*4+k+1]+=!x;
}
}
}
}
for(int i=1;i<=n;i++){
s[i]=d[i];
siz[d[i]]++;
}
for(int i=1;i<=n;i++){
siz[i]+=siz[i-1];
}
sort(s+1,s+n+1);
for(int i=1;i<=n;i++){
s[i]+=s[i-1];
sum[i][0]=sum[i-1][0]+(s[i]==(i*(i-1)/2));//交换前
sum[i][1]=sum[i-1][1]+(s[i]==(i*(i-1)/2+1));//交换后
}
ans=0;
for(int i=n;i>=1;i--){
for(int j=i-1;j>=1;j--){
int x=i,y=j,res=sum[n][0];
if(g[x][y]){
swap(x,y);
}
if(d[x]>=d[y]){//交换前在同一个强连通分量
res+=(sum[siz[d[x]]-1][1]-sum[siz[d[y]-1]][1]);
}
if(d[x]+1<d[y]){//交换后在同一个强连通分量
res-=(sum[siz[d[y]-1]][0]-sum[siz[d[x]]-1][0]);
}
ans=(ans*2+res)%mod;
}
}
printf("%lld\n",ans);
}
signed main(){
scanf("%lld",&T);
while(T--){
solve();
}
return 0;
}
/*
2
3
0
2
6
1
3
7
F
F1
*/
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: 10400kb
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 266795052 371842543 67 0 7359 2 274305004 266338303 901107579 28174 2 699555017 63 1447744 2726 0 482956837 371842543 2093940 34687 7466 4262014 360656728 308924428 989705702 923440739 718165604 86033 285220919 542113286 32032 3899391 624478288 371842543 63 63 115 2097151 268435455 25 4...
result:
wrong answer 3rd numbers differ - expected: '285212672', found: '266795052'
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%