QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#523720#5407. 基础图论练习题hcawa0 53ms54364kbC++142.4kb2024-08-18 16:51:492024-08-18 16:51:49

Judging History

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

  • [2024-08-18 16:51:49]
  • 评测
  • 测评结果:0
  • 用时:53ms
  • 内存:54364kb
  • [2024-08-18 16:51:49]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
constexpr int N = 5010, Mod = 1e9 + 7;
int n, pw2[N * N / 2], outdeg[N], d[N], pre1[N], pre2[N];
int pre3[N];
pair<int, int> interval[N];
bool e[N][N];
int main() {
    pw2[0] = 1;
    for (int i = 1; i < N * N / 2; ++i)
        pw2[i] = (pw2[i - 1] + pw2[i - 1]) % Mod;
    int T;
    cin >> T;
    while (T--) {
        cin >> n;
        fill(outdeg + 1, outdeg + n + 1, 0);
        for (int i = 1; i <= n; ++i)
            fill(e[i] + 1, e[i] + n + 1, false);
        for (int i = 2; i <= n; ++i) {
            string str;
            cin >> str;
            for (int l = 1, r; l < i; l += 4) {
                r = min(l + 3, i - 1);
                int res = str[(l - 1) >> 2] <= '9' ? str[(l - 1) >> 2] & 15 : str[(l - 1) >> 2] - 'A' + 10;
                for (int j = l; j <= r; ++j) {
                    if (res >> (j - l) & 1) {
                        e[i][j] = true;
                        ++outdeg[i];
                    } else {
                        e[j][i] = true;
                        ++outdeg[j];
                    }
                }
            }
        }
        copy(outdeg + 1, outdeg + n + 1, d + 1);
        sort(d + 1, d + n + 1);
        for (int l = 1, r; l <= n; l = r) {
            r = l + 1;
            while (r <= n && d[r] == d[l])
                ++r;
            interval[d[l]] = {l, r - 1};
        }
        for (int i = 1, sum = 0; i <= n; ++i) {
            sum += d[i];
            pre1[i] = pre1[i - 1] + (sum == i * (i - 1) / 2);
            pre2[i] = pre2[i - 1] + (sum + 1 == i * (i - 1) / 2);
            pre3[i] = pre3[i - 1] + (sum - 1 == i * (i - 1) / 2);
        }
        int ans = 0;
        for (int i = 1; i <= n; ++i)
            for (int j = i + 1; j <= n; ++j) {
                int x = interval[outdeg[e[i][j] ? j : i]].second, y = interval[outdeg[e[i][j] ? i : j]].first;

                if (x + 1 == y && d[x] + 1 == d[y]) {
                    ans = (ans + 1ll * pre1[n] * pw2[(j - 1) * (j - 2) / 2 + i - 1]) % Mod;
                    continue;
                }

                if (x > y)
                    swap(x, y);

                ans = (ans + 1ll * (pre1[x - 1] + pre1[n] - pre1[y - 1] + pre2[y - 1] - pre2[x - 1]) * 
                        pw2[(j - 1) * (j - 2) / 2 + i - 1]) % Mod;
            }
        cout << ans << "\n";
    }
    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: 53ms
memory: 54364kb

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
268435455
371842543
63
0
1983
2
268435455
268435455
719476259
32767
2
719476259
63
2097151
2509
0
719476259
371842543
2097151
32767
32767
3113982
719476259
502774846
719476259
719476259
719476259
64360
268435455
719476259
32767
2097151
719476259
371842543
63
63
115
2097151
268435455
13
...

result:

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

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%