QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#414323 | #6705. Median | xiaole | WA | 29ms | 4048kb | C++23 | 1.4kb | 2024-05-18 21:08:53 | 2024-05-18 21:08:54 |
Judging History
answer
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;using ll = long long;using PLL = pair<ll,ll>;
const ll MAX = 1e18;const ll MIN = -1e18;const ll INF=0x3f3f3f3f;
const ll Q = 2000+9;const ll MOD = 1e9 + 7;
vector<ll> s[Q];
vector<ll> x[Q];
bool vis[Q];
ll dfs(ll now){
ll cnt=1;
if(vis[now]){
return -1;
}
vis[now]=true;
for(auto i:s[now]){
cnt+=dfs(i);
}
return cnt;
}
ll dfs2(ll now){
ll cnt=1;
if(vis[now]){
return -1;
}
vis[now]=true;
for(auto i:x[now]){
cnt+=dfs2(i);
}
return cnt;
}
ll ans[Q];
void solve(){
ll n,m;cin>>n>>m;
memset(ans,0,sizeof ans);
bool ok=true;
for (ll i = 1; i <= m; i++)
{
ll o,p;cin>>o>>p;
if(o==p) ok=false;
x[o].push_back(p);
s[p].push_back(o);
}
if(ok==false){
for (ll i = 1; i <= n; i++)
{
cout<<0;
}cout<<"\n";
return;
}
for (ll i = 1; i <= n; i++)
{
memset(vis,0,sizeof vis);
ll l=dfs(i)-1;
memset(vis,0,sizeof vis);
ll r=dfs2(i)-1;
if(l==-1 or r==-1 )cout<<0;
else
if((l+r==0 or l+r==1)or(l==n/2 and r==n/2)){
cout<<1;
}else cout<<0;
}cout<<"\n";
}
int main(){
ios;ll _=1;cin>>_;
while (_--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3564kb
input:
2 5 4 1 2 3 2 2 4 2 5 3 2 1 1 2 3
output:
01000 000
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 29ms
memory: 4048kb
input:
66 13 2 9 13 7 11 11 19 9 1 8 1 5 1 2 8 4 2 2 1 5 2 6 3 3 11 3 2 4 6 6 10 9 8 3 5 1 7 5 8 3 9 4 9 6 7 3 1 2 3 11 6 9 4 1 6 5 2 1 5 4 6 8 4 15 15 10 6 15 8 7 6 11 1 5 2 3 4 11 13 4 6 10 12 10 13 1 6 15 2 5 12 13 14 5 3 15 86 14 12 8 1 14 9 8 15 5 10 1 9 11 2 6 2 7 10 10 13 14 5 4 13 5 8 4 10 13 9 6 9...
output:
1111111111111 00010000000 111 00000000000 000000000000000 000000000000000 00000 00000 0000000 0000000000000 000000000 000000000 000000000000000 000000000 000000000 0000000000000 0000000000000 000000000000000 00000000000 000000000000000 00000000000 00000000000 00000 00000000000 00000000000 00000 0000...
result:
wrong answer 2nd lines differ - expected: '01001000111', found: '00010000000'