QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#567795 | #9319. Bull Farm | Blueqwq | RE | 1ms | 6016kb | C++20 | 4.9kb | 2024-09-16 13:57:07 | 2024-09-16 13:57:07 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2010;
const int Q = 1000010;
const int mod = 998244353;
const bool multiTest = 1;
// head
bool memoryStart;
#define rep0(n) for(int i = (1), _Lim = (n); i <= _Lim; i++)
#define rep1(i, n) for(int i = (1), _Lim = (n); i <= _Lim; i++)
#define rep2(i, l, r) for(int i = (l), _Lim = (r); i <= _Lim; i++)
#define rep3(i, r, l, _) for(int i = (r), _Lim = (l); i >= _Lim; i--)
#define M5(this, def, from, xy, orz, ...) orz
#define do(args...) M5(args, rep3, rep2, rep1, rep0)(args)
using ll = long long;
using ull = unsigned long long;
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
#define all(g) g.begin(), g.end()
#define sz(g) (int)(g.size())
#define bit(x, y) (((x) >> (y)) & 1)
template <typename T = int> T read(){
T x = 0; bool f = false; char ch = getchar();
while(!isdigit(ch)) {if(ch == '-') f = true; ch = getchar();}
while(isdigit(ch)) {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
return f ? -x : x;
}
template <typename T> void write(T x, char ed = '\n') {
if(x < 0) putchar('-'), x = -x;
static int _Num[30], _Nm = 0;
do _Num[++_Nm] = x % 10, x /= 10; while(x);
while(_Nm) putchar(_Num[_Nm--] ^ 48);
putchar(ed);
}
template <typename T> void read(T& a) {a = read<T>();}
template <typename T, typename... Tp> void read(T& a, Tp&... Args) {a = read<T>(); read(Args...);}
template <typename T, typename... Tp> void write(T a, Tp... Args) {write(a, ' '); write(Args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) {return rng() % (r - l + 1) + l;}
int qpow(int a, int b, int md = mod) {int res = 1; for(; b; b >>= 1, a = a * a % md) (b & 1) && (res = res * a % md, true); return res;}
struct Query {
int a, b, c, id;
bool operator < (const Query ano) const {
return c < ano.c;
}
} qry[N];
int n, m, q;
int t[N][N];
char s[N << 1];
int fa[N];
bitset<N> g[N];
int find(int x) {
if(fa[x] == x) return x;
g[fa[x]] |= g[x];
return fa[x] = find(fa[x]);
}
void merge(int u, int v) {
u = find(u); v = find(v);
fa[u] = v; g[v] |= g[u];
}
int decode(char a, char b) {
return (a - 48) * 50 + (b - 48);
}
int deg[N];
bool vis[N];
vector<int> cur;
void dfs(int u, int id) {
if(vis[u]) return;
vis[u] = true;
cur.push_back(u);
dfs(t[id][u], id);
}
void addedge(int u, int v) {
u = find(u); v = find(v);
if(u == v) return;
for(int k = 1; k <= n; k++)
if(g[k][u]) g[k] |= g[v];
}
void add(int k) {
for(int i = 1; i <= n; i++)
deg[i] = 0;
for(int i = 1; i <= n; i++)
deg[t[k][i]]++;
bool flg1 = true;
vector<int> deg0, deg2;
for(int i = 1; i <= n; i++) {
if(deg[i] != 1) flg1 = false;
if(deg[i] == 0) deg0.push_back(i);
if(deg[i] == 2) deg2.push_back(i);
}
if(flg1) {
for(int i = 1; i <= n; i++)
vis[i] = false;
for(int i = 1; i <= n; i++) if(!vis[i]) {
cur.clear();
dfs(i, k);
for(int j = 0; j < cur.size() - 1; j++)
merge(cur[j], cur[j + 1]);
}
} else if(deg0.size() == 1 && deg2.size() == 1) {
vector<int> in;
for(int i = 1; i <= n; i++)
if(t[k][i] == deg2[0]) in.push_back(i);
addedge(in[0], deg0[0]);
addedge(in[1], deg0[0]);
}
}
bool ans[N];
void init() {}
void clear() {}
void solve() {
read(n, m, q);
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++)
g[i][j] = false;
fa[i] = i, g[i][i] = true;
}
for(int i = 1; i <= q; i++)
ans[i] = false;
for(int i = 1; i <= m; i++) {
scanf("%s", s + 1);
for(int j = 1; j <= n; j++)
t[i][j] = decode(s[j + j - 1], s[j + j]);
}
for(int i = 1; i <= q; i++) {
scanf("%s", s + 1);
qry[i].id = i;
qry[i].a = decode(s[1], s[2]);
qry[i].b = decode(s[3], s[4]);
qry[i].c = decode(s[5], s[6]);
}
sort(qry + 1, qry + q + 1);
int cc = 0;
for(int i = 1; i <= q; i++) {
while(cc < qry[i].c) add(++cc);
if(g[find(qry[i].a)][find(qry[i].b)]) ans[qry[i].id] = true;
}
for(int i = 1; i <= q; i++)
putchar(ans[i] ? '1' : '0');
puts("");
}
bool memoryEnd;
signed main() {
#ifdef LOCAL
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif
init(); int t = 1;
if(multiTest) t = read();
while(0 > ~ -- t) clear(), solve();
fprintf(stderr, "Memory : %.2lfMB, Time : %.2lfs\n", abs(&memoryStart - &memoryEnd) / 1048576.0, clock() * 1.0 / CLOCKS_PER_SEC);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 4084kb
input:
2 5 2 4 0305040201 0404040404 030300 020500 050102 020501 6 2 4 030603010601 010203060504 030202 060402 050602 060401
output:
1011 0100
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 6016kb
input:
1 3 3 6 020202 030301 030201 020102 030203 010201 010303 020303 010202
output:
010101
result:
ok single line: '010101'
Test #3:
score: -100
Runtime Error
input:
200 10 10 5000 01060:04020305080709 0103070:060204050908 09070503080401060:02 050308010204090:0607 03010502040607080:09 03080109020504060:07 06050:09040302080107 07080305010409060:02 030809010:0204060507 0:060908070201050304 060700 090:03 09080: 070405 010703 0:0100 080601 030600 070206 0:0:09 08040...