#[allow(unused)] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref() .map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } #[allow(unused)] macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } #[allow(unused)] macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::>() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; } #[allow(unused)] mod rnd { static mut S:usize=88172645463325252; #[inline] pub fn next()->usize{ unsafe{ S=S^S<<7; S=S^S>>9; S } } } #[allow(unused)] #[inline] fn get_time()->f64{ static mut START:f64=-1.; let t=std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs_f64(); unsafe{ if START<0.{START=t;} t-START } } #[cfg(local)] #[allow(unused)] macro_rules! debug{ ($x:expr)=>{ eprintln!("{}: {:?}",stringify!($x),$x); }; ($x:expr,$($l:expr),*)=>{ eprint!("{}: {:?}, ",stringify!($x),$x); debug!($($l),*); } } #[cfg(not(local))] #[allow(unused)] macro_rules! debug{ ($($_:expr),*)=>{} } const N:usize=256; const M:usize=2048; struct In{ edge1:[[Vec;2];N], edge2:[[(usize,bool);3];M] } impl In{ fn input()->In{ input!{ q:[([usize;3],[usize;3]);M] } let mut edge2=[[(0,false);3];M]; for (i,v) in q.iter().enumerate(){ for (j,(id,f)) in v.0.iter().zip(v.1.iter()).enumerate(){ edge2[i][j]=(*id,*f==1); } } let mut edge1=[();N].map(|_|[vec![],vec![]]); for i in 0..M{ for (idx,f) in edge2[i].iter(){ edge1[*idx][*f as usize].push(i); } } In{edge1,edge2} } } struct Out{ out:[bool;N], cnt:[usize;M], edge:[[Vec;2];N] } impl Out{ #[inline] // cnt,edgeの計算はしない fn new()->Out{ let mut out=[false;N]; let mut r=!0; for i in 0..N{ if i&63==0{ r=rnd::next(); } out[i]=r&1==0; r>>=1; } Out{out,cnt:[0;M],edge:[();N].map(|_|[vec![],vec![]])} } #[inline] fn re(&mut self,input:&In,r:usize){ self.cnt.fill(0); for i in 0..N{ for j in 0..2{ self.edge[i][j].clear(); for k in input.edge1[i][j].iter(){ if *ki64{ self.cnt.iter().map(|x|(*x!=0) as i64).sum() } #[inline] fn change(&mut self,add:i64,new:&[(usize,bool)],score:&mut i64)->bool{ let mut diff=0; for &(idx,f) in new{ if self.out[idx]!=f{ for i in self.edge[idx][!f as usize].iter(){ self.cnt[*i]-=1; if self.cnt[*i]==0{ diff-=1; } } for i in self.edge[idx][f as usize].iter(){ self.cnt[*i]+=1; if self.cnt[*i]==1{ diff+=1; } } } } if add<=diff{ *score+=diff; for &(idx,f) in new{ self.out[idx]=f; } true } else{ for &(idx,f) in new{ if self.out[idx]!=f{ for i in self.edge[idx][!f as usize].iter(){ self.cnt[*i]+=1; } for i in self.edge[idx][f as usize].iter(){ self.cnt[*i]-=1; } } } false } } } const TL:f64=1.98; fn sa(r:usize,cur:&mut Out)->bool{ let mut score=cur.score(); let mut iter=0; let mut up=0; let mut th=[0;256]; loop{ if iter&2047==0{ if get_time()>=TL{break;} const LIM:f64=500000.; let p=iter as f64/LIM as f64; if p>=1.{break;} const T:f64=0.5; let heat=T*(1.-p); for i in 0..128{ let id=i<<1; let r=rnd::next(); th[id]=(heat*((r&4294967295) as f64/4294967296.).ln()) as i64; th[id+1]=(heat*((r>>32) as f64/4294967295.).ln()) as i64; } } iter+=1; let rnd=rnd::next(); if cur.change(th[iter&255],&[(rnd%N,rnd>>63==0)],&mut score){ if score==r as i64{break;} up+=1; } } let p=up as f64/iter as f64; debug!(r,iter,p); debug!(score); if cfg!(local){ if score==r as i64{ eprintln!("success"); } else{ eprintln!("failed"); } } assert_eq!(score,cur.score()); score==r as i64 } fn solve(input:&In)->[bool;256]{ let mut out=Out::new(); let mut ans=out.out; let mut best=0; let mut pos=950; let mut range=16; while get_time()<=TL{ out.re(input,pos); if sa(pos,&mut out){ ans=out.out; best=pos; pos+=range; } else{ out.out=ans; range=1.max(range>>1); pos-=range; pos=(pos-range).max(best+1); } } eprintln!("score: {}",best); if cfg!(local){ println!("{best}"); } ans } fn main(){ let input=In::input(); let ans=solve(&input); if !cfg!(local){ for &i in ans.iter(){ print!("{}",i as usize); } println!(); } }