結果

問題 No.370 道路の掃除
ユーザー sekiya9311sekiya9311
提出日時 2016-05-14 00:52:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,379 bytes
コンパイル時間 1,589 ms
コンパイル使用メモリ 119,752 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 18:38:44
合計ジャッジ時間 2,195 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/iostream:41,
                 from main.cpp:1:
In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]',
    inlined from 'int main()' at main.cpp:92:11:
/home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/ostream:204:25: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
  204 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:44:8: note: 'ans' was declared here
   44 |     LL ans;
      |        ^~~

ソースコード

diff #

#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define RREP(i,a) for(int (i)=(a)-1;(i)>=0;(i)--)
#define FORR(i,a,b) for(int (i)=(a)-1;(i)>=(b);(i)--)
#define MOD 1e9+7
#define PI acos(-1.0)
#define DEBUG(C) cout<<C<<endl;
#define PII pair<long long,long long>

typedef long long LL;
typedef unsigned long long ULL;

using namespace std;

int v[]={1,-1};

//自分の場所,(とったゴミの数),移動距離

int main(void){
    LL ans;
    vector<vector<bool> > m(1,vector<bool>(20001,false));
    vector<int> cnt(20001,0);   //とったゴミの数
    queue<PII> q,c;
    queue<int> qq;
    int N,M; cin>>N>>M;
    vector<int> D(M,0);
    REP(i,M){
        cin>>D[i];
        m[0][D[i]+10000]=true;
    }
    int bcnt=0;
    int buf;
    if(m[0][10000]) buf=1;
    else buf=0;
    q.push(PII(0,0));   //(今の場所,移動距離)
    c.push(PII(buf,0));  //とったゴミの数,使用するboolQueueナンバー
    qq.push(0);
    while(!q.empty()){
        int me=q.front().first+10000,dis=q.front().second;
        int myC=c.front().first,myQ=c.front().second;  //今までとったゴミの数
        int be=qq.front()+10000; qq.pop();
        q.pop(); c.pop();
        if(me<0 || me>=20001) continue;
        if(myQ<0 || myQ>bcnt) continue;
        REP(i,2){
            int mme=me+v[i];
            int ddis=dis+1;
            int myCC=myC,myQQ=myQ;
            if(mme<0 || mme>=20001) continue;
            if(m[myQ][mme]){
                //m[myQ][mme]=false;
                myCC++;
                //myQQ++;
                m.push_back(m[myQ]);
                myQQ=++bcnt;
                m[myQQ][mme]=false;
                be=mme;
            }
            if(myCC==N){
                ans=ddis;
                break;
            }
            q.push(PII(mme,ddis));
            c.push(PII(myCC,myQQ));
            qq.push(be);
        }
    }
    cout<<ans<<endl;
}
0