QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#613068#6705. Medianzqx#AC ✓5ms4492kbC++232.6kb2024-10-05 13:31:202024-10-05 13:31:20

Judging History

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

  • [2024-10-05 13:31:20]
  • 评测
  • 测评结果:AC
  • 用时:5ms
  • 内存:4492kb
  • [2024-10-05 13:31:20]
  • 提交

answer

#include<bits/stdc++.h>
#define AC return 0;
#define int long long 
#define pii pair<int,int>
#define all(tar) tar.begian(),tar.end()
const int N=2e2+5;
const int mod=998244353; 
using namespace std;
int n,m,t;
int deg[N],tdeg[N],mx[N][N],mn[N][N];
vector<int>e1[N],e2[N];
void init(){
   memset(deg,0,sizeof(deg));
   memset(tdeg,0,sizeof(tdeg));
   memset(mx,0,sizeof(mx));
   memset(mn,0,sizeof(mn));
}
void mergemn(int i,int j){
   for(int k=1;k<=n;k++){
      if(mn[i][k]||k==i) mn[j][k]=1;
   }
}
void mergemx(int i,int j){
   for(int k=1;k<=n;k++){
      if(mx[i][k]||k==i) mx[j][k]=1;
   }
}
void solve(){
   init();
   cin>>n>>m;
   for(int i=1;i<=n;i++) e1[i].clear(),e2[i].clear();
   bool f=true;
   for(int i=1;i<=m;i++){
      int x,y;cin>>x>>y;
      if(x==y) f=false;
      deg[x]++;e1[y].push_back(x);
      tdeg[y]++;e2[x].push_back(y);
   }
   if(!f){
      for(int i=1;i<=n;i++) cout<<0;
      cout<<'\n';return;
   }
   vector<int>ans;queue<int>q;
   for(int i=1;i<=n;i++){
      if(deg[i]==0) q.push(i);
   }
   while(q.size()){
      int u=q.front();q.pop();
      ans.push_back(u);
      for(auto j:e1[u]){
         mergemn(u,j);
         if(!--deg[j]){
            q.push(j);
         }
      }
   }
   //cout<<ans.size()<<endl;
   if(ans.size()!=n){
      for(int i=1;i<=n;i++) cout<<0;
      cout<<'\n';return;      
   }
   for(int i=1;i<=n;i++){
      if(tdeg[i]==0) q.push(i);
   }
   ans.clear();
   while(q.size()){
      int u=q.front();q.pop();
      ans.push_back(u);
      for(auto j:e2[u]){
         mergemx(u,j);
         if(!--tdeg[j]){
            q.push(j);
         }
      }
   }  
   //cout<<ans.size()<<endl;
   if(ans.size()!=n){
      for(int i=1;i<=n;i++) cout<<0;
      cout<<'\n';return;      
   }ans.clear();
   // for(int i=1;i<=n;i++){
   //    cout<<mx[5][i]<<" ";
   // }
   // cout<<'\n';
   int lim=n/2-(n%2==0);
   for(int i=1;i<=n;i++){
      int gs=0,fre=n-1;
      for(int j=1;j<=n;j++){
         if(mn[i][j]&&mx[i][j]){
            for(int k=1;k<=n;k++) cout<<0;
            cout<<'\n';return;               
         }
         if(mn[i][j]) gs++,fre--;
         if(mx[i][j]) fre--;
      }
      if(gs+fre<lim||gs>lim) ans.push_back(0);
      else ans.push_back(1);
      //cout<<gs<<" "<<fre<<" "<<lim<<endl;
   }    
   for(auto j:ans) cout<<j;
   cout<<'\n';
}
/*
2
5 4
1 2
3 2
2 4
2 5
3 2
1 1
2 3
*/
signed main(){
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin>>t;
   while(t--){
      solve();
   }
   AC
}   

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 5ms
memory: 4452kb

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
01001000111
111
11111111111
111111111111111
001001000000000
00100
01100
1111111
1000000000000
111101101
111111111
000011111011101
010111111
001100000
0100001001101
1111111111111
001000010000000
10010111011
001000000000100
11111111111
00100000011
11111
01000000110
11101110111
00000
1111...

result:

ok 66 lines