結果
問題 | No.343 手抜き工事のプロ |
ユーザー |
|
提出日時 | 2016-02-13 01:40:01 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 925 bytes |
コンパイル時間 | 1,331 ms |
コンパイル使用メモリ | 161,580 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 05:26:01 |
合計ジャッジ時間 | 2,159 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:6:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 6 | int n, l; scanf("%d", &n); scanf("%d", &l); | ~~~~~^~~~~~~~~~ main.cpp:6:41: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 6 | int n, l; scanf("%d", &n); scanf("%d", &l); | ~~~~~^~~~~~~~~~ main.cpp:16:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 16 | scanf("%d", &x); | ~~~~~^~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int n, l; scanf("%d", &n); scanf("%d", &l); if (n == 1) { cout << 0 << endl; return 0; } vector<int> xs(n-1); for (auto &x : xs) { scanf("%d", &x); } int m = 0; for (int i = 0; i < n-1; i++) { if (i == 0 && abs(xs[i]) >= l) { cout << -1 << endl; return 0; } if (i != 0) { if (abs(xs[i - 1] - xs[i]) >= l) { cout << -1 << endl; return 0; } } m++; } vector<double> gs(n - 1); gs[n - 2] = xs[n - 2]; for (int i = n - 3; i >= 0; i--) { gs[i] = xs[i] + gs[i + 1]; } for (int i = 0; i < n-1; i++) { double g = gs[i]; if (n - 1 - i != 0) g /= n - 1 - i; if (xs[i] - l / 2.0 < g && g < xs[i] + l / 2.0) { if (i == 0) { if (-1 * l / 2.0 < g && g < l / 2.0) m--; } else if (xs[i - 1] - l / 2.0 < g && g < xs[i - 1] + l / 2.0) m--; } } cout << m << endl; return 0; }