QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#287503#5407. 基础图论练习题AtomAlpaca0 12ms4036kbC++142.3kb2023-12-20 18:05:372023-12-20 18:05:37

Judging History

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

  • [2023-12-20 18:05:37]
  • 评测
  • 测评结果:0
  • 用时:12ms
  • 内存:4036kb
  • [2023-12-20 18:05:37]
  • 提交

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]] 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(); } }

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 12ms
memory: 4036kb

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
272697387
371842543
65
0
1983
2
406851731
268435455
719477219
33803
2
719476299
75
2097152
2519
0
736524323
371842543
2105855
32767
32915
3113982
723738295
502774846
719476307
719476259
719476259
105456
268774155
719499811
32767
7118847
719476259
371842543
87
82
147
2695167
268435455
13...

result:

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

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%