結果

問題 No.1896 Arrays and XOR Procedure 2
ユーザー tnakao0123tnakao0123
提出日時 2022-04-09 01:47:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,595 bytes
コンパイル時間 695 ms
コンパイル使用メモリ 50,116 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-19 06:05:03
合計ジャッジ時間 7,086 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 3 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1896.cc:  No.1896 Arrays and XOR Procedure 2 - yukicoder
 */

#include<cstdio>
#include<algorithm>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 3000;
const int MAX_K = 10000;

enum { OPA = 1, OPB = 2 };

/* typedef */

typedef pair<int,int> pii;

struct Op {
  int t, p, q;
  Op() {}
  Op(int _t, int _p, int _q): t(_t), p(_p), q(_q) {}
  void print() { printf("%d %d %d\n", t, p + 1, q + 1); }
};

/* global variables */

int as[MAX_N], bs[MAX_N];
Op ops[MAX_K];

/* subroutines */

pii getmsb(int n, int v[]) {
  int msb = 1, x = -1;
  for (int i = 0; i < n; i++) {
    while ((msb << 1) <= v[i]) msb <<= 1;
    if (v[i] & msb) x = i;
  }
  return pii(msb, x);
}

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  for (int i = 0; i < n; i++) scanf("%d", bs + i);

  pii pa = getmsb(n, as), pb = getmsb(n, as);
  int amsb = pa.first, ax = pa.second;
  int bmsb = pb.first, bx = pb.second;

  int k = 0;
  if (amsb < bmsb) {
    ops[k++] = Op(OPA, ax, bx);
    amsb = bmsb;
    as[ax] ^= bs[bx];
  }

  for (int i = 0; i < n; i++)
    if (! (bs[i] & amsb)) {
      ops[k++] = Op(OPB, ax, i);
      bs[i] ^= as[ax];
    }

  for (int i = 0; i < n; i++)
    if (as[i] & amsb) {
      ops[k++] = Op(OPB, i, 0);
      as[i] ^= bs[0];
    }

  printf("%d\n", k);
  for (int i = 0; i < k; i++) ops[i].print();

  if (false) {
    int maxa = *max_element(as, as + n);
    int minb = *min_element(bs, bs + n);
    if (maxa < minb) puts("OK");
    else puts("NG");
  }
  return 0;
}
0