QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#287479 | #5407. 基础图论练习题 | AtomAlpaca | 0 | 13ms | 3968kb | C++14 | 2.3kb | 2023-12-20 17:12:20 | 2023-12-20 17:12:21 |
Judging History
answer
#include <bits/stdc++.h>
typedef long long ll;
const int MAX = 5005;
const int INF = MAX;
const int MOD = 1e9 + 7;
int n, T, res, l, r, ans;
int id[MAX], d[MAX], sum[MAX], p0[MAX], p1[MAX], p2[MAX];
char s[MAX];
std::bitset <MAX> g[MAX];
std::pair <int, int> bnd[MAX];
ll qp(ll a, ll x)
{
ll res = 1;
while (x) { if (x & 1) { res = res * a % MOD; } a = a * a % MOD; x >>= 1; }
return res;
}
inline int get(char c) { return (c >= '0' and c <= '9' ? c - '0' : c - 'A' + 10); }
bool cmp(int a, int b) { return d[a] < d[b]; }
void solve()
{
ans = 0;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { g[i][j] = false; } }
for (int i = 2; i <= n; ++i)
{
scanf("%s", s + 1);
for (int j = 1; j <= std::ceil(i / 4.0); ++j)
{
int p = get(s[j]);
for (int k = 0; k <= 3 and 4 * j + k - 3 < i; ++k)
{
if (p >> k & 1) { g[i][4 * j + k - 3] = true; }
else { g[4 * j + k - 3][i] = true; }
}
}
}
// for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { printf("%d ", g[i][j] ? 1 : 0); } printf("\n"); }
for (int i = 1; i <= n; ++i) { d[i] = 0; }
for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { if (g[i][j]) { ++d[i]; } } }
for (int i = 1; i <= n; ++i) { id[i] = i; }
std::sort(id + 1, id + n + 1, cmp);
for (int i = 1; i <= n; ++i) { sum[i] = sum[i - 1] + d[id[i]]; }
for (int i = 1; i <= n; ++i) { bnd[i] = {INF, -INF}; }
for (int i = 1; i <= n; ++i) { int v = d[id[i]]; bnd[v].first = std::min(bnd[v].first, i); bnd[v].second = std::max(bnd[v].second, i); }
for (int i = 1; i <= n; ++i)
{
p0[i] = p0[i - 1] + (sum[i] == (i * (i - 1) / 2));
p1[i] = p1[i - 1] + ((sum[i] - 1) == (i * (i - 1) / 2));
p2[i] = p2[i - 1] + ((sum[i] + 1) == (i * (i - 1) / 2));
}
for (int i = 1; i <= n; ++i)
{
for (int j = i + 1; j <= n; ++j)
{
if (g[i][j]) { l = bnd[d[i]].first, r = bnd[d[j]].second; }
else { l = bnd[d[i]].second, r = bnd[d[j]].first; }
if (d[id[l]] + 1 == d[id[r]] or d[id[r]] + 1 == d[id[l]]) { res = p0[n]; }
else if (l < r) { res = p0[l - 1] + p0[n] - p0[r - 1] + p1[r - 1] - p1[l - 1]; }
else { res = p0[r - 1] + p0[n] - p0[l - 1] + p2[l - 1] - p2[r - 1]; }
ans = (ans + qp(2, (j - 1) * (j - 2) / 2 + i - 1) * res % MOD) % MOD;
}
}
printf("%d\n", ans);
}
int main() { scanf("%d", &T); while (T--) { solve(); } }
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 13ms
memory: 3968kb
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 285483519 371842543 79 0 1983 2 270499840 268435455 48538624 32899 2 884007957 63 3180563 2513 0 719476299 371842543 2097207 54291 32768 3147841 719476260 502774846 884007957 719476259 719476259 64360 541073419 377568228 60415 2112047 719476259 371842543 96 65 187 5409329 268435455 13 5...
result:
wrong answer 3rd numbers differ - expected: '285212672', found: '285483519'
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%