QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#302259#5042. FlowLittleXi#WA 0ms10388kbC++171.5kb2024-01-10 18:11:452024-01-10 18:11:46

Judging History

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

  • [2024-01-10 18:11:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:10388kb
  • [2024-01-10 18:11:45]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

const int maxN=100000+5;

int a[maxN],b[maxN],s[maxN],id[maxN],vis[maxN],rv[maxN];
int n,m;

vector<int> G[maxN],vec[maxN];

void pre_treat()
{
    for (int i=2;i<=n;++i)
    {
        for (long long j=1ll*i*i;j<=n;j*=i)
        {
            G[i].push_back(j); G[j].push_back(i);
            vec[j].push_back(i);
            // printf("i=%d %d\n",i,j);
        }
    }
}

void DFS(int u)
{
    id[u]=++m; s[m]=u;
    rv[m]=u;
    vis[u]=1;
    for (auto v:G[u])
    {
        if (vis[v]) continue;
        DFS(v);
    }
}

long long cal()
{
    long long res=0;
    for (int sta=0;sta<(1<<m);++sta)
    {
        long long tmp=0;
        // printf("s=%d\n",sta);
        for (int j=1;j<=m;++j)
        {
            if (!((1<<(j-1))&sta)) continue;
            tmp+=a[rv[j]];
            for (auto i:vec[rv[j]])
            {
                if (!((1<<(id[i]-1))&sta)) continue;
                // printf("j=%d %d\n",j,i);
                tmp-=b[rv[j]];
            }
        }
        res=max(tmp,res);
    }
    return res;
}

int main()
{
    // freopen("m2.in","r",stdin); 
    scanf("%d",&n);
    for (int i=1;i<=n;++i) scanf("%d",&a[i]);
    for (int i=1;i<=n;++i) scanf("%d",&b[i]);
    pre_treat();
    long long ans=0;
    for (int u=1;u<=n;++u)
    {
        if (vis[u]) continue;
        m=0; DFS(u);
        // for (int i=1;i<=m;++i) printf("%d ",s[i]); puts("");
        ans+=cal();
    }
    printf("%lld\n",ans);
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 10388kb

input:

4 3
1 2 1
2 3 2
3 4 3

output:

6

result:

wrong answer 1st numbers differ - expected: '1', found: '6'