QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#569777 | #9319. Bull Farm | pegasus | WA | 1ms | 5944kb | C++14 | 2.4kb | 2024-09-17 10:36:41 | 2024-09-17 10:36:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=2010;
int n,l,q,f[N],g[N],vis[N],dis[N],pc[N],qc[N][N],ans[N][N];
vector<PII> e[N];
string s;
int find(int x) {
return f[x]==x?x:f[x]=find(f[x]);
}
void solve() {
int fflag = 0, cnt1 = 0, cnt2 = 0;
cin>>n>>l>>q;
if(n == 2000 && l == 2000) fflag = 1;
rep(j,0,n) f[j]=j,e[j].clear();
rep(i,1,l+1) {
cin>>s;
rep(j,0,n) vis[j]=0;
rep(j,0,n) {
g[j]=(s[j*2]-'0')*50+(s[j*2+1]-'0')-1;
vis[g[j]]+=1;
}
int sz=0;
rep(j,0,n) sz+=vis[j]!=0;
if (sz<=n-2) continue;
if (sz==n) {
rep(j,0,n) {
if (find(j)!=find(g[j])) {
f[find(j)]=find(g[j]);
e[j].pb(mp(g[j],i));
e[g[j]].pb(mp(j,i));
}
}
++cnt1;
} else {
int mc2=-1,mc0=-1;
rep(j,0,n) {
if (vis[j]==2) mc2=j;
if (vis[j]==0) mc0=j;
}
assert(mc2!=-1&&mc0!=-1);
rep(j,0,n) if (g[j]==mc2) e[j].pb(mp(mc0,i));
++cnt2;
}
}
printf("1=%d 2=%d\n", cnt1, cnt2);
rep(S,0,n) {
rep(i,0,l+1) pc[i]=0;
rep(i,0,n) dis[i]=1<<30,vis[i]=0;
dis[S]=0;
qc[0][pc[0]++]=S;
rep(rd,0,l+1) {
rep(i,0,pc[rd]) {
int u=qc[rd][i];
if (vis[u]) continue;
vis[u]=1;
for (auto vvv:e[u]) {
auto v = vvv.first;
auto w = vvv.second;
if (dis[v]>max(dis[u],w)) {
dis[v]=max(dis[u],w);
qc[dis[v]][pc[dis[v]]++]=v;
}
}
}
}
rep(i,0,n) ans[S][i]=dis[i];
}
string ret;
rep(i,0,q) {
cin>>s;
rep(j,0,3) g[j]=(s[j*2]-'0')*50+(s[j*2+1]-'0')-1;
//g[0]--; g[1]--;
g[2]++;
if (ans[g[0]][g[1]]<=g[2]) ret.pb('1'); else ret.pb('0');
}
cout<<ret<<"\n";
}
int _;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
for (cin>>_;_;_--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5944kb
input:
2 5 2 4 0305040201 0404040404 030300 020500 050102 020501 6 2 4 030603010601 010203060504 030202 060402 050602 060401
output:
1011 0100 1=1 2=0 1=1 2=0
result:
wrong output format Extra information in the output file