結果

問題 No.370 道路の掃除
ユーザー hogeover30hogeover30
提出日時 2016-05-21 04:12:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 593 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 58,184 KB
最終ジャッジ日時 2024-04-27 02:20:49
合計ジャッジ時間 879 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:8:5: error: 'vector' was not declared in this scope
    8 |     vector<int> L(1), R(1);
      |     ^~~~~~
main.cpp:3:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | using namespace std;
main.cpp:8:12: error: expected primary-expression before 'int'
    8 |     vector<int> L(1), R(1);
      |            ^~~
main.cpp:12:13: error: 'L' was not declared in this scope
   12 |             L.push_back(-d);
      |             ^
main.cpp:14:13: error: 'R' was not declared in this scope
   14 |             R.push_back(d);
      |             ^
main.cpp:16:16: error: 'L' was not declared in this scope
   16 |     sort(begin(L), end(L));
      |                ^
main.cpp:17:16: error: 'R' was not declared in this scope
   17 |     sort(begin(R), end(R));
      |                ^

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n, m; cin>>n>>m;
    vector<int> L(1), R(1);
    for(int i=0; i<m; ++i) {
        int d; cin>>d;
        if (d<0)
            L.push_back(-d);
        else
            R.push_back(d);
    }
    sort(begin(L), end(L));
    sort(begin(R), end(R));

    int res=1<<30;
    for(int k=0; k<=n; ++k) {
        int x=min<int>(k, L.size()-1);
        if (n-x<R.size()) res=min(res, L[x]*2+R[n-x]);
        x=min<int>(k, R.size()-1);
        if (n-x<L.size()) res=min(res, R[x]*2+L[n-x]);
    }
    cout<<res<<endl;
}
0