QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#287504#5407. 基础图论练习题AtomAlpaca0 13ms3952kbC++142.3kb2023-12-20 18:06:232023-12-20 18:06:23

Judging History

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

  • [2023-12-20 18:06:23]
  • 评测
  • 测评结果:0
  • 用时:13ms
  • 内存:3952kb
  • [2023-12-20 18:06:23]
  • 提交

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]) { r = bnd[d[i]].first, l = bnd[d[j]].second; }
			else { l = bnd[d[i]].second, r = bnd[d[j]].first; }
			if ((d[id[l]] + 1 == d[id[r]] and l + 1 == r) or (d[id[r]] + 1 == d[id[l]] and r + 1 == 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, 1ll * (j - 1) * (j - 2) / 2 + i - 1) * res % MOD) % MOD;
		}
	}
	printf("%d\n", ans);
}

int main() { scanf("%d", &T); while (T--) { solve(); } }

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 13ms
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
285212672
371842543
84
0
1983
2
268505087
268435455
719476515
32785
2
719476771
123
2621439
2523
0
719476275
371842543
2097159
41087
32767
3113984
719478307
502774846
719476259
719476259
719476259
65224
268697613
719477283
32767
2171007
719476259
371842543
120
84
219
5769215
268435455
1...

result:

wrong answer 16th numbers differ - expected: '2621567', found: '2621439'

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%