QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#86635 | #5407. 基础图论练习题 | chenxia25 | 0 | 28ms | 34108kb | C++14 | 2.4kb | 2023-03-10 14:34:57 | 2023-03-10 14:34:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define mr make_pair
#define fi first
#define se second
using vi = vector<int>; using vii = vector<pii>;
#define pb emplace_back
#define sz(x) ((int)(x).size())
template<class T, class U> inline void cmn(T &x, const U &y) { if(y < x) x = y; }
template<class T, class U> inline void cmx(T &x, const U &y) { if(y > x) x = y; }
const char nl = '\n', nk = ' ';
const int inf = sizeof(int) == 4 ? 0x3f3f3f3f : 0x3f3f3f3f3f3f3f3f;
const int P = 1e9 + 7;
const int N = 5010;
int n;
bool a[N][N];
int pre[N][N];
int adp[N], sup[N];
void mian() {
cin >> n;
for(int i = 2; i <= n; ++i) {
static char s[N]; cin >> s + 1;
int m = (i + 2) / 4;
for(int j = 1; j <= m; ++j) {
int val = s[j] <= '9' ? s[j] ^ 48 : s[j] - 'A' + 10;
for(int k = 0; k < 4; ++k) {
int K = 4 * j + k - 3;
if(K >= i) break;
if(val >> k & 1) a[i][K] = true;
else a[K][i] = true;
}
}
}
static int deg[N], cnt[N], sum[N];
for(int i = 1; i <= n; ++i) deg[i] = count(a[i] + 1, a[i] + n + 1, true), ++cnt[deg[i]];
for(int i = 1; i <= n; ++i) sum[i] = deg[i];
sort(sum + 1, sum + n + 1);
// for(int i = 1; i <= n; ++i) cerr << sum[i] << (i == n ? nl : nk);
int ori = 0;
for(int i = 1; i <= n; ++i) ori += (sum[i] += sum[i - 1]) == i * (i - 1) / 2;
for(int l = 1; l <= n; ++l) {
int res0 = ori, res1 = ori;
for(int r = l; r < n; ++r) {
res0 += (sum[r] - 1 == r * (r - 1) / 2) - (sum[r] == r * (r - 1) / 2);
res1 += (sum[r] + 1 == r * (r - 1) / 2) - (sum[r] == r * (r - 1) / 2);
pre[l][r + 1] = res0;
pre[r + 1][l] = res1;
}
}
for(int i = 1; i <= n; ++i) adp[sum[i] - sum[i - 1]] = i;
for(int i = n; i; --i) sup[sum[i] - sum[i - 1]] = i;
// for(int i = 0; i < n; ++i) cerr << adp[i] << nk << sup[i] << nl;
int ans = 0, pw = 1;
for(int i = 1; i <= n; ++i) for(int j = 1; j < i; ++j) {
int x = i, y = j;
if(a[y][x]) swap(x, y);
// cerr << sup[deg[x]] << nk << adp[deg[y]] << nl;
int res = deg[x] == deg[y] + 1 ? ori : pre[sup[deg[x]]][adp[deg[y]]];
ans = (ans + (ll)res * pw) % P;
if((pw += pw) >= P) pw -= P;
}
cout << ans << nl;
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
// cin >> t;
while(t--) mian();
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: 28ms
memory: 34108kb
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:
0
result:
wrong answer 1st numbers differ - expected: '281603732', found: '0'
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%