QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#184910 | #5407. 基础图论练习题 | YuJiahe | 0 | 104ms | 104244kb | C++23 | 2.0kb | 2023-09-21 14:11:43 | 2023-09-21 14:11:43 |
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[id[l]] + 1 == a[id[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;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 104ms
memory: 104244kb
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 272968235 371842543 63 0 1983 2 408846484 268435455 48539328 33933 2 884007485 63 2656276 2509 0 736524363 371842543 2105903 54291 32916 3147839 723736248 502774846 884008005 719476259 719476259 105360 541412105 377590756 60415 7092655 719476259 371842543 63 63 115 2335281 268435455 13 ...
result:
wrong answer 3rd numbers differ - expected: '285212672', found: '272968235'
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%