QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#571927 | #9319. Bull Farm | rookiefyq | WA | 51ms | 9684kb | C++14 | 3.2kb | 2024-09-18 10:26:24 | 2024-09-18 10:26:25 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int,int>
#define tii tuple<int, int, int>
using namespace std;
bool debug = 1;
#define dbg(x) if(debug) cerr<<BRIGHT_CYAN<<#x<<COLOR_RESET<<" = "<<(x)<<NORMAL_FAINT<<COLOR_RESET<<endl;
const string COLOR_RESET = "\033[0m", BRIGHT_CYAN = "\033[1;36m", NORMAL_FAINT = "\033[0;2m";
int trans(char ch1, char ch2) {
int res = (ch1 - 48) * 50 + (ch2 - 48);
return res;
}
const int N = 2003, M = 1e6+999;
int n, l, q, p[N][N], cnt[N], ans[M], vis[N], pos[N];
vector<tuple<int, int, int>> qy[N];
bitset<2002> bt[N];
void solve(){
cin >> n >> l >> q;
for (int i = 0; i <= n; i++)
bt[i].reset(), qy[i].clear(), bt[i].set(i);
for (int i = 1; i <= l; i++)
{
string st;
cin >> st;
for (int j = 1; j <= n; j++)
p[i][j] = trans(st[j * 2 - 2], st[j * 2 - 1]);
}
for (int i = 1; i <= q; i++){
string st;
cin >> st;
int a, b, c;
a = trans(st[0], st[1]);
b = trans(st[2], st[3]);
c = trans(st[4], st[5]);
qy[c].push_back(tii(a, b, i));
}
for(auto [a, b, id] : qy[0])
if(a == b)
ans[id] = 1;
else
ans[id] = 0;
for (int i = 1; i <= l; i++){
for (int j = 1; j <= n; j++)
pos[j] = vis[j] = cnt[j] = 0;
int flag = 0, num = 0;
for (int j = 1; j <= n; j++){
cnt[p[i][j]]++;
if(cnt[p[i][j]] > flag) flag = cnt[p[i][j]], num = 1;
else if(cnt[p[i][j]] == flag) num++;
}
if(flag == 1){
for (int j = 1; j <= n; j++){
if(vis[j])
continue;
int u = j;
bitset<2002> tmp;
while(1){
if(vis[u])
break;
vis[u] = 1;
tmp |= bt[u];
u = p[i][u];
}
u = j;
while(1){
bt[u] |= tmp;
u = p[i][u];
if(u == j)
break;
}
}
}
else if(flag == 2 && num == 1){
int u, v, w;
for (int j = 1; j <= n; j++){
if(pos[p[i][j]]){
u = pos[p[i][j]];
v = j;
}
pos[p[i][j]] = j;
}
for (int j = 1; j <= n; j++)
if(!pos[j])
w = j;
for (int j = 1; j <= n; j++)
if (bt[j][u] | bt[j][v])
bt[j] |= bt[w];
}
for(auto [a, b, id] : qy[i]){
if(bt[a][b] == 1)
ans[id] = 1;
else
ans[id] = 0;
}
}
for (int i = 1; i <= q; i++)
cout << ans[i];
cout << '\n';
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t = 1;
cin>>t;
while(t--)
solve();
return 0;
}
//__builtin_popcountll()
// cout<<fixed<<setprecision(2);
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7780kb
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: 9684kb
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
Wrong Answer
time: 51ms
memory: 5828kb
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...
output:
011110001101101111111111111111110101111111110111011110110110111011010101111111111111111101111111111110111111110111111111111101111111111110111111111111111111110001100111111111111111111111111011101111111111111111111111111111111111111111011011110100111110111111110111111100111111101110111111111101111110...
result:
wrong answer 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '011110001101101111111111111111...1111111111111111101111111111111'