結果

問題 No.451 575
ユーザー ykun03ykun03
提出日時 2016-12-03 02:18:37
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 848 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 55,256 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-05-09 19:07:20
合計ジャッジ時間 4,502 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

int main(){
  int n;
  cin >> n;
  if(n == 1){
    int b;
    cin >> b;
    if(b == 1){
      cout << -1 << endl;
      return 0;
    }
    cout << 2 << endl;
    cout << 1 << endl;
    cout << b-1 << endl;
    return 0;
  }
  int *a = new int[n+2], *b = new int[n+1];
  for (int j = 1; j <= n; ++j) cin >> b[j];

  int flag = 1;
  for(a[2] = b[2] + 1; a[2] < b[1]; ++a[2]){
    flag = 1;
    a[1] = b[1] - a[2];
    a[3] = a[2] - b[2];
    int i = 3;
    for (; i <= n && flag; ++i){
      if(i%2 == 1){
        a[i+1] = b[i] - a[i];
      } else {
        a[i+1] = a[i] - b[i];
      }
      flag = a[i+1] >= 1;
    }
    if(flag) break;
  }

  if(flag){
    cout << n+1 << endl;
    for(int i = 1; i <= n+1; i++){
      cout << a[i] << endl;
    }
  } else {
    cout << -1 << endl;
  }
  
  return 0;
}
0