QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#139703 | #5407. 基础图论练习题 | 1kri# | 40 | 273ms | 112232kb | C++14 | 2.9kb | 2023-08-14 11:06:19 | 2024-07-04 01:41:52 |
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];
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;
}
namespace Brute{
int m,u[100005],v[100005],first[100005],nxt[100005];
void add_edge(int a,int b){
int i=++m;
u[i]=a,v[i]=b;
nxt[i]=first[u[i]],first[u[i]]=i;
return;
}
int idx,dfn[100005],low[100005];
int tot,sta[100005],in_sta[100005];
int col_tot;
void init(){
m=0;
for (int i=1;i<=n;i++)first[i]=dfn[i]=low[i]=in_sta[i]=0;
idx=tot=col_tot=0;
return;
}
void dfs(int now){
sta[++tot]=now;
in_sta[now]=1;
dfn[now]=low[now]=++idx;
for (int i=first[now];i;i=nxt[i]){
if (dfn[v[i]]==0)dfs(v[i]),low[now]=min(low[now],low[v[i]]);
else if (in_sta[v[i]]==1)low[now]=min(low[now],dfn[v[i]]);
}
if (dfn[now]==low[now]){
++col_tot;
while(sta[tot]!=now)in_sta[sta[tot--]]=0;
in_sta[sta[tot--]]=0;
}
return;
}
int work(){
for (int i=1;i<=n;i++)
if (dfn[i]==0)dfs(i);
return col_tot;
}
}
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]++;
}
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){
Brute::init();
a[i][j]^=1,a[j][i]^=1;
for (int k=1;k<=n;k++)
for (int l=1;l<=n;l++)
if (a[k][l]==1)Brute::add_edge(k,l);
sum=(sum+1ll*t*Brute::work())%mod;
a[i][j]^=1,a[j][i]^=1;
}
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: 20
Accepted
Test #1:
score: 20
Accepted
time: 102ms
memory: 107800kb
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 84 0 1983 2 268505087 268435455 719476515 32785 2 719476771 123 2621567 2523 0 719476275 371842543 2097159 41087 34815 3113984 719478307 502774846 719476267 719476259 719476259 65224 268697613 719477283 36863 2171007 719476259 371842543 120 84 219 5769215 268435455 1...
result:
ok 10000 numbers
Test #2:
score: 0
Accepted
time: 123ms
memory: 108004kb
input:
10000 100 0 2 1 8 41 F2 30 30 F60 7D2 605 024 E910 45F3 3CB0 3B88 0FE21 A7DF3 3B162 70D7A 70B9C1 DFB731 883B33 930FC6 4F8BEC1 CC73551 1A344F3 88966C9 3879FE20 93839630 B6C3FF85 F6D5F7B1 F757DCB20 63C3512A3 9BFD99935 ED1E4F248 ECAB4DA041 EA5CE54511 EA07C72263 F8ADE1FD8C B220226E1F0 34F274277A0 4A1A14...
output:
281603732 2097151 0 144 268443647 32767 2097151 2 19 903009902 0 268435455 1103 1099 268501119 719476259 17 574715508 0 268435455 321515202 1023 745417303 84 2097151 371842543 301989887 272629791 268435455 153406 0 719476531 2 3368 132695 0 402653183 268435455 371842543 0 0 17 719476259 371842543 23...
result:
ok 10000 numbers
Test #3:
score: 0
Accepted
time: 106ms
memory: 109480kb
input:
10000 100 1 0 3 7 11 C1 71 1A C01 E43 237 9B5 33C1 0DE3 7C74 B042 38E60 65480 1D103 862A7 B2DA80 C63273 CF8AD3 AFBDC2 2816D11 1B12351 1869CC5 6BC6DB3 50E5FAB1 4E291CB2 4DF82716 0D410C3E FD4B31250 8BF2C54A0 1266235D1 757755C58 724DFD1960 F6D1285122 281CDE0BB1 5EF924A6A9 786A08B90C1 BE8C674EE52 B9EFA2...
output:
281603732 371842549 371842543 268435459 1281 371842543 719476259 371842543 84 60934 108 2 268435455 108 1159 108 2097663 2 371842543 719476259 2 371842543 1536 7288681 269746175 371842543 268435463 2 371842543 0 899345324 84 1183 0 19 93 371842543 21 21 21 1152 371842543 780828798 268435455 71947625...
result:
ok 10000 numbers
Test #4:
score: 0
Accepted
time: 122ms
memory: 108124kb
input:
10000 100 0 0 1 3 D1 D0 B4 DD 940 C13 2C3 62A E900 2FC1 2470 E6EE 80151 912A3 CADA5 7F6D3 0CB410 E17771 686F85 68DFEE FABD991 150D7A2 90C8247 5B06F87 46894CE0 42575142 BC2873D5 8F1E0A9C D26EDC921 30F8DCAA2 6ECD63697 C739CFD42 631139F800 A57ED99C72 20B0B17882 347727E7CA E619F1E8A91 1DC6F46E610 01C38C...
output:
281603732 21 371842543 2 102 102 0 268435455 1536 17 719476259 2 2 371842543 2621443 32767 2 21 371842543 189 719476259 1035 1087 2097151 0 719476259 2 2 268435455 0 21 144 719476259 2 1023 32767 2097151 32775 719476259 371842543 0 36863 21 2097151 2 32767 268435455 2 32768 180 21 123 371842543 93 3...
result:
ok 10000 numbers
Test #5:
score: 0
Accepted
time: 119ms
memory: 106488kb
input:
10000 100 1 3 3 C A1 A2 96 AA 9D1 A01 C16 EDD 2560 D652 0990 0630 1CCF0 6FCD0 FF216 A1AE4 733020 7287D3 E64A46 ADA8C2 AD3E2A0 02BC872 6D92D01 05C5759 33F30180 D42829D1 42734D77 01C7FE14 047CF2770 AE654B450 8C50339E5 AABDF020C 92316BB5E0 4E2EA0A9E2 3C962A0C27 9956ED19E9 458EFDCCCC0 0B1BC934520 5B83A4...
output:
281603732 21 2359295 719476259 105 0 268435455 2113543 33023 21 2 0 0 32847 2097151 405396975 21 371842543 2162687 268435455 84 371842543 105 32767 3343 268435455 371842543 719476259 0 32895 2 719476259 21 2 21 21 21 21 21 21 21 171 2621439 268959743 2113791 108 2 32767 268435487 268435463 32840 78 ...
result:
ok 10000 numbers
Test #6:
score: 0
Accepted
time: 124ms
memory: 106464kb
input:
10000 100 1 3 0 7 D1 82 10 3D E60 EE2 0B1 5A5 10C0 B543 0AD3 1390 45750 C6830 0EAB5 B2D55 FF2090 503CC2 0BB701 EB004B 3FDD210 17A52F1 44B5255 7418726 75843761 150CEF50 F20F26E6 8FBBA768 D24A5D161 AA31E8A90 373E9FE24 D32AA0A0A F4C90F3500 6C36C6F8C3 726D14EF35 CFC549657E 10803BE30D1 4DF734243E0 FF192B...
output:
281603732 0 2375679 21 21 2097151 2098207 21 2 2097151 0 0 2 84 0 32767 268435455 2 21 2097279 1040 2 268435455 93 2097151 2097151 105 719476259 2170879 36863 268435455 371842543 268435455 719476259 719476259 102 0 371842543 2 21 1535 1025 21 371842543 2 371842543 0 371842543 21 1033 21 371842543 17...
result:
ok 10000 numbers
Subtask #2:
score: 20
Accepted
Dependency #1:
100%
Accepted
Test #7:
score: 20
Accepted
time: 241ms
memory: 112128kb
input:
10000 300 1 0 5 7 B1 C2 26 32 DA0 243 682 E2E D4B1 DFD3 60C3 4D66 826E1 D8511 AFC36 254F4 EC8F70 F5B480 7DEA20 06DF55 3EA08A1 C6B5463 C9B2C45 544D18E 2693C7C0 31E27182 D31059D1 BE767720 AC55C6D80 A21839A80 AE17E0DD6 772EF61A9 66EE846D51 B19BE410D0 03A8D64927 3297B9C9DC 05E209071C0 0A327E1EBE2 7C4427...
output:
713679823 719476259 189 2236927 2097151 380231151 1280 33407 21 2 404226047 268435455 2 177 13 371842543 180 268435455 418322861 120 32879 138 19 0 2098175 21 91318796 268435455 219 371842544 719476262 666809811 32775 2255 36967 21 21 32769 32783 2164735 719476259 371842543 13 2105343 462361576 2627...
result:
ok 10000 numbers
Test #8:
score: 0
Accepted
time: 265ms
memory: 110676kb
input:
10000 300 1 3 7 D 70 A0 97 D2 581 D73 FE3 ADE BE90 2C00 0FD0 1ADD 9D7E1 85380 8D154 1C3E1 4091C1 835721 16A5A0 A579FF 3338C21 4C5BC41 B3267C0 481D2E5 C045A400 D2330C70 AA7E1366 ED783C80 5D9C8EB61 A20944E71 2F2CCB6F4 AB4C91E62 FABB51BF80 41ED063E43 C54DCF1D52 4B12739A29 9F98B9E4760 927BF482451 E8BFD2...
output:
713679823 268435459 62321207 128701157 120 123 3145743 2 371842543 33926 2 2 61146 2 268435455 1287 371842543 2 140217 719541795 1043 36863 61689 719476515 2097279 192 2143 0 780828798 0 219 162 1223 0 2603 12411540 33886 91318796 0 32767 171 0 268435455 21 2097151 21 373939695 256347164 371842547 7...
result:
ok 10000 numbers
Test #9:
score: 0
Accepted
time: 273ms
memory: 111192kb
input:
10000 300 1 3 3 A D0 D0 76 31 710 D91 4F7 A42 F3B1 6AA2 71F0 F751 CB4B0 30362 8EB94 C1913 532281 59FF53 9C2B57 3DCF3B BA00450 6E6FE40 76F7C50 4EE1E71 0FBA9391 D3C71DA3 2E925076 A44C773E F02E9DFB1 DC7535EE3 90DAF35E7 784F6A354 409869FC20 9C10BEAFB1 0EE9879CC0 EE8886BEEA CE586A8E371 08003AF5E92 FAB058...
output:
713679823 0 2655231 177 719476259 2130942 2097151 84 371842543 13 719476259 2 1107 17 21 2 786585123 268435455 93 13 69121 268435455 108 2 719476259 21 2363391 719476259 2621439 719476259 17 2 371842543 719492643 719476259 2 371842543 32767 0 49407 2 268435455 719476259 49155 339738623 40970 19 2 0 ...
result:
ok 10000 numbers
Test #10:
score: 0
Accepted
time: 265ms
memory: 112232kb
input:
10000 300 1 2 0 B A0 42 A7 C3 3B0 310 4B0 E7D 4421 9AB2 BBB2 5C0B 932B1 96EF3 12742 15A3C CDCC71 729330 1B7FD3 5C8E8B F431B00 C2E9C11 86FE105 2A2516D 376B4CA0 432EA5A1 A5EB6871 39A6E061 D93C4F551 C75FF9432 80CC17881 62FF560ED DB75889331 6D4C06F682 ABDA809031 AA8BE151AF FDA74DF05B1 9BBFF121F21 37DD84...
output:
713679823 371842543 219 123 13 268435455 1159 2047 0 2097151 2097151 78 719476259 19 719476259 78 719476259 0 32767 0 2097663 1023 2 19 21 1071 0 268435455 268435455 81 0 1151 0 719476259 268435455 268435459 0 2047 719476259 2 371842543 1055 719476259 21 49167 719476259 719476259 21 268435455 102 0 ...
result:
ok 10000 numbers
Test #11:
score: 0
Accepted
time: 252ms
memory: 111592kb
input:
10000 300 0 1 2 5 21 E3 E7 86 C31 AE2 604 3AD BD21 7532 7D50 4062 FC4C0 14321 D2F02 04FC5 930270 D2F1C3 C4B331 3E6C9D 14B2D91 D4DB863 972E643 704C878 44068510 30CC1B10 60027D91 ECF452A6 3DC3A8021 208B1B201 BE704CBC0 D7B215102 4B2067BFC0 93203D7A02 D6859EAB12 9A1DA02E88 C1256A2BBE1 7959F7570A2 03AD40...
output:
713679823 2 0 1055 21 371842543 34847 2 1039 21 21 36863 723670563 268435455 21 81 0 371842543 719476259 719476323 719476259 21 371842543 2097151 2 0 38419 21 2097153 84 371842543 268435455 2097151 1287 2099199 0 2097151 371842543 371842671 853693987 268435463 2621439 268435455 33279 21 371842543 21...
result:
ok 10000 numbers
Test #12:
score: 0
Accepted
time: 252ms
memory: 111208kb
input:
10000 300 1 3 1 D C1 C0 81 CE 6D1 8F0 E03 DF8 9811 1062 6977 A4A8 35BD0 A8A22 896E7 AC529 E6A321 DFB152 BA0EF1 201971 22B6670 D9B2A33 5456C01 624F7BC 5D70CF31 2DF2CEE2 A281DE17 4259303C FC2738E01 FE7D9DE22 5D66F93C4 48F91AB50 DC6EE7EC10 FF7C2E2AB0 CCE40C2874 C463A3A01F 79687341061 E63184689B1 CE3739...
output:
713679823 32768 171 1041 2 371842543 371842543 2 2097151 1047 268435455 1159 177 21 2 2097151 0 270532607 171 2105343 268435455 2 0 0 2 123 35071 719476259 120 2 1023 2097151 21 93 2097151 2097159 719476259 1023 2 719476259 1023 1537 0 2097151 268435455 268435455 0 2097151 21 371842543 2 49159 0 78 ...
result:
ok 10000 numbers
Subtask #3:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #13:
score: 0
Time Limit Exceeded
input:
10000 500 1 0 1 D 00 52 64 DC 651 C83 3D5 81F C280 5D02 A006 69BA F9170 ED933 600D4 F1224 8A7760 6692B3 C724E5 A84AEE DE9D551 BA075F0 004A075 0CB2132 200D6780 BC8227B2 E253F4C6 DE92ECBB 324EB89A0 394E85723 AD1B83763 AC28DAAE3 42480D89C1 9E82EECD13 EDCB865053 F8505D00E7 5966982D421 1369B1238A2 0C7886...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%