結果

問題 No.790 ちきんの括弧並べ
ユーザー GrenacheGrenache
提出日時 2019-04-28 11:10:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 389 ms / 2,000 ms
コード長 1,082 bytes
コンパイル時間 3,859 ms
コンパイル使用メモリ 75,048 KB
実行使用メモリ 41,980 KB
最終ジャッジ日時 2024-05-08 22:49:36
合計ジャッジ時間 6,654 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
40,488 KB
testcase_01 AC 112 ms
40,476 KB
testcase_02 AC 113 ms
40,196 KB
testcase_03 AC 110 ms
40,308 KB
testcase_04 AC 124 ms
41,288 KB
testcase_05 AC 117 ms
40,992 KB
testcase_06 AC 127 ms
41,160 KB
testcase_07 AC 125 ms
40,616 KB
testcase_08 AC 185 ms
40,456 KB
testcase_09 AC 389 ms
41,380 KB
testcase_10 AC 128 ms
41,808 KB
testcase_11 AC 125 ms
41,980 KB
testcase_12 AC 153 ms
41,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.Scanner;


public class Main_yukicoder790 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();

		int ans = 0;
		
		// n個のビットのうち、i個のビットが立っているmaskのパターンの生成
		int i = n;
		n = 2 * i;

		int mask = (0x1 << i) - 1;
		while (mask < 0x1 << n) {
			// maskに対する処理

			int cnt = 0;
			for (int j = 0; j < n; j++) {
				if ((0x1 << j & mask) != 0) {
					cnt++;
				} else {
					cnt--;
				}

				if (cnt < 0) {
					break;
				}
			}
			if (cnt == 0) {
				ans++;
			}

			// 次のmaskの計算
			int xx = mask & -mask;
			int yy = mask + xx;
			mask = ((mask & ~yy) / xx >> 1) | yy;
		}
		
		pr.println(ans);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}
0