QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#587989 | #9319. Bull Farm | sazhi | RE | 1ms | 4112kb | C++20 | 2.2kb | 2024-09-24 23:19:00 | 2024-09-24 23:19:01 |
Judging History
answer
// author: jieda
// file: cpp
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
# define fi first
# define se second
# define all(x) x.begin(),x.end()
# define stst stringstream
# define pb push_back
# define pf push_front
# define pp push
# define lowbit(x) (x)&(-x)
# define fa(i,op,n) for (ll i = op; i <= n; i++)
# define fb(j,op,n) for (ll j = op; j >= n; j--)
# define fg(i,op,n) for (ll i = op; i != n; i = ne[i])
int dx[4] = {-1,0,1,0},dy[4] = {0,1,0,-1};
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const ll N = 2e3+10,M = 1e5+10,INF = 0x3f3f3f3f,mod = 1e9+7;
const ll MOD = 212370440130137957ll;//hash(hight)
const int base = 131;
const double eps = 1e-3;
const int seed=10086,mo=1e6+7; //hash(lower)
int prime = 233317;
int read(){
char u,v;cin>>u>>v;
return (u-48)*50+v-48;
}
void solve(){
int n,l,q;cin>>n>>l>>q;
vector<vector<int>> t(l+1,vector<int>(n+1));
bitset<N> b[N];
for(int i = 1;i<=l;i++){
for(int j = 1;j<=n;j++){
int x = read();
t[i][j] = x;
b[j][j] = 1;
}
}
vector<int> ans(n+1);
vector<vector<array<int,3>>> query(q+1);
for(int i = 1;i<=q;i++){
int a = read(),b = read(),c = read();
query[c].pb({a,b,i});
}
auto add = [&](int x,int y) -> void{
if(b[x][y]) return ;
for(int i =1;i<=n;i++){
if(b[i][x]){
b[i] |= b[y];
}
}
};
auto use = [&](auto &p) -> void{
vector<int> vis(n+1);
int f = 0;
for(int i = 1;i<=n;i++){
if(!vis[p[i]]) vis[p[i]] = 1;
else if(f) return;
else f = p[i];
}
if(!f){
for(int i = 1;i<=n;i++){
add(i,p[i]);
}
}else{
int x = 0;
for(int i = 1;i<=n;i++){
if(!vis[i]){
x = i;
}
}
for(int i = 1;i<=n;i++){
if(p[i] == f){
add(i,x);
}
}
}
return ;
};
for(int i = 0;i<=l;i++){
use(t[i]);
for(auto[x,y,idx]:query[i]){
ans[idx] = b[x][y];
}
}
for(int i = 1;i<=q;i++){
cout<<ans[i];
}
cout<<'\n';
return ;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t = 1;
cin>>t;
while(t--){
solve();
}
return 0;
}
/**/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4112kb
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: -100
Runtime Error
input:
1 3 3 6 020202 030301 030201 020102 030203 010201 010303 020303 010202