QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#649005 | #5407. 基础图论练习题 | ddxrS | 0 | 11ms | 4288kb | C++14 | 1.8kb | 2024-10-17 21:15:50 | 2024-10-17 21:15:52 |
Judging History
answer
/*
由兰道定理得,竞赛图的强连通分量个数为 $\sum_{i=1}^{n}[\sum_{j=1}^i out_j=C(i,2)]$。
每次反转一条边可以做到 O(1) 修改。
*/
#include<bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;
const int N = 5005;
const ll mod = 1e9 + 7;
bool flg[N][N];
int n;
char s[N];
int out[N], sum[N], nxt[N];
int cnt1[N], cnt2[N];
int turn(char x) {return (x >= '0' && x <= '9' ? (x ^ 48) : (10 + (x - 'A')));}
void solve() {
scanf("%lld", &n);
for(int i = 1; i <= n; i++) out[i] = 0;
for(int i = 2, l; i <= n; i++) { l = (i - 1) / 4 + 1;
cin>>(s + 1);
for(int j = 1; j <= l; j++) for(int k = 4 * j - 3, x = turn(s[j]); k <= 4 * j && k < i; k++, x >>= 1)
if(x & 1) flg[i][k] = true, flg[k][i] = false, out[i]++;
else flg[k][i] = true, flg[i][k] = false, out[k]++;
}
for(int i = 1; i <= n; i++) sum[i] = out[i], nxt[i] = 0;
sort(sum + 1, sum + n + 1);
for(int i = 1; i <= n; i++) nxt[sum[i]] = i;
for(int i = 1; i <= n; i++) if(!nxt[i]) nxt[i] = nxt[i - 1];
for(int i = 1; i <= n; i++) {
int p = i * (i - 1) / 2; sum[i] += sum[i - 1];
if(sum[i] == p) cnt1[i] = cnt1[i - 1] + 1;
else if(sum[i] == p - 1) cnt2[i] = cnt2[i - 1] + 1;
}
ll ans = 0;
for(int i = n; i >= 1; i--) for(int j = i - 1; j >= 1; j--) {
int sum = cnt1[n];
if(flg[i][j]) {
if(out[j] >= out[i]) sum += (cnt2[nxt[out[j]] - 1] - cnt2[nxt[out[i] - 1]]);
if(out[j] + 1 < out[i]) sum -= (cnt1[nxt[out[i] - 1]] - cnt1[nxt[out[j]] - 1]);
} else {
if(out[i] >= out[j]) sum += (cnt2[nxt[out[i]] - 1] - cnt2[nxt[out[j] - 1]]);
if(out[i] + 1 < out[j]) sum -= (cnt1[nxt[out[j] - 1]] - cnt1[nxt[out[i]] - 1]);
}
ans = (ans * 2 + sum) % mod;
}
printf("%lld\n", ans);
}
signed main() {
int t; cin>>t;
while(t--) solve();
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: 11ms
memory: 4288kb
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 267895045 381717687 252 0 1983 2 502858233 889298933 290150734 193105 2 452893849 252 13359055 4555 0 511733279 345599024 11205497 134078 196304 13496183 505983926 79290916 711152486 778139620 389911197 121661 488286159 970957967 141306 6014537 261928825 816714368 252 252 241 14408775 7...
result:
wrong answer 3rd numbers differ - expected: '285212672', found: '267895045'
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%