QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#591254 | #9310. Permutation Counting 4 | Livinfly | WA | 1ms | 5596kb | C++17 | 3.3kb | 2024-09-26 14:59:11 | 2024-09-26 14:59:12 |
Judging History
answer
// #pragma GCC optimize(2)
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mkp(x, y) make_pair((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long LL;
typedef double db;
typedef pair<int, int> PII;
// 无向图边数 + 有向图边数 n+l
const int N = 2010, Q = 1e6+10, INF = 0x3f3f3f3f;
vector<PII> e[N];
int n, l, q, fa[N], deg[N], to[N], buc[N][N], cnt[N], dis[N][N];
bool vis[N];
int leader(int x) {
if(x == fa[x]) return x;
return fa[x] = leader(fa[x]);
}
void solve() {
cin >> n >> l >> q;
for(int i = 1; i <= n; i ++) fa[i] = i, e[i].clear();
for(int i = 1; i <= l; i ++) {
string s; cin >> s;
for(int j = 1; j <= n; j ++) deg[i] = 0;
for(int j = 0; j < n; j ++) {
to[j+1] = (s[j*2]-'0')*50 + (s[j*2+1]-'0');
// cerr << to[j+1] << ' ';
deg[to[j+1]]++;
}
// cerr << '\n';
int siz = count_if(deg+1, deg+n+1, [&](auto x) {
return x;
});
if(siz < n-1) continue;
if(siz == n) {
for(int j = 1; j <= n; j ++) {
int x = j, y = to[j], fx = leader(x), fy = leader(y);
if(fx != fy) {
fa[fy] = fx;
e[x].eb(y, i);
e[y].eb(x, i);
}
}
}
else {
int deg0 = -1, deg2 = -1;
for(int j = 1; j <= n; j ++) {
if(deg[j] == 0) deg0 = j;
if(deg[j] == 2) deg2 = j;
}
for(int j = 1; j <= n; j ++) { // 空格的移动
if(to[j] == deg2) e[j].eb(deg0, i);
}
}
}
for(int S = 1; S <= n; S ++) {
for(int i = 0; i <= l; i ++) cnt[i] = 0;
for(int i = 1; i <= n; i ++) dis[S][i] = INF, vis[i] = false;
dis[S][S] = 0;
buc[0][cnt[0]++] = S;
for(int d = 0; d <= l; d ++) {
for(int i = 0; i < cnt[d]; i ++) {
int u = buc[d][i];
if(vis[u]) continue;
vis[u] = true;
for(auto [v, w]: e[u]) {
if(dis[S][v] > max(dis[S][u], w)) {
dis[S][v] = max(dis[S][u], w);
buc[dis[S][v]][cnt[dis[S][v]]++] = v;
}
}
}
}
}
while(q--) {
string s; cin >> s;
for(int j = 0; j < 3; j ++) {
to[j+1] = (s[j*2]-'0')*50 + (s[j*2+1]-'0');
// cerr << to[j+1] << ' ';
}
// cerr << dis[to[1]][to[2]] << '\n';
if(dis[to[1]][to[2]] <= to[3]) cout << "1";
else cout << "0";
// cerr << '\n';
}
cout << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed; // << setprecision(20); // double
// freopen("i.txt", "r", stdin);
// freopen("o.txt", "w", stdout);
// time_t t1 = clock();
int Tcase = 1;
cin >> Tcase; // scanf("%d", &Tcase);
while (Tcase--)
solve();
// cout << "time: " << 1000.0 * (1.*(clock() - t1) / CLOCKS_PER_SEC) << "ms\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5596kb
input:
4 5 1 2 1 5 1 2 1 2 2 2 5 1 1 2 4 2 3 5 5 3 4 5 3 5 1 2 3 4 3 5 3 3 5 1 5 1 4 4 5 5 5 1 2
output:
00 00 00 000
result:
wrong answer 1st words differ - expected: '0', found: '00'