結果
問題 | No.1900 Don't be Powers of 2 |
ユーザー |
![]() |
提出日時 | 2022-04-08 23:04:30 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 108 ms / 2,000 ms |
コード長 | 1,123 bytes |
コンパイル時間 | 970 ms |
コンパイル使用メモリ | 67,712 KB |
実行使用メモリ | 51,440 KB |
最終ジャッジ日時 | 2024-11-28 14:07:33 |
合計ジャッジ時間 | 3,115 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 42 |
ソースコード
#include <stdio.h> #include <vector> #include <atcoder/maxflow> std::vector<int> V[2010]; int color[2010]; void init(int k, int col) { if(color[k]) return; color[k] = col; for(int i=0;i<V[k].size();i++) init(V[k][i],3-col); } std::vector< std::pair<int,int> > edge; int x[2010]; int main() { int a; scanf("%d",&a); for(int i=1;i<=a;i++) scanf("%d",&x[i]); for(int i=1;i<=a;i++) { for(int j=i+1;j<=a;j++) { int val = (x[i]^x[j]); if(val%65536==0) val/=65536; if(val%256==0) val/=256; if(val%16==0) val/=16; if(val%4==0) val/=4; if(val%2==0) val/=2; if(val==1) { V[i].push_back(j); V[j].push_back(i); edge.push_back(std::make_pair(i,j)); } } } for(int i=1;i<=a;i++) init(i,1); atcoder::mf_graph<int> G(2*a+3); int source = 2*a+1, sink = 2*a+2; for(int i=1;i<=a;i++) G.add_edge(source,i,1); for(int i=1;i<=a;i++) G.add_edge(i+a,sink,1); for(int i=0;i<edge.size();i++) { int s = edge[i].first, t = edge[i].second; if(color[s]==2) { int temp = s; s = t; t = temp; } G.add_edge(s,a+t,1); } printf("%d",a-G.flow(source,sink)); }