結果

問題 No.1727 [Cherry 3rd Tune] Stray
ユーザー chocoruskchocorusk
提出日時 2021-09-13 22:12:52
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,260 bytes
コンパイル時間 3,341 ms
コンパイル使用メモリ 77,264 KB
実行使用メモリ 41,728 KB
最終ジャッジ日時 2024-04-16 13:36:40
合計ジャッジ時間 4,760 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		//FastScanner scanner=new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n=scanner.nextInt();
		UnionFind uf=new UnionFind(1<<(2*n));
		for(int i=0; i<(1<<(2*n)); i++) {
			int x=0, y=0;
			for(int j=0; j<n; j++) {
				if((i&(1<<j))!=0) {
					if(j==n-1) x^=1;
					else x^=(1<<(j+1));
					y^=(1<<(j+n));
				}
				if((i&(1<<(j+n)))!=0) {
					if(j==0) x^=(1<<(2*n-1));
					else x^=(1<<(j-1+n));
					y^=(1<<j);
				}
			}
			uf.unite(i, x);
			uf.unite(i, y);
		}
		out.println(uf.cmp);
		scanner.close();
		out.close();
	}
}
class UnionFind{
	int n;
	int[] par;
	int cmp;
	public UnionFind(int n) {
		this.n=n;
		this.par=new int[n];
		Arrays.fill(this.par, -1);
		this.cmp=n;
	}
	public int find(int x) {
		if(par[x]<0) return x;
		return par[x]=find(par[x]);
	}
	public boolean unite(int x, int y) {
		x=find(x);
		y=find(y);
		if(x==y) {
			return false;
		}
		cmp--;
		if(par[x]>par[y]) {
			int tmp=x;
			x=y;
			y=tmp;
		}
		par[x]+=par[y];
		par[y]=x;
		return true;
	}
	public boolean same(int x, int y) {
		return find(x)==find(y);
	}
}
0