QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#139674 | #5407. 基础图论练习题 | 1kri# | 0 | 115ms | 104288kb | C++14 | 2.6kb | 2023-08-14 10:07:48 | 2024-07-04 01:41:43 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define mod 1000000007
using namespace std;
int pow_2[25000005];
int t,n,a[5005][5005];
char str[5005];
int pos[5005];
int ch[5005],s0[5005],s1[5005];
int pre[5005],nxt[5005];
vector<int> work(int l,int r){
if (l==r){
vector<int> ans;
ans.push_back(l);
return ans;
}
int mid=(l+r)/2;
vector<int> cl=work(l,mid),cr=work(mid+1,r);
vector<int> c;
int i=0,j=0;
while(i<(int)cl.size()&&j<(int)cr.size()){
if (a[cl[i]][cr[j]]==1)c.push_back(cl[i++]);
else c.push_back(cr[j++]);
}
while(i<(int)cl.size())c.push_back(cl[i++]);
while(j<(int)cr.size())c.push_back(cr[j++]);
return c;
}
int main(){
pow_2[0]=1;
for (int i=1;i<=25000000;i++)pow_2[i]=pow_2[i-1]*2%mod;
cin>>t;
while(t--){
cin>>n;
for (int i=1;i<n;i++){
scanf("%s",str+1);
for (int j=1;j<=(i+3)/4;j++){
int x=0;
if (str[j]>='0'&&str[j]<='9')x=str[j]-'0';
else x=str[j]-'A'+10;
for (int k=0;k<4&&4*j+k-3<=i;k++){
a[i+1][4*j+k-3]=((x>>k)&1);
a[4*j+k-3][i+1]=1-((x>>k)&1);
}
}
}
vector<int> c=work(1,n);
for (int i=0;i<n;i++)pos[c[i]]=i;
memset(ch,0,sizeof(ch));
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
if (a[i][j]==1&&pos[i]>pos[j]){
ch[pos[j]+1]++;
ch[pos[i]+1]--;
}
int ans=1;
for (int i=1;i<n;i++){
ch[i]+=ch[i-1];
s0[i]=s0[i-1],s1[i]=s1[i-1];
if (ch[i]==0)s0[i]++,ans++;
if (ch[i]==1)s1[i]++;
}
for (int i=0;i<n;i++){
pre[i]=nxt[i]=i;
for (int j=0;j<n;j++){
if (a[c[i]][c[j]]==1)pre[i]=min(pre[i],j);
if (a[c[j]][c[i]]==1)nxt[i]=max(nxt[i],j);
}
}
int sum=0;
for (int i=1;i<=n;i++)
for (int j=1;j<i;j++){
int x=pos[i],y=pos[j];
if (a[i][j]==0)swap(x,y);
int t=pow_2[(i-2)*(i-1)/2+j-1];
if (y==x+1){
int cnt=0;
int p=x+1;
int l=-1,r=-1;
for (int i=x;i>=0;i--){
if (i<p){
if (i<x&&l==-1)l=p;
cnt++;
}
p=min(p,pre[i]);
}
if (l==-1)l=0;
p=y-1;
for (int i=y;i<n;i++){
if (i>p){
if (i>y&&r==-1)r=p;
cnt++;
}
p=max(p,nxt[i]);
}
if (r==-1)r=n-1;
int fg=0;
for (int i=l;i<=x;i++)
for (int j=y;j<=r;j++)
if (i!=x&&j!=y&&a[c[i]][c[j]]==1)fg=1;
if (fg==0)sum=(sum+1ll*t*cnt)%mod;
else sum=(sum+1ll*t*(ans-(s0[y]-s0[x])))%mod;
}
else{
if (x<y)sum=(sum+1ll*t*(ans-(s0[y]-s0[x])))%mod;
else sum=(sum+1ll*t*(ans+(s1[x]-s1[y])))%mod;
}
}
cout<<sum<<endl;
}
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: 115ms
memory: 104288kb
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:
375809602 13 486576194 973634635 120 0 1983 2 377720863 524325479 877681988 51797 2 259873983 153 3673231 2587 0 397085772 992807247 2935591 59041 54087 4164772 704656295 788040854 108100608 31113654 381477913 69664 288903185 981833299 54360 2286223 744745226 199410269 198 148 227 8398024 279990272 ...
result:
wrong answer 1st numbers differ - expected: '281603732', found: '375809602'
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%