Submission #1150525


Source Code Expand

#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int mx[]={1,-1,0,0};
int my[]={0,0,1,-1};
int main(){
    queue<pii>que; pii s,c,g,now;
    int h,w; cin>>h>>w;
    vector<vector<char>>v(h,vector<char>(w));
    rep(i,h)rep(j,w){
        cin>>v[i][j];
        if(v[i][j]=='S')s=pii(i,j);
        if(v[i][j]=='C')c=pii(i,j);
        if(v[i][j]=='G')g=pii(i,j);
        }
    vvi d1(h,vi(w,INF)),d2(h,vi(w,INF));
    d1[s.first][s.second]=0;
    que.push(s);
    bool flag=false;
    while(!que.empty()){
        now=que.front(); que.pop();
        if(now==c){break;flag=true;}
        rep(i,4){
            pii temp=pii(now.first+my[i],now.second+mx[i]);
            if(d1[temp.first][temp.second]==INF&&v[temp.first][temp.second]!='#'){
                que.push(temp);d1[temp.first][temp.second]=d1[now.first][now.second]+1;}
        }
    }
    ll ans=(ll)d1[c.first][c.second];
    while(!que.empty())que.pop();
    que.push(c);
    d2[c.first][c.second]=0;
    while(!que.empty()){
        now=que.front(); que.pop();
        if(now==g){break;flag=true;}
        rep(i,4){
            pii temp=pii(now.first+mx[i],now.second+my[i]);
            if(d2[temp.first][temp.second]==INF&&v[temp.first][temp.second]!='#'){
                que.push(temp);d2[temp.first][temp.second]=d2[now.first][now.second]+1;}
        }
    }
    if(!flag)return puts("-1")*0;
    cout<<ans+d2[g.first][g.second]<<endl;
}

Submission Info

Submission Time
Task C - 自宅からの脱出
User yebityon
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2138 Byte
Status WA
Exec Time 30 ms
Memory 2560 KB

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
AC × 6
WA × 18
Set Name Test Cases
All input_0.txt, input_1.txt, input_10.txt, input_11.txt, input_12.txt, input_13.txt, input_14.txt, input_15.txt, input_16.txt, input_17.txt, input_18.txt, input_19.txt, input_2.txt, input_20.txt, input_21.txt, input_22.txt, input_23.txt, input_3.txt, input_4.txt, input_5.txt, input_6.txt, input_7.txt, input_8.txt, input_9.txt
Case Name Status Exec Time Memory
input_0.txt WA 1 ms 256 KB
input_1.txt WA 1 ms 256 KB
input_10.txt AC 1 ms 256 KB
input_11.txt WA 1 ms 256 KB
input_12.txt WA 1 ms 256 KB
input_13.txt WA 2 ms 384 KB
input_14.txt WA 20 ms 2560 KB
input_15.txt WA 30 ms 2432 KB
input_16.txt AC 13 ms 2048 KB
input_17.txt WA 28 ms 2560 KB
input_18.txt WA 2 ms 384 KB
input_19.txt WA 2 ms 384 KB
input_2.txt AC 1 ms 256 KB
input_20.txt WA 2 ms 384 KB
input_21.txt WA 22 ms 2560 KB
input_22.txt AC 16 ms 2560 KB
input_23.txt WA 16 ms 2560 KB
input_3.txt AC 1 ms 256 KB
input_4.txt WA 1 ms 256 KB
input_5.txt WA 1 ms 256 KB
input_6.txt WA 1 ms 256 KB
input_7.txt AC 1 ms 256 KB
input_8.txt WA 1 ms 256 KB
input_9.txt WA 1 ms 256 KB