結果
| 問題 |
No.3345 Reducible Sequence
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-13 21:25:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 998 ms / 2,000 ms |
| コード長 | 1,066 bytes |
| コンパイル時間 | 678 ms |
| コンパイル使用メモリ | 77,332 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-11-13 21:26:15 |
| 合計ジャッジ時間 | 5,638 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include<iostream>
#include<cassert>
using namespace std;
#include<algorithm>
#include<vector>
struct bimatch{
int n;
vector<vector<int> >G;
vector<int>match;
vector<bool>used;
bimatch(int _n=0):n(_n),G(n),match(n),used(n){}
void add_edge(int u,int v)
{
G[u].push_back(v);
G[v].push_back(u);
}
bool dfs(int v)
{
used[v]=true;
for(int u:G[v])
{
int w=match[u];
if(w<0||!used[w]&&dfs(w))
{
match[v]=u;
match[u]=v;
return true;
}
}
return false;
}
int count()
{
int ans=0;
bool flag=true;
fill(match.begin(),match.end(),-1);
while(flag)
{
flag=false;
fill(used.begin(),used.end(),false);
for(int v=0;v<n;v++)if(!used[v]&&match[v]<0&&dfs(v))ans++,flag=true;
}
return ans;
}
};
int N,A[5000];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>N;
for(int i=0;i<N;i++)cin>>A[i];
int L=1,R=N+1;
while(R-L>1)
{
int m=(L+R)/2;
bimatch G(N+m);
for(int x=1;x<=m;x++)for(int i=0;i<N;i++)if(A[i]%x==0)G.add_edge(x-1,m+i);
if(G.count()==m)L=m;
else R=m;
}
cout<<L<<endl;
}