QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#769576 | #9574. Strips | __stick | WA | 2ms | 9788kb | C++20 | 3.0kb | 2024-11-21 18:16:34 | 2024-11-21 18:16:41 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC optimize (3,"Ofast","inline")
using namespace std;
const int MAXN=1e6+10;
const int mod=1e9+7;
#define INF (0x3f3f3f3f)
int que[MAXN];
int hd[MAXN];
int d[MAXN];
int s, t, etot = 1;
int tot;
int Hd,Tl;
int vis[MAXN];
int mincost;
int maxflow;
struct Edge {
int to, nxt, val, flow;
} e[MAXN * 6];
void adde(int x, int y, int z, int w) {
e[++etot] = {y, hd[x], z, w};
hd[x] = etot;
}
// adde(x, y, val, flow), adde(x, y, -val, 0);
bool bfs() {
memset(d, 0x3f, (tot + 1) * 4), Hd = 1, Tl = 0, que[++Tl] = s, d[s] = 0;
while (Hd <= Tl) {
int u = que[Hd++];
vis[u] = 0;
for (int i = hd[u]; i; i = e[i].nxt) {
int v = e[i].to;
if (e[i].flow == 0) continue;
if (d[u] + e[i].val < d[v]) {
d[v] = d[u] + e[i].val;
if (vis[v] == 0) que[++Tl] = v, vis[v] = 1;
}
}
}
return d[t] != INF;
}
int dfs(int u, int lim) {
if (u == t) return lim;
int flow = 0; vis[u] = 1;
for (int i = hd[u]; i && lim; i = e[i].nxt) {
int v = e[i].to;
if (vis[v] || e[i].flow == 0 || d[v] != d[u] + e[i].val) continue;
int f = dfs(v, min(e[i].flow, lim));
if (f == 0) d[v] = INF;
e[i].flow -= f, e[i ^ 1].flow += f, flow += f, lim -= f, mincost += e[i].val * f;
}
return vis[u] = 0, flow;
}
void dinic() {
int flow = 0;
while (bfs()) maxflow += dfs(s, INF);
}
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,a,b) for(int i=(a);i>=(b);--i)
int a[305];
map<int,vector<int>> p;
map<int,int> id;
int idx=0;
inline int ID(int x){
if(id.count(x))return id[x];
return id[x]=++idx;
}
map<int,bool> Mp;
signed main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
For(i,1,n){
int x=a[i];
for(int j=2;j*j<=x;j++){
if(x%j==0)p[a[i]].push_back(j);
while(x%j==0)x/=j;
}
if(x>1)p[a[i]].push_back(x);
}
// adde(x, y, val, flow), adde(x, y, -val, 0);
s=++idx,t=++idx;
For(i,1,n){
adde(s,ID(a[i]),0,1),adde(ID(a[i]),s,0,0);
}
queue<int> q;
For(i,1,n){q.push(a[i]);Mp[a[i]]=1;}
while(!q.empty()){
int x=q.front(); q.pop();
// cout<<"QWE "<<x<<'\n';
adde(ID(x),t,0,1),adde(t,ID(x),0,0);
if(x==1)continue;
for(int dd:p[x]){
int y=x/dd;
adde(ID(x),ID(y),-1,INF),adde(ID(y),ID(x),1,0);
// cout<<x<<' '<<y<<'\n';
if(Mp[y])continue;
if(y!=1&&!p[y].size()){
if(y%dd==0)p[y]=p[x];
else for(int tt:p[x])if(tt!=dd)p[y].push_back(tt);
}
Mp[y]=1;
q.push(y);
}
}
tot=idx;
dinic();
// cout<<maxflow<<'\n';
cout<<-mincost<<'\n';
return 0;
}
/*
6 1
a?b??c
2 2 2
*/
詳細信息
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 9788kb
input:
4 5 2 3 16 7 11 2 9 14 13 5 3 2 4 11 6 10 2 1 11 2 1 2 6 1 5 3 2 1 2 6 1 5 2
output:
4
result:
wrong output format Unexpected end of file - int32 expected (test case 1)