QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#86639 | #5407. 基础图论练习题 | themoon | 0 | 10ms | 1872kb | C++14 | 3.4kb | 2023-03-10 14:35:53 | 2023-03-10 14:35:53 |
Judging History
answer
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=5005;
const int Mod=1e9+7;
int n;
bool vis[N][N];
inline int Read(){
char ch;
int f=1;
while((ch=getchar())<'0'||ch>'9')
if(ch=='-') f=-1;
int x=ch^48;
while((ch=getchar())>='0'&&ch<='9')
x=(x<<3)+(x<<1)+(ch^48);
return x*f;
}
inline void print(int x){
if(x>=10) print(x/10);
putchar(x%10+48);
return ;
}
inline void Print(int x,char ch='\n'){
if(x<0){
putchar('-');
print(-x);
}
else print(x);
putchar(ch);
return ;
}
inline int Get(char ch){
if(ch>='0'&&ch<='9') return ch-'0';
if(ch>='A'&&ch<='F') return ch-'A'+10;
return -1;
}
int deg[N];
inline void Init(){
n=Read();
for(int i=1;i<=n;i++)
deg[i]=0;
for(int i=2;i<=n;i++){
for(int j=1;j<=(i-1+3)/4;j++){
char ch;
while((ch=getchar())&&Get(ch)==-1);
for(int k=0;k<=3;k++){
if(4*j+k-3>=i) break ;
vis[i][4*j+k-3]=Get(ch)&(1<<k);
vis[4*j+k-3][i]=vis[i][4*j+k-3]^1;
}
}
}
/*for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
printf("i=%d j=%d %d\n",i,j,vis[i][j]);*/
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(vis[i][j]) deg[j]++;
return ;
}
inline int Max(int x,int y){
return x>y?x:y;
}
inline int Min(int x,int y){
return x<y?x:y;
}
inline void Cmax(int&x,int y){
if(y>x) x=y;
return ;
}
inline void Cmin(int&x,int y){
if(y<x) x=y;
return ;
}
int mn[N],mx[N],id[N];
int pre[N],suf[N];
int add[N],sub[N];
inline bool Cmp(int x,int y){
return deg[x]<deg[y];
}
inline void GetAns(){
for(int i=0;i<=n-1;i++)
mn[i]=n+1,mx[i]=0;
for(int i=1;i<=n;i++)
id[i]=i;
sort(id+1,id+n+1,Cmp);
int tot=0,cnt=0;
for(int i=1;i<=n;i++){
Cmax(mx[deg[id[i]]],i);
Cmin(mn[deg[id[i]]],i);
tot+=deg[id[i]];
cnt++;
pre[i]=suf[i]=(tot==cnt*(cnt-1)/2);
add[i]=(tot+1==cnt*(cnt-1)/2);
sub[i]=(tot-1==cnt*(cnt-1)/2);
}
for(int i=1;i<=n;i++)
pre[i]+=pre[i-1];
suf[n+1]=0;
for(int i=n;i;i--)
suf[i]+=suf[i+1];
for(int i=1;i<=n;i++){
add[i]+=add[i-1];
sub[i]+=sub[i-1];
}
return ;
}
inline int GetAdd(int ll,int rr){
return add[rr]-add[ll-1];
}
inline int GetSub(int ll,int rr){
return sub[rr]-sub[ll-1];
}
//u++,v--
inline int Query(int u,int v){
if(deg[u]<=deg[v]){
if(deg[u]+1==deg[v]) return pre[n];
if(deg[u]==deg[v]){
int idu=mx[deg[u]];
int idv=mn[deg[v]];
return pre[idv-1]+suf[idu]+GetSub(idv,idu-1);
}
int idu=mx[deg[u]];
int idv=mn[deg[v]];
return pre[idu-1]+suf[idv]+GetAdd(idu,idv-1);
}
else{
int idu=mn[deg[u]];
int idv=mx[deg[v]];
return pre[idv-1]+suf[idu]+GetSub(idv,idu-1);
}
}
inline int Quick_Pow(int a,int b){
int ss=1;
for(;b;b>>=1){
if(b&1) ss=1ll*ss*a%Mod;
a=1ll*a*a%Mod;
}
return ss;
}
int ans;
inline void Solve(){
ans=0;
GetAns();
for(int u=1;u<=n;u++){
int pw=Quick_Pow(2,(u-2)*(u-1)/2);
for(int v=1;v<u;v++){
int ss;
if(vis[u][v]) ss=Query(u,v);
else ss=Query(v,u);
ss=1ll*ss*pw%Mod;
ans=(ans+ss)%Mod;
pw=2*pw%Mod;
}
}
return Print(ans);
}
int T;
#include<ctime>
int main(){
//freopen("tournament.in","r",stdin);
//freopen("tournament.out","w",stdout);
//#define LOCAL
#ifdef LOCAL
int st=clock();
#endif
for(T=Read();T;T--){
Init();
Solve();
}
#ifdef LOCAL
int en=clock();
printf("cost %d ms\n",en-st);
#endif
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: 10ms
memory: 1872kb
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 82 0 1983 2 268503039 268435455 719476515 32785 2 719476771 91 2621567 2523 0 719476275 371842543 2097159 41087 34815 3113984 719478307 502774846 719476267 719476259 719476259 64712 268697609 719477283 36863 2154623 719476259 371842543 104 82 219 4720639 268435455 13...
result:
wrong answer 5th numbers differ - expected: '84', found: '82'
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%