1 solutions

  • 0
    @ 2025-11-5 20:14:38

    C :

    #include <stdio.h>
    #include <string.h>
    
    int n, k, pi;
    int list[1001], tmp[1001];
    char optr;
    
    int verify(){
      //printf("Verifying...\n");
      for(int i = 0; i < 2*pi; i++){
        //printf("Verified no.%d not to be fake.\n", tmp[i]);
        list[tmp[i]] = 1;
      }
    }
    int verifyRemains(){
      //printf("Verify Remains...\n");
      int i = 1, j = 1;
      for(i = 0; i < 2*pi; i++)
        if(list[tmp[i]] == 0)
          list[tmp[i]] = 2;
      for(i = 1; i <= n; i++){
        if(list[i] == 0){
          list[i] = 1;
          //printf("Verified no.%d not to be fake.\n", i);
        }
        else if(list[i] == 2)
          list[i] = 0;
      }
    }
    int check(){
      for(int i = 0; i < k; i++){
        scanf("%d", &pi);
        for(int j = 0; j < 2*pi; j++)
          scanf("%d", &tmp[j]);
        scanf(" %c", &optr);
        if(optr == '=') verify();
        else verifyRemains();
      }
      int res = 0;
      for(int i = 1; i <= n; i++){
        if(list[i] == 0){
          if(!res)
            res = i;
          else
            return 0;
        }
      }
      return res;
    }
    int main(){
      int i, j;
      scanf("%d%d",&n,&k);
      printf("%d\n", check());
      return 0;
    }
    

    C++ :

    #include<cstdio>
    #include<cstring>
    #define N 1005
    using namespace std;
    
    int normal[N],light[N],heavy[N],tmp[N];
    
    int main()
    {
        memset(normal,0,sizeof(normal));
        memset(light,0,sizeof(light));
        memset(heavy,0,sizeof(heavy));
        //freopen("data.in","r",stdin);
        int n,k;
        int i,j,p;
        scanf("%d%d",&n,&k);
        for(i=0;i<k;i++)
        {
            int x;
            char ch;
            scanf("%d",&x);
            for(j=0;j<2*x;j++)
                scanf("%d",tmp+j);
            while((ch=getchar())!='='&&ch!='<'&&ch!='>');
            if(ch=='<')
            {
                for(j=0;j<x;j++)
                    light[tmp[j]]=1;
                for(j=x;j<2*x;j++)
                    heavy[tmp[j]]=1;
                for(j=1;j<=n;j++)
                {
                    bool flag=true;
                    for(p=0;p<2*x;p++)
                    {
                        if(j==tmp[p])
                        {
                            flag=false;
                            break;
                        }
                    }
                    if(flag)
                        normal[j]=1;
                }
            }
            else if(ch=='=')
            {
                for(j=0;j<2*x;j++)
                    normal[tmp[j]]=1;
            }
            else if(ch=='>')
            {
                for(j=0;j<x;j++)
                    heavy[tmp[j]]=1;
                for(j=x;j<2*x;j++)
                    light[tmp[j]]=1;
                for(j=1;j<=n;j++)
                {
                    bool flag =true;
                    for(p=0;p<2*x;p++)
                    {
                        if(j==tmp[p])
                        {
                            flag=false;
                            break;
                        }
                    }
                    if(flag)
                        normal[j]=1;
                }
            }
        }
        int mark,count=0;
        for(i=1;i<=n;i++)
        {
            if(normal[i])
                continue;
            if(light[i]&&heavy[i])
                continue;
            mark=i;
            count++;
        }
        if(count>1)
            printf("0\n");
        else
            printf("%d\n",mark);
        return 0;
    }
    
    • 1

    Information

    ID
    20174
    Time
    3000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By