QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#414288 | #6705. Median | xiaole | ML | 0ms | 3540kb | C++23 | 1.7kb | 2024-05-18 20:18:20 | 2024-05-18 20:18:20 |
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 = 200+9;const ll MOD = 1e9 + 7;
vector<ll> s[Q];
vector<ll> x[Q];
ll ans[Q];
void dfs(ll now){
for(auto i:s[now]){
ans[i]=ans[now]-1;
dfs(i);
}
}
void dfs2(ll now){
for(auto i:x[now]){
ans[i]=ans[now]+1;
dfs2(i);
}
}
void solve(){
ll n,m;cin>>n>>m;
bool ok=true;
for (ll i = 1; i <= n; i++)
{
ans[i]=0;
}
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;
}
ans[1]=1000;
for (ll i = 1; i <= n; i++)
{
if(ans[i]!=0){
dfs(i);
dfs2(i);
}
}
vector<ll> v;v.push_back(0);
for (ll i = 1; i <= n; i++)
{
v.push_back(ans[i]);
if(ans[i]==0){
for (ll i = 1; i <= n; i++)
{
cout<<0;
}cout<<"\n";
return;
}
x[i].clear();
s[i].clear();
}
ll t[1000];
memset(t,0,sizeof t);
sort(v.begin()+1,v.end());
for (ll i = 1; i <= n; i++)
{
if(ans[i]==v[(n+1)/2]){
t[i]=1;
break;
}
}
for (ll i = 1; i <= n; i++)
{
cout<<t[i];
}
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: 0ms
memory: 3540kb
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
Memory Limit Exceeded
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...