結果

問題 No.3184 Make Same
ユーザー tnakao0123
提出日時 2025-06-21 22:33:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 824 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 45,716 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-21 22:33:39
合計ジャッジ時間 14,340 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:33:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |   for (int i = 0; i < n; i++) scanf("%d", as + i);
      |                               ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 3184.cc:  No.3184 Make Same - yukicoder
 */

#include<cstdio>
#include<algorithm>
#include<utility>

using namespace std;

/* constant */

const int MAX_N = 200000;
const int BN = 30;

/* typedef */

using pii = pair<int,int>;

/* global variables */

int as[MAX_N];
pii ops[BN];

/* subroutines */

/* main */

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

  int m = 0;
  for (int i = BN - 1; i >= 0; i--) {
    int r = 0;
    while (r < n && ! ((as[r] >> i) & 1)) r++;
    if (r > 0 && r < n) {
      ops[m++] = {r, i};
      for (int j = 0; j < r; j++) as[j] |= (1 << i);
      sort(as, as + n);
    }
  }

  printf("%d\n", m);
  for (int i = 0; i < m; i++) {
    auto [r, j] = ops[i];
    printf("1 %d %d\n", r, 1 << j);
  }
  
  return 0;
}
0