結果

問題 No.1017 Reiwa Sequence
ユーザー 👑 hos.lyrichos.lyric
提出日時 2020-04-03 21:38:33
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 703 ms / 2,000 ms
コード長 2,293 bytes
コンパイル時間 1,602 ms
コンパイル使用メモリ 117,880 KB
実行使用メモリ 45,140 KB
最終ジャッジ日時 2023-09-04 07:09:45
合計ジャッジ時間 26,756 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 145 ms
11,820 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 625 ms
35,852 KB
testcase_13 AC 617 ms
35,672 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 142 ms
11,076 KB
testcase_20 AC 141 ms
12,088 KB
testcase_21 AC 143 ms
12,664 KB
testcase_22 AC 141 ms
11,100 KB
testcase_23 AC 140 ms
11,352 KB
testcase_24 AC 141 ms
11,864 KB
testcase_25 AC 142 ms
12,084 KB
testcase_26 AC 142 ms
11,620 KB
testcase_27 AC 140 ms
11,352 KB
testcase_28 AC 141 ms
11,868 KB
testcase_29 AC 139 ms
11,560 KB
testcase_30 AC 141 ms
11,276 KB
testcase_31 AC 140 ms
11,884 KB
testcase_32 AC 140 ms
11,684 KB
testcase_33 AC 139 ms
12,132 KB
testcase_34 AC 141 ms
11,076 KB
testcase_35 AC 140 ms
12,080 KB
testcase_36 AC 142 ms
11,336 KB
testcase_37 AC 139 ms
11,356 KB
testcase_38 AC 140 ms
11,560 KB
testcase_39 AC 142 ms
12,096 KB
testcase_40 AC 679 ms
40,008 KB
testcase_41 AC 675 ms
40,776 KB
testcase_42 AC 683 ms
41,324 KB
testcase_43 AC 672 ms
39,268 KB
testcase_44 AC 677 ms
39,120 KB
testcase_45 AC 686 ms
40,616 KB
testcase_46 AC 682 ms
40,872 KB
testcase_47 AC 668 ms
39,468 KB
testcase_48 AC 703 ms
45,088 KB
testcase_49 AC 682 ms
45,140 KB
testcase_50 AC 664 ms
43,480 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 138 ms
11,084 KB
testcase_53 AC 141 ms
12,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }




void main() {
  try {
    for (; ; ) {
      const N = readInt();
      auto A = new long[N];
      foreach (i; 0 .. N) {
        A[i] = readLong();
      }
      
      int[] ans;
      
      const m = min(N, 21);
      alias Entry = Tuple!(long, "sum", int, "id");
      auto es = new Entry[1 << m];
      foreach (h; 0 .. 1 << m) {
        es[h].id = h;
      }
      foreach (i; 0 .. m) {
        foreach (h; 0 .. 1 << i) {
          es[h | 1 << i].sum = es[h].sum + A[i];
        }
      }
      es.sort;
      foreach (h; 0 .. (1 << m) - 1) {
        if (es[h].sum == es[h + 1].sum) {
          ans = new int[N];
          foreach (i; 0 .. m) {
            if (es[h].id & 1 << i) {
              ++ans[i];
            }
            if (es[h + 1].id & 1 << i) {
              --ans[i];
            }
          }
          break;
        }
      }
      
      if (!ans.empty) {
        writeln("Yes");
        foreach (i; 0 .. N) {
          if (i > 0) write(" ");
          write(ans[i] * A[i]);
        }
        writeln();
      } else {
        writeln("No");
      }
    }
  } catch (EOFException e) {
  }
}
0