QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#501416#7558. Abstractucup-team1525RE 1ms4256kbC++171.8kb2024-08-02 18:04:162024-08-02 18:04:16

Judging History

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

  • [2024-08-02 18:04:16]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:4256kb
  • [2024-08-02 18:04:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int B = 1;
const ll W=1ll<<B;
int n,m;
const int N=10005;
// int a[N];
vector<int> e[N],ord;
int d[N];
struct bigint
{
    int len;
    ll a[4005];
}a[N];

bigint operator + (const bigint &x,const bigint &y){
    bigint z;
    z.len=max(x.len,y.len);
    ll t=0;
    for(int i=0;i<z.len;i++){
        z.a[i]=t+x.a[i]+y.a[i];
        t=z.a[i]>>B;
        z.a[i]=z.a[i]&(W-1);
    }
    while(t){
        z.a[z.len]=t&(W-1);
        z.len++;
        t>>=B;
    }
    return z;
}
// void mult(bigint &x){
//     ll t=0;
//     for(int i=0;i<x.len;i++){
//         x.a[i]=x.a[i]*2+t;
//         t=x.a[i]>>B;
//         x.a[i]=x.a[i]&(W-1);
//     }
//     while(t){
//         x.a[x.len]=t&(W-1);
//         x.len++;
//         t>>=B;
//     }
// }
int bl(ll x)
{
    int sum=0;
    while (x)
    {
        ++sum;
        x>>=1;
    }
    return sum-1;
}
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1,x;i<=n;++i)
    {
        scanf("%d",&x);
        a[i].len=1;
        a[i].a[0]=x;
    }
    for (int i=1,u,v;i<=m;++i)
    {
        scanf("%d%d",&u,&v);
        e[u].push_back(v);
        d[v]++;
    }
    queue<int> q;
    for (int i=1;i<=n;++i)
        if (d[i]==0)
            q.push(i);
    while (!q.empty())
    {
        int x=q.front();
        q.pop();
        ord.push_back(x);
        for (int y:e[x])
        {
            --d[y];
            if (!d[y])
                q.push(y);
        }
    }
    for (int x:ord)
    { 
        a[x]=a[x]+a[x];
        for (int y:e[x])
            a[y]=a[x]+a[y];
    }
    int o=ord.back();
    if (a[o].len==1&&a[o].a[0]==0)
    {
        puts("0");
        return 0;
    }
    printf("%d\n",(a[o].len-1)*B+bl(a[o].a[a[o].len-1]));
    return 0;
}

詳細信息

Test #1:

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

input:

3 2
1 1 1
1 2
2 3

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

6 8
1 1 4 5 1 4
1 4
1 5
2 3
2 5
3 4
4 5
4 6
5 6

output:

8

result:

ok 1 number(s): "8"

Test #3:

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

input:

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

output:

9

result:

ok 1 number(s): "9"

Test #4:

score: -100
Runtime Error

input:

7286 80481
637288250 628935175 588324396 766398783 663989874 865498593 695497968 630237220 19939888 448367842 412696777 111291257 304805809 585852799 58270069 391993802 606944382 827515045 389862501 643981354 160381074 324288921 257053597 980043955 417281046 870855665 360154617 60327683 966755927 55...

output:


result: