結果
問題 | No.1896 Arrays and XOR Procedure 2 |
ユーザー |
![]() |
提出日時 | 2022-09-08 13:07:51 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 108 ms / 2,000 ms |
コード長 | 2,403 bytes |
コンパイル時間 | 2,270 ms |
コンパイル使用メモリ | 77,820 KB |
実行使用メモリ | 52,312 KB |
最終ジャッジ日時 | 2024-11-24 06:30:09 |
合計ジャッジ時間 | 8,478 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int[] countsA = new int[n]; int maxA = 0; int aIdx = 0; for (int i = 0; i < n; i++) { countsA[i] = getCount(sc.nextInt()); if (maxA < countsA[i]) { maxA = countsA[i]; aIdx = i; } } int[] countsB = new int[n]; int maxB = 0; int bIdx = 0; for (int i = 0; i < n; i++) { countsB[i] = getCount(sc.nextInt()); if (maxB < countsB[i]) { maxB = countsB[i]; bIdx = i; } } int ans = 0; StringBuilder sb = new StringBuilder(); if (maxA < maxB) { sb.append("1 1 ").append(bIdx + 1).append("\n"); ans++; maxA = maxB; aIdx = 0; countsA[0] = maxB; } for (int i = 0; i < n; i++) { if (countsB[i] < maxA) { sb.append("2 ").append(aIdx + 1).append(" ").append(i + 1).append("\n"); ans++; } } for (int i = 0; i < n; i++) { if (countsA[i] == maxA) { sb.append("1 ").append(i + 1).append(" 1\n"); ans++; } } System.out.println(ans); System.out.print(sb); } static int getCount(int x) { int count = 0; while (x > 0) { count++; x >>= 1; } return count; } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }