QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#302249#5050. ValueLittleXi#WA 2ms10432kbC++171.5kb2024-01-10 18:05:512024-01-10 18:05:52

Judging History

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

  • [2024-01-10 18:05:52]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10432kb
  • [2024-01-10 18:05:51]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 10280kb

input:

4
1 1 1 2
1 1 1 1

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 2ms
memory: 8904kb

input:

4
1 1 1 1
1 1 1 2

output:

3

result:

ok 1 number(s): "3"

Test #3:

score: 0
Accepted
time: 0ms
memory: 10332kb

input:

1
4
10

output:

4

result:

ok 1 number(s): "4"

Test #4:

score: 0
Accepted
time: 0ms
memory: 10028kb

input:

2
6 8
2 4

output:

14

result:

ok 1 number(s): "14"

Test #5:

score: 0
Accepted
time: 2ms
memory: 10432kb

input:

5
1 6 10 5 1
7 1 5 10 9

output:

18

result:

ok 1 number(s): "18"

Test #6:

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

input:

10
2 2 8 10 2 10 8 10 6 5
9 2 7 4 2 2 8 3 10 10

output:

50

result:

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