QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#86732 | #5407. 基础图论练习题 | Zeardoe | 0 | 11ms | 7452kb | C++14 | 4.0kb | 2023-03-10 18:26:45 | 2023-03-10 18:26:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(i, a, b) for(int i = (a); i <= (b); i++)
#define cl(i, n) i.clear(),i.resize(n);
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int inf = 1e9;
//#define cerr if(false)cerr
//#define freopen if(false)freopen
#define watch(x) cerr << (#x) << ' '<<'i'<<'s'<<' ' << x << endl
void pofe(int number, int bitnum) {
string s; f(i, 0, bitnum) {s += char(number & 1) + '0'; number >>= 1; }
reverse(s.begin(), s.end()); cerr << s << endl;
return;
}
void cmax(int &x, int y) {if(x < y) x = y;}
void cmin(int &x, int y) {if(x > y) x = y;}
//调不出来给我对拍!
int dir[5050][5050];
int deg[5050];
//分段
const int mod = 1e9 + 7;
int qpow(int x, int k) {
int res = 1;
while(k) {
if(k & 1) res = res * x % mod;
k >>= 1;
x = x * x % mod;
}
return res;
}
int t[5050];
int tdeg[5050];
int add[5050], mns[5050];
bool cmp(int x, int y) {return deg[x] < deg[y];}
signed main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
//freopen();
//freopen();
//time_t start = clock();
//think twice,code once.
//think once,debug forever.
int T = 1e4; cin >> T;
while(T --) {
int n; cin >> n;
f(i, 1, n) deg[i] = 0, add[i] = mns[i] = 0;
f(i, 2, n) {
int k = (i + 2) / 4;
f(j, 1, k) {
char ch; cin >> ch;
if(isalpha(ch)) ch = ch - 'A' + 10;
else ch = ch - '0';
f(d, 0, 3) {
int x = ch & 1;
dir[i][4 * j + d - 3] = x;
ch >>= 1;
}
}
}
// f(i, 2, n) f(j, 1, i - 1) cout << dir[i][j] << " \n"[j == i - 1];
f(i, 2, n) f(j, 1, i - 1) {
if(dir[i][j] == 1) deg[i] ++;
else deg[j] ++;
}
f(i, 1, n) t[i] = i;
sort(t + 1, t + n + 1, cmp);
f(i, 1, n) tdeg[i] = deg[t[i]];
int num = 0;
int sum = 0;
f(i, 1, n) {
sum += tdeg[i];
int kp = i * (i - 1) / 2;
if(sum == kp) {
num ++;
add[i] = mns[i] = -1;
}
else {
if(sum == kp - 1) add[i] = 1; //可以 +1 成功
if(sum == kp + 1) mns[i] = 1; //可以 -1 成功
}
}
// cerr << num << endl;
// f(i, 1, n) cerr << add[i] << " ";
// cerr << endl;
// f(i, 1, n) cerr << mns[i] << " ";
// cerr << endl;
f(i, 2, n) {add[i] = add[i - 1] + add[i]; mns[i] = mns[i - 1] + mns[i];}
int res = 0;
f(i, 2, n) f(j, 1, i - 1) {
int coe = qpow(2, (i - 2) * (i - 1) / 2 + j - 1);
int ans = num; int ti = i, tj = j;
if(deg[i] > deg[j]) swap(ti, tj);
int l = lower_bound(tdeg + 1, tdeg + n + 1, deg[ti]) - tdeg;
int r = upper_bound(tdeg + 1, tdeg + n + 1, deg[tj]) - tdeg - 1;
int am = (dir[ti][tj] == 1 ? (l < r) : (l > r)); //am = 0: (left ~ right - 1) -1.
// cerr << l << " " << r << endl;
if(l > r) swap(l, r);
// if(tdeg[l] + 1 == tdeg[r] && tdeg[r] - 1 == tdeg[l]) l = r;
if(am == 1) {
ans += add[r - 1] - add[l - 1];
}
else {
if(tdeg[l] + 1 == tdeg[r] && tdeg[r] - 1 == tdeg[l]) l = r;
ans += mns[r - 1] - mns[l - 1];
}
// cout << j << " " << i << " " << ans << endl;
res += coe * ans % mod; res %= mod;
}
cout << res << endl;
}
//time_t finish = clock();
//cout << "time used:" << (finish-start) * 1.0 / CLOCKS_PER_SEC <<"s"<< endl;
return 0;
}
/*
2023/x/xx
start thinking at h:mm
start coding at h:mm
finish debugging at h:mm
*/
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: 7452kb
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 289745451 371842543 79 0 1983 2 549323049 268435455 48539328 33933 2 884007997 63 3180564 3521 0 736524363 371842543 2105911 54291 32916 3147841 723736248 502774846 884008005 719476259 719476259 135205 541581438 377590756 60415 8410727 719476259 371842543 96 65 209 5577413 268435455 13 ...
result:
wrong answer 3rd numbers differ - expected: '285212672', found: '289745451'
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%