QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#648890 | #5407. 基础图论练习题 | little_pinkpig | 0 | 8ms | 7968kb | C++14 | 2.3kb | 2024-10-17 20:51:17 | 2024-10-17 20:51:17 |
answer
#include<bits/stdc++.h>
#define MAXN (5005)
#define ll long long
using namespace std;
const int mod=1000000007;
void File()
{
freopen(".in","r",stdin);
freopen(".out","w",stdout);
}
template<typename type>
void read(type &x)
{
bool f=0;char ch=0;x=0;
while(ch<'0'||ch>'9'){f|=!(ch^'-');ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
x=f?-x:x;
}
template<typename type,typename... Args>
void read(type &x,Args &... args)
{
read(x);
read(args...);
}
bool vis[MAXN][MAXN];
char str[MAXN];
int test,n,s,t,scnt,pw,ans;
int deg[MAXN],sum[MAXN],pre[MAXN][MAXN],posl[MAXN],posr[MAXN];
void solve()
{
read(n);
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) vis[i][j]=0,pre[i][j]=0;
for(int i=0;i<=n;i++) posl[i]=posr[i]=0;
for(int i=2,m;i<=n;i++)
{
scanf("%s",str+1);
m=(i+2)>>1;
for(int j=1,x;j<=m;j++)
{
x=isdigit(str[j])?(str[j]^48):(str[j]-'A'+10);
for(int k=0,p;k<4;k++)
{
p=(j<<2)+k-3;
if(p>=i) break;
if((x>>k)&1) vis[i][p]=1;
else vis[p][i]=1;
}
}
}
for(int i=1;i<=n;i++) deg[i]=0;
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) deg[i]+=vis[i][j];
for(int i=1;i<=n;i++) sum[i]=deg[i];
sort(sum+1,sum+n+1);
scnt=0;
for(int i=1;i<=n;i++)
{
sum[i]+=sum[i-1];
if(sum[i]==i*(i-1)/2) ++scnt;
}
for(int l=1,x,y;l<=n;l++)
{
x=y=scnt;
for(int r=l;r<n;r++)
{
x+=(sum[r]-1==r*(r-1)/2)-(sum[r]==r*(r-1)/2);
y+=(sum[r]+1==r*(r-1)/2)-(sum[r]==r*(r-1)/2);
pre[l][r+1]=x,pre[r+1][l]=x;
}
}
for(int i=n;i;i--) posl[sum[i]-sum[i-1]]=i;
for(int i=1;i<=n;i++) posr[sum[i]-sum[i-1]]=i;
pw=1,ans=0;
for(int i=1,x,y,res;i<=n;i++)
{
for(int j=1;j<i;j++)
{
x=i,y=j;
if(vis[y][x]) swap(x,y);
res=(deg[x]==deg[y]+1)?scnt:pre[posl[deg[x]]][posr[deg[y]]];
ans=(ans+1ll*pw*res)%mod;
pw=2ll*pw%mod;
}
}
printf("%d\n",ans);
}
int main()
{
#ifndef ONLINE_JUDGE
File();
#endif
read(test);
for(int i=1;i<=test;i++) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 8ms
memory: 7968kb
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 289745452 371842543 84 0 1983 2 408916116 268435455 48539584 33951 2 884007997 123 3180692 2523 0 736524379 371842543 2105911 62611 34964 3147841 723738296 502774846 884008013 719476259 719476259 106224 541674263 377591780 64511 7166511 719476259 371842543 120 84 219 6007345 268435455 1...
result:
wrong answer 3rd numbers differ - expected: '285212672', found: '289745452'
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%