結果
| 問題 | No.451 575 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-16 17:13:34 |
| 言語 | C++17(gcc12) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 35 ms / 2,000 ms |
| コード長 | 1,294 bytes |
| 記録 | |
| コンパイル時間 | 937 ms |
| コンパイル使用メモリ | 110,776 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-03-08 21:16:25 |
| 合計ジャッジ時間 | 3,280 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:23:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | for (auto &&i : b) scanf("%lld", &i);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
int main() {
int n;
cin >> n;
vector<ll> b(n);
for (auto &&i : b) scanf("%lld", &i);
vector<ll> p(n+1), q(n+1); // px+q;
ll l = 1, r = 1e18;
ll ans1 = 1, ans2 = 1e18;
p[0] = 1;
for (int i = 1; i <= n; ++i) {
if(i & 1){
p[i] = -p[i-1];
q[i] = -q[i-1]+b[i-1];
}else {
p[i] = p[i-1];
q[i] = q[i-1]-b[i-1];
}
if(p[i] > 0){
ans1 = max(ans1, l-q[i]);
ans2 = min(ans2, r-q[i]);
if(ans1 > ans2) {
puts("-1");
return 0;
}
}else {
ans1 = max(ans1, q[i]-r);
ans2 = min(ans2, q[i]-l);
if(ans1 > ans2) {
puts("-1");
return 0;
}
}
}
printf("%d\n", n+1);
for (int i = 0; i < n+1; ++i) {
printf("%lld\n", p[i]*ans1+q[i]);
}
return 0;
}