結果

問題 No.370 道路の掃除
ユーザー ikdikd
提出日時 2016-07-22 21:25:28
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 704 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 51,800 KB
最終ジャッジ日時 2024-04-24 02:07:41
合計ジャッジ時間 596 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:5: error: ‘vector’ was not declared in this scope
   10 |     vector<int> D(M);
      |     ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    2 | #include<algorithm>
  +++ |+#include <vector>
    3 | 
main.cpp:10:12: error: expected primary-expression before ‘int’
   10 |     vector<int> D(M);
      |            ^~~
main.cpp:12:15: error: ‘D’ was not declared in this scope
   12 |         cin>> D[i];
      |               ^
main.cpp:15:10: error: ‘D’ was not declared in this scope
   15 |     sort(D.begin(), D.end());
      |          ^
main.cpp:16:12: error: expected primary-expression before ‘int’
   16 |     vector<int> po, ne;
      |            ^~~
main.cpp:18:21: error: ‘po’ was not declared in this scope
   18 |         if(D[i]>=0) po.push_back(D[i]);
      |                     ^~
main.cpp:19:14: error: ‘ne’ was not declared in this scope
   19 |         else ne.push_back(D[i]);
      |              ^~
main.cpp:21:13: error: ‘ne’ was not declared in this scope
   21 |     reverse(ne.begin(), ne.end());
      |             ^~
main.cpp:23:12: error: expected primary-expression before ‘int’
   23 |     vector<int> dL(M+1, 1e8), dR(M+1, 1e8);
      |            ^~~
main.cpp:24:5: error: ‘dL’ was not declared in this scope
   24 |     dL[0]=dR[0]=0;
      |     ^~
main.cpp:24:11: error: ‘dR’ was not declared in this scope
   24 |     dL[0]=dR[0]=0;
      |           ^~
main.cpp:26:21: error: ‘po’ was not declared in this scope
   26 |     for(int i=1; i<=po.size(); i++) dR[i]=po[i-1];
      |                     ^~

ソースコード

diff #

#include<iostream>
#include<algorithm>

using namespace std;

int main(){

    int N, M;
    cin>> N>> M;
    vector<int> D(M);
    for(int i=0; i<M; i++){
        cin>> D[i];
    }

    sort(D.begin(), D.end());
    vector<int> po, ne;
    for(int i=0; i<M; i++){
        if(D[i]>=0) po.push_back(D[i]);
        else ne.push_back(D[i]);
    }
    reverse(ne.begin(), ne.end());

    vector<int> dL(M+1, 1e8), dR(M+1, 1e8);
    dL[0]=dR[0]=0;
    for(int i=1; i<=ne.size(); i++) dL[i]=-(ne[i-1]);
    for(int i=1; i<=po.size(); i++) dR[i]=po[i-1];

    int ans=1e8;
    for(int k=0; k<=N; k++){
        ans=min(ans, min(dL[k]*2+dR[N-k], dL[k]+dR[N-k]*2));
    }

    cout<< ans<< endl;


    return 0;
}
0