QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#184898 | #5407. 基础图论练习题 | YuJiahe | 0 | 97ms | 105192kb | C++23 | 2.0kb | 2023-09-21 14:07:50 | 2023-09-21 14:07:50 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int S=5005,p=1000000007;
int pw2[S*S];
int n;
char tmp[S];
int f[S][S],a[S];
int id[S],pos[S],lb[S],rb[S];
int b[S],sm0[S],sm1[S],sm2[S];
inline void add(int &x,int y)
{
x+=y;
if(x>=p) x-=p;
}
inline void slove()
{
scanf("%d",&n);
for(int i=2;i<=n;i++)
{
scanf("%s",tmp+1);
for(int j=1;j<=(i-1)/4+!!((i-1)%4);j++)
{
if(tmp[j]>='A'&&tmp[j]<='F') tmp[j]=tmp[j]-'A'+10;
else tmp[j]-='0';
f[i][j*4-3+0]=tmp[j]&1,tmp[j]>>=1;
f[i][j*4-3+1]=tmp[j]&1,tmp[j]>>=1;
f[i][j*4-3+2]=tmp[j]&1,tmp[j]>>=1;
f[i][j*4-3+3]=tmp[j]&1,tmp[j]>>=1;
}
}
for(int i=1;i<=n;i++)
{
a[i]=0;
for(int j=1;j<=i-1;j++) a[i]+=f[i][j];
for(int j=i+1;j<=n;j++) a[i]+=1-f[j][i];
}
for(int i=1;i<=n;i++) id[i]=i;
sort(id+1,id+n+1,[&](int x,int y){return a[x]<a[y];});
for(int i=1;i<=n;i++) pos[id[i]]=i;
for(int i=1;i<=n;i++)
{
if(i>1&&a[id[i]]==a[id[i-1]]) lb[i]=lb[i-1];
else lb[i]=i;
}
for(int i=n;i>=1;i--)
{
if(i<n&&a[id[i]]==a[id[i+1]]) rb[i]=rb[i+1];
else rb[i]=i;
}
for(int i=1;i<=n;i++) b[i]=b[i-1]+a[id[i]];
for(int i=1;i<=n;i++) b[i]-=i*(i-1)/2;
for(int i=1;i<=n;i++)
{
sm0[i]=sm0[i-1]+(b[i]==0);
sm1[i]=sm1[i-1]+(b[i]==1);
sm2[i]=sm2[i-1]+(b[i]==-1);
}
// for(int i=1;i<=n;i++) printf("%d %d %d\n",id[i],a[id[i]],b[i]);
int ans=0;
for (int i = n, tmp, l, r;i >= 2;i --){
for (int j = i - 1;j >= 1;j --){
if (f[i][j]) swap(i, j);
tmp = sm0[n], l = rb[pos[i]], r = lb[pos[j]];
if (a[l] + 1 == a[r]) goto Calc;
if (l < r) tmp += sm1[r - 1] - sm1[l - 1] - sm0[r - 1] + sm0[l - 1];
else tmp += sm2[l - 1] - sm2[r - 1] - sm0[l - 1] + sm0[r - 1];
Calc: ans = (ans * 2ll + tmp) % p;
if (f[j][i]) swap(i, j);
}
}
printf("%d\n",ans);
}
int main()
{
pw2[0]=1;
for(int i=1;i<=S*S-3;i++) pw2[i]=2ll*pw2[i-1]%p;
int T;
scanf("%d",&T);
while(T-->0) slove();
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: 97ms
memory: 105192kb
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 12 272968363 371842543 107 0 3930 2 408846484 268435455 753572067 36045 1 883737157 98 2654228 1997 0 884007997 371842543 2359295 40960 32767 3147847 260607153 536870846 719747107 719476259 719476259 105882 480595209 310473700 60415 7289263 719476259 371842543 85 63 115 2337074 268435455 1...
result:
wrong answer 2nd numbers differ - expected: '13', found: '12'
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%