QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#185897 | #5407. 基础图论练习题 | leexzq | 0 | 103ms | 104412kb | C++14 | 2.2kb | 2023-09-22 19:24:57 | 2023-09-22 19:24:57 |
Judging History
answer
//I play to win
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pi pair<int,int>
#define ld long double
#define vi vector<int>
#define all(x) begin(x),end(x)
using namespace std;
inline ll read()
{
ll x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
for(;isdigit(c);c=getchar())x=(x<<3)+(x<<1)+(c^48);
return x*f;
}
inline void out(ll x){if(x>9)out(x/10);putchar(x%10^48);}
inline void print(ll x,char c='\n'){if(x<0)putchar('-'),x=-x;out(x),putchar(c);}
const int N=5005,p=1e9+7;
char str[N];
int e[N][N],d[N],id[N],s[N],pw[N*N],suf[N],pre[N],c1[N],c2[N];
void solve()
{
int n=read();ll ans=0;
for(int i=1;i<=n;i++)d[i]=c1[i]=c2[i]=0,id[i]=i,memset(e[i]+1,0,n<<2);
for(int i=1;i<n;i++)
{
scanf("%s",str+1);
for(int j=1;j<=(i+3)/4;j++)
{
int v=(str[j]<='9')?(str[j]-'0'):(str[j]-'A'+10);
for(int k=0;k<4;k++)
{
int x=i+1,y=4*j+k-3;
if(y>=x)continue;
if(v>>k&1^1)swap(x,y);
e[x][y]=1,d[x]++;
}
}
}
sort(id+1,id+n+1,[&](int x,int y){return d[x]<d[y];});
for(int i=1;i<=n;c1[i]+=c1[i-1],c2[i]+=c2[i-1],i++)
if((s[i]=d[id[i]]+s[i-1])==i*(i-1)/2)c1[i]++;
else if(s[i]+1==i*(i-1)/2)c2[i]++;
pre[1]=1,suf[n]=n;
for(int i=2;i<=n;i++)pre[i]=(d[id[i]]==d[id[i-1]])?pre[i-1]:i;
for(int i=n-1;i;i--)suf[i]=(d[id[i]]==d[id[i+1]])?suf[i+1]:i;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
int x=id[i],y=id[j];
if(e[x][y])
{
ll res=c1[n];
if(d[x]!=d[y]+1)
{
int l=pre[i],r=suf[j];
assert(l!=r);
if(l<r)res+=c2[r-1]-c2[l-1];
else res-=c1[l-1]-c1[r-1];
}
if(x<y)swap(x,y);
(ans+=pw[(x-2)*(x-1)/2+y-1]*res%p)%=p;
}
}
print(ans);
}
int main()
{
pw[0]=1;
for(int i=1;i<N*N;i++)pw[i]=pw[i-1]*2%p;
int T=read();
while(T--)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: 103ms
memory: 104412kb
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 268435455 371842543 63 0 1983 2 268435455 268435455 719476259 32767 2 719476259 63 2097151 2509 0 719476259 371842543 2097151 32767 32767 3113982 719476259 502774846 719476259 719476259 719476259 64360 268435455 719476259 32767 2097151 719476259 371842543 63 63 115 2097151 268435455 13 ...
result:
wrong answer 3rd numbers differ - expected: '285212672', found: '268435455'
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%