QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#661444#9449. New School TermForever_Young#WA 1ms7912kbC++232.7kb2024-10-20 16:14:422024-10-20 16:14:43

Judging History

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

  • [2024-10-20 16:14:43]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7912kb
  • [2024-10-20 16:14:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define data dataa
using LL=long long;
using ULL=unsigned long long;
using LD=long double;
#define gcd(x,y) __gcd(unsigned(x),unsigned(y))
const int MOD=int(1e9)+7;
const int inv2=(MOD+1)/2;
const int N=5010;
int f[N],tmp[N],num[N<<1][2],fa[N<<1],co[N<<1],n,m;
int pre[N<<1][N];
vector<int>V[N<<1];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
void add(int f[],int x)
{
    for(int i=n;i>=0;i--)if(i>=x)f[i]=(f[i]+f[i-x])%MOD;
}
void del(int f[],int x)
{
    for(int i=0;i<=n;i++)
    if(!x)f[i]=LL(f[i])*inv2%MOD;
    else if(i>=x)f[i]=(f[i]-f[i-x]+MOD)%MOD;
}
const int M=int(1e6)+10;
int Ex[M],Ey[M];
int main()
{
    scanf("%d%d",&n,&m);
    int sum1=0;
    rep(i,2*n)V[i].pb(i),co[i]=0,num[i][0]=1,num[i][1]=0,fa[i]=i;
    f[0]=1;
    rep(i,2*n)add(f,num[i][0]-num[i][1]);
    rep(i,m)scanf("%d%d",&Ex[i],&Ey[i]);
    for(int i=m;i;i--)
    {
        int x=Ex[i],y=Ey[i];
        int a=find(x),b=find(y);
        if(a==b)continue;
        del(f,num[a][0]-num[a][1]);
        del(f,num[b][0]-num[b][1]);
        for(int j=0;j<=n;j++)tmp[j]=f[j];
        sum1-=num[a][1]+num[b][1];
        int num0,num1;
        if(co[x]==co[y])num0=num[a][0]+num[b][1],num1=num[a][1]+num[b][0];
        else num0=num[a][0]+num[b][0],num1=num[a][1]+num[b][1];
        if(num0<num1)swap(num0,num1);
        int nsum1=sum1+num1;
        add(tmp,num0-num1);
        bool newcoy=!co[x];
        if(!tmp[n-nsum1])newcoy=!newcoy;
        bool change=newcoy!=co[y];
        if(change)for(auto x:V[b])co[x]^=1;
        fa[b]=a;
        for(auto x:V[b])V[a].pb(x);
        num[a][0]+=num[b][change];
        num[a][1]+=num[b][!change];
        if(num[a][0]<num[a][1])
        {
            swap(num[a][0],num[a][1]);
            for(auto x:V[a])co[x]^=1;
        }
        sum1+=num[a][1];
        add(f,num[a][0]-num[a][1]);
    }
    vector<int>id;
    rep(i,2*n)if(find(i)==i)id.pb(i);
    int cnt=id.size();
    f[0]=1;
    for(int i:id)
    {
        memset(tmp,0,sizeof(tmp));
        for(int j=min(num[i][0],num[i][1]);j<=n;j++)
        {
            if(j>=num[i][0]&&f[j-num[i][0]])tmp[j]=1,pre[i][j]=0;
            if(j>=num[i][1]&&f[j-num[i][1]])tmp[j]=1,pre[i][j]=1;
        }
        for(int j=0;j<=n;j++)f[j]=tmp[j];
    }
    // if(!f[n])
    // {
    //     rep(i,n)printf("0");
    //     rep(i,n)printf("1");
    //     puts("");
    //     return 0;
    // }
    int now=n;
    for(int ids=cnt-1;ids>=0;ids--)
    {
        int i=id[ids];
        if(pre[i][now])for(auto x:V[i])co[x]^=1;
        now-=num[i][pre[i][now]];
    }
    rep(i,2*n)printf("%d",co[i]);puts("");
    return 0;
}

詳細信息

Test #1:

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

input:

2 4
1 3
2 4
1 4
1 2

output:

0101

result:

ok Output is valid. OK

Test #2:

score: 0
Accepted
time: 1ms
memory: 7912kb

input:

3 7
2 5
1 3
4 6
2 6
4 5
2 4
5 6

output:

110010

result:

ok Output is valid. OK

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3828kb

input:

1 0

output:

11

result:

wrong answer The number of 0s must be equal to that of 1s.