結果
問題 | No.370 道路の掃除 |
ユーザー | kapo |
提出日時 | 2016-05-14 13:18:32 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,129 bytes |
コンパイル時間 | 663 ms |
コンパイル使用メモリ | 66,512 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-06 02:24:19 |
合計ジャッジ時間 | 1,684 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:46:46: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wformat=] 46 | printf("i=%d n=%d road.size=%d\n", i, n, road.size()); | ~^ ~~~~~~~~~~~ | | | | int std::vector<int>::size_type {aka long unsigned int} | %ld main.cpp:43:33: warning: ‘start’ may be used uninitialized in this function [-Wmaybe-uninitialized] 43 | for (i = lm; i <= start && i + n-1 < road.size(); i++) { | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <cstdlib> #include <climits> #define rep(i,a,b) for(int i=a;i<b;i++) using namespace std; int main() { int i, j, n, m, f=0, tmp, max=INT_MAX; vector<int> road; cin >> n >> m; rep(i, 0, m) { cin >> tmp; road.push_back(tmp); if (tmp == 0) f = 1; } if (!f) { road.push_back(0); n++; m++; } sort(road.begin(), road.end()); for (auto i : road) cout << i << " "; cout << endl; int start; rep(i, 0, m) { if (road[i] == 0) start = i; } int sum = 0, left, right, lm; if (start - (n-1) > 0) { lm = start - (n-1); } else { lm = 0; } for (i = lm; i <= start && i + n-1 < road.size(); i++) { left = road[i]; right = road[i + n-1]; printf("i=%d n=%d road.size=%d\n", i, n, road.size()); if (left >= 0) { sum = right; } else if (right <= 0) { sum = abs(left); } else { abs(left) < abs(right) ? sum = abs(left) * 2 + right : sum = abs(left) + right * 2; } cout << "left=" << left << " right=" << right << " sum=" << sum << endl; if (sum < max) { max = sum; } } cout << max << endl; return 0; }