QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#184833 | #5407. 基础图论练习题 | YuJiahe | 0 | 7ms | 3952kb | C++23 | 1.7kb | 2023-09-21 13:23:34 | 2023-09-21 13:23:35 |
answer
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#define mod 1000000007
using namespace std;
const int N = 5005;char tp[N];
int t, n, a[N], id[N], rk[N], le[N], ri[N], to[N][N], ans, s0[N], s1[N], s2[N];
int main(){scanf("%d", &t);
while (t --){scanf("%d", &n), id[1] = 1, a[1] = 0, ans = 0;
for (int i = 2;i <= n;i ++){scanf("%s", tp), id[i] = i, a[i] = 0;
for (int j = 0;j < i - 1;j ++) a[i] +=
to[i][j + 1] = (tp[j >> 2] >= 'A' ? tp[j >> 2] - 'A' + 10 : tp[j >> 2] - '0') >> (j & 3) & 1;
for (int j = 1;j < i;j ++) a[j] += 1 - to[i][j];
}sort(id + 1, id + n + 1, [&](int x, int y){return a[x] < a[y];});
for (int i = 1;i <= n;i ++) rk[id[i]] = i;
sort(a + 1, a + n + 1);
for (int i = 1;i <= n;i ++){
if (i > 1 && a[i] == a[i - 1])
le[i] = le[i - 1];else le[i] = i;
}
for (int i = n;i >= 1;i --){
if (i < n && a[i] == a[i + 1])
ri[i] = ri[i + 1];else ri[i] = i;
}
for (int i = 1, sm = 0;i <= n;i ++) s0[i] = s0[i - 1] + ((sm += a[i]) == i * (i - 1) / 2);
for (int i = 1, sm = 0;i <= n;i ++) s1[i] = s1[i - 1] + ((sm += a[i]) == i * (i - 1) / 2 + 1);
for (int i = 1, sm = 0;i <= n;i ++) s2[i] = s2[i - 1] + ((sm += a[i]) == i * (i - 1) / 2 - 1);
for (int i = n, tmp, lp, rp;i >= 2;i --){
for (int j = i - 1;j >= 1;j --){
if (to[i][j]) swap(i, j);tmp = s0[n];int l = rk[i], r = rk[j];
if (a[l] + 1 == a[r]) goto Calc;
if (l < r) tmp += s1[r - 1] - s1[l - 1] - s0[r - 1] + s0[l - 1];
else tmp += s2[l - 1] - s2[r - 1] - s0[l - 1] + s0[r - 1];
Calc: ans = (ans * 2 + tmp) % mod;
if (to[j][i]) swap(i, j);
}
}printf("%d\n", ans);
}
}
// 2 0 1
// 3
// i -> j cd[i] --, cd[j] ++
// j -> i cd[j] --, cd[i] ++ (swap(i, j))
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 3952kb
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 65 0 1983 2 545063060 268435455 48539328 33933 2 884007485 75 2656276 3234 0 736524363 371842543 2105903 54291 32916 3147839 723736248 502774846 884008005 719476259 719476259 130037 541547563 377590756 60415 8156591 719476259 371842543 63 79 165 2400965 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%