QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#212154#5407. 基础图论练习题Rong70 8ms16972kbC++144.8kb2023-10-13 09:56:412023-10-13 09:56:41

Judging History

你现在查看的是最新测评结果

  • [2023-10-13 09:56:41]
  • 评测
  • 测评结果:0
  • 用时:8ms
  • 内存:16972kb
  • [2023-10-13 09:56:41]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int T, n;
int E[5005][5005];
int firs[5005], nex[25000005], to[25000005], tot;
char s[2005];
int idx, dfn[5005], low[5005], bel[5005], sz[5005], cnt, sta[5005], top;
int ct[5005][5005], fw[5005][5005], rd_in_Scc[5005];
vector < int > vet[5005];
bool ins[5005];
long long Ans;
void Clear (){
    for (int i = 1;i <= n;++ i)
        for (int j = 1;j <= n;++ j)
            E[i][j] = ct[i][j] = fw[i][j] = 0;
    for (int i = 1;i <= n;++ i){
        bel[i] = 0;
        sz[i] = 0;
        rd_in_Scc[i] = 0;
        vet[i].clear ();
        firs[i] = 0;
        dfn[i] = low[i] = 0;
    }
    cnt = 0;
    tot = 0;
    idx = 0;
    Ans = 0;
}
void Add (int u, int v){
    E[u][v] = 1;
    E[v][u] = - 1;
    ++ tot;
    nex[tot] = firs[u];
    firs[u] = tot;
    to[tot] = v;
}
int Represent (char a){
    if (a >= '0' && a <= '9')
        return a - '0';
    else
        return 10 + a - 'A';
}
void Tarjan (int u){
    if (dfn[u] > 0)
        return ;
    low[u] = dfn[u] = ++ idx;
    sta[++ top] = u;
    ins[u] = true;
    for (int e = firs[u], v;e;e = nex[e]){
        v = to[e];
        if (dfn[v] == 0){
            Tarjan (v);
            low[u] = min (low[u], low[v]);
        } else
        if (ins[v])
            low[u] = min (low[u], dfn[v]);
    }
    if (dfn[u] == low[u]){
        int v;
        ++ cnt;
        do {
            v = sta[top --];
            ++ sz[cnt];
            bel[v] = cnt;
            ins[v] = false;
            vet[cnt].push_back (v);
        } while (u != v);
        for (int p = 0;p < (int) vet[cnt].size ();++ p)
            for (int e = firs[vet[cnt][p]];e;e = nex[e])
                if (bel[to[e]] == cnt)
                    ++ rd_in_Scc[to[e]];
        for (int p = 0;p < (int) vet[cnt].size ();++ p)
            ++ ct[cnt][rd_in_Scc[vet[cnt][p]]];
        for (int i = sz[cnt];i >= 0;-- i)
            if (rd_in_Scc[i] == 0 || sz[cnt] == i)
                fw[cnt][i] = i;
            else
                fw[cnt][i] = fw[cnt][i + 1];
    }
}
const long long mod = 1e9 + 7;
long long Qpow (long long a, long long p){
    long long Res = 1;
    while (p > 0){
        if (p & 1)
            Res = Res * a % mod;
        a = a * a % mod;
        p >>= 1;
    }
    return Res;
}
int main (){
    int Q;
    scanf ("%d", &T);
    Q = T;
    while (T --){
        scanf ("%d", &n);
        // if (T == Q - 3)
        //     printf ("%d\n", n);
        for (int i = 2;i <= n;++ i){
            int l = (i - 1) / 4 + 1;
            scanf ("\n%s", s + 1);
            // if (T == Q - 3)
            //     printf ("%s\n", s + 1);
            for (int j = 1;j <= l;++ j){
                for (int k = 4 * j - 3, x = Represent (s[j]);k <= 4 * j && k < i;++ k, x >>= 1)
                    if (x & 1)
                        Add (i, k);
                    else
                        Add (k, i);
            }
        }
        // if (T <= Q - 3)
        //     puts ("0");
        // if (T <= Q - 3)
        //     continue;
        for (int i = 1;i <= n;++ i)
            Tarjan (i);
        for (int i = 1;i <= n;++ i){
            long long w = Qpow (2, (i - 1) * (i - 2) / 2);
            for (int j = 1;j < i;++ j){
                int u = i, v = j;
                if (E[u][v] < 0)
                    swap (u, v);
                if (bel[u] != bel[v]){
                    if (bel[u] - 1 == bel[v])
                        (Ans += w * cnt % mod) %= mod;
                    else
                        (Ans += w * (cnt - (bel[u] - bel[v])) % mod) %= mod;
                } else {
                    int rep = bel[u];
                    int p = 0, lim = sz[rep] + 1;
                    -- ct[rep][rd_in_Scc[u]];
                    ++ rd_in_Scc[u];
                    ++ ct[rep][rd_in_Scc[u]];
                    -- ct[rep][rd_in_Scc[v]];
                    -- rd_in_Scc[v];
                    ++ ct[rep][rd_in_Scc[v]];
                    if (ct[rep][rd_in_Scc[u] - 1] == 0)
                        lim = min (lim, rd_in_Scc[u] - 1);
                    if (ct[rep][rd_in_Scc[v] + 1] == 0)
                        lim = min (lim, rd_in_Scc[v] + 1);
                    while (ct[rep][p] > 0){
                        p = fw[rep][p + 1];
                        p = min (p, lim);
                    }
                    -- ct[rep][rd_in_Scc[u]];
                    -- rd_in_Scc[u];
                    ++ ct[rep][rd_in_Scc[u]];
                    -- ct[rep][rd_in_Scc[v]];
                    ++ rd_in_Scc[v];
                    ++ ct[rep][rd_in_Scc[v]];
                    (Ans += w * (cnt + p) % mod) %= mod;
                }
                (w <<= 1) %= mod;
            }
        }
        printf ("%lld\n", Ans);
        Clear ();
    }
    return 0;
}
/*
8
0
0
0
D
80
C1
54
*/

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 16972kb

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
351976128
767492450
263
0
1983
2
330197713
6217695
420513935
198298
2
238512056
283
10568526
2978
0
655049053
94434688
10333864
90513
120080
10229570
588647418
708566763
268360880
231848011
172665236
97445
878681977
137295765
70625
11335480
670283062
329598308
248
277
282
13429594
35195...

result:

wrong answer 3rd numbers differ - expected: '285212672', found: '351976128'

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%