QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#649031#5407. 基础图论练习题lifan0 15ms4364kbC++141.8kb2024-10-17 21:20:572024-10-17 21:21:00

Judging History

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

  • [2024-10-17 21:21:00]
  • 评测
  • 测评结果:0
  • 用时:15ms
  • 内存:4364kb
  • [2024-10-17 21:20:57]
  • 提交

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: 15ms
memory: 4364kb

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
251113734
327455501
270
0
1983
2
446245363
989995365
888991962
195933
2
891483044
292
13878907
4569
0
202648588
119205755
10947080
152228
273828
15660107
401646784
79291948
422209336
388020715
936825725
122525
489271649
202620276
146878
6121431
7582599
897859329
269
256
345
20962439
987...

result:

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

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%