QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#414290#6705. MedianxiaoleWA 6ms3724kbC++231.8kb2024-05-18 20:21:022024-05-18 20:21:04

Judging History

你现在查看的是最新测评结果

  • [2024-05-18 20:21:04]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:3724kb
  • [2024-05-18 20:21:02]
  • 提交

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];
ll  vis[Q];
void dfs(ll now){
    if(vis[now]) return;
    vis[now]=true;
    for(auto i:s[now]){
        ans[i]=ans[now]-1;
        dfs(i);
    }
}
void dfs2(ll now){
    if(vis[now]) return;
    vis[now]=true;
    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){
        memset(vis,0,sizeof vis);
        dfs(i);
        memset(vis,0,sizeof vis);
        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;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3536kb

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: 6ms
memory: 3724kb

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:

0000000000000
10000000000
000
00000000000
000000000000000
001000000000000
00100
01000
0000000
0010000000000
000000000
100000000
000010000000000
000000000
010000000
0000001000000
0000000000000
000001000000000
00000000000
100000000000000
00000000000
00000010000
00000
10000000000
00000000000
01000
0000...

result:

wrong answer 1st lines differ - expected: '1111111111111', found: '0000000000000'