結果

問題 No.1837 Same but Different
ユーザー tnakao0123tnakao0123
提出日時 2022-02-15 10:19:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,287 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 42,220 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-11 16:56:28
合計ジャッジ時間 2,237 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1837.cc:  No.1837 Same but Different - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 3000;
const int MAX_A = 10000;

/* typedef */

/* global variables */

int as[MAX_N], bs[MAX_N];
bool used[MAX_A * 2 + 1];

/* subroutines */

void printv(int n, int v[]) {
  for (int i = 0; i < n; i++)
    printf("%d%c", v[i], (i + 1 < n) ? ' ' : '\n');
}

bool check(int n) {
  fill(used, used + MAX_A * 2 + 1, false);

  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      used[as[i] + as[j]] = true;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      if (used[bs[i] + bs[j]]) {
	printf("  check NG: sum=%d\n", bs[i] + bs[j]);
	return false;
      }
  return true;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  int asum = 0, bsum = 0;
  for (int i = 0; i < n; i++) as[i] = i * 3, asum += as[i];
  for (int i = 0; i < n; i++) bs[i] = i * 3 + 7, bsum += bs[i];

  int r = n % 3;
  if (r == 1) as[0]++, asum++;
  else if (r == 2) as[0]++, as[1]++, asum += 2;

  for (int i = n - 1; bsum > asum;) {
    as[i] += 3, asum += 3;
    if (--i < 2) i = n - 1;
  }

  printv(n, as), printv(n, bs);

  //if (check(n)) puts("OK");
  //else puts("NG");
  return 0;
}
0