結果

問題 No.451 575
ユーザー ei1333333ei1333333
提出日時 2016-12-02 01:04:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 1,119 bytes
コンパイル時間 2,027 ms
コンパイル使用メモリ 149,696 KB
実行使用メモリ 4,420 KB
最終ジャッジ日時 2023-08-22 12:49:50
合計ジャッジ時間 5,916 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 9 ms
4,376 KB
testcase_07 AC 64 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 50 ms
4,380 KB
testcase_11 AC 152 ms
4,380 KB
testcase_12 AC 201 ms
4,376 KB
testcase_13 AC 195 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 12 ms
4,376 KB
testcase_17 AC 65 ms
4,420 KB
testcase_18 AC 64 ms
4,376 KB
testcase_19 AC 45 ms
4,376 KB
testcase_20 AC 9 ms
4,380 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 198 ms
4,376 KB
testcase_24 AC 104 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 7 ms
4,380 KB
testcase_30 AC 69 ms
4,384 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 14 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

typedef long long int64;
int64 RANGE = 1000000000000000000LL;


// A_0 A_1 A_2 A_3
//  B_0=A_1+A_2   A_2=B_0-A_1
//  B_1=A_2-A_3   A_3=A_2-B_1
//  B_2=A_3+A_4
//  B_3=A_4-A_5

int main()
{
  int N;
  int64 B[100000];

  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> B[i];
  }

  int64 initial = 1;
  set< int64 > fos;
  while(true) {
    int64 xs = initial;
    if(initial <= 0 || initial > RANGE || fos.count(initial)) {
      break;
    }
    fos.insert(initial);
    bool flag = false;
    for(int i = 0; i < N; i++) {
      if(i & 1) xs = xs - B[i];
      else xs = B[i] - xs;
      if(xs <= 0) {
        initial += -xs + 1;
        flag = true;
        break;
      }
      if(xs > RANGE) {
        initial -= xs + 1;
        flag = true;
        break;
      }
    }

    if(!flag) {
      cout << N + 1 << endl;
      int64 rev = initial;
      cout << rev << endl;
      for(int i = 0; i < N; i++) {
        if(i & 1) rev = rev - B[i];
        else rev = B[i] - rev;
        cout << rev << endl;
      }
      return (0);
    }


  }
  cout << -1 << endl;

}
0