QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#302259 | #5042. Flow | LittleXi# | WA | 0ms | 10388kb | C++17 | 1.5kb | 2024-01-10 18:11:45 | 2024-01-10 18:11:46 |
Judging History
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: 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'