提出 #68891134


ソースコード 拡げる

#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define vin vector<int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pll>
#define br cout<<endl
#define no cout<<"NO"<<endl
#define yes cout<<"YES"<<endl
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pr(v) for(auto it:v) cout<<it<<" ";cout<<endl;
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define debug(x) cout<< #x<<'='<<x<<endl;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const ll mod=1e9+7;

//eJya
//evu
//lyinf
//iwnlyg
//it's easy; 
//just think;
// for factors use sieve
struct state
{
    ll d,r,c,swap;
};
bool poss(ll r,ll c,ll n, ll m,vector<string>&v,ll swap){
    if(r>=0 && r<n && c>=0 && c<m){
        if((v[r][c]=='.') or (v[r][c]=='?') or((v[r][c]=='G'))) return true;
        else if(v[r][c]=='#') return false;
        else if((v[r][c]=='o') && (swap%2==0)) return true;
        else if((v[r][c]=='x')&& (swap%2==1)) return true;
        else return false;
    }
    return false;
}
void solve()
{
    ll n,m;cin>>n>>m;
    // string s;cin>>s;
    vector<string>v(n);
    rep(i,0,n) cin>>v[i];
    vector<vector<vll>>dis(n,vector<vll>(m,vll(2,1e18)));
    // cout<<"################################################ ";
    pll st,ee;
    rep(i,0,n){
        rep(j,0,m){
            if(v[i][j]=='S') { st={i,j};dis[i][j][0]=0;dis[i][j][1]=0;}
            if(v[i][j]=='G') ee={i,j};
        }
    } 


    queue<state>q;
    q.push({0,st.F,st.S,0});
    ll dr[]={1,0,-1,0};
    ll dc[]={0,-1,0,1};
    while(!q.empty()){
        auto it=q.front();q.pop();
        ll d=it.d,r=it.r,c=it.c,sw=it.swap;
        if(v[r][c]=='G') continue;
        rep(i,0,4){
            ll nr=r+dr[i],nc=c+dc[i];
            if(!poss(nr,nc,n,m,v,sw)) continue;
            ll nsw=sw;if(v[nr][nc]=='?') nsw=!nsw;
            if(dis[nr][nc][nsw]>(d+1)){
                dis[nr][nc][nsw]=d+1;
                q.push({d+1,nr,nc,nsw});
                // else cout<<d+1<<endl;
            }
        }
    }
    // for(auto it:dis){
    //     for(auto i:it) cout<<i[0]<<" , "<<"   ";cout<<endl;
    // }

    ll mini=min(dis[ee.F][ee.S][0],dis[ee.F][ee.S][1]);
    if(mini>=1e18) cout<<-1;
    else cout<<mini;
    cout<<endl;
    
}
 
int main()
{
    IOS;
    ll eJya;
    // cin>>eJya; while(eJya--) 
    solve();    
}

提出情報

提出日時
問題 D - Toggle Maze
ユーザ epsa__
言語 C++ 20 (gcc 12.2)
得点 0
コード長 2492 Byte
結果 WA
実行時間 50 ms
メモリ 17632 KiB

コンパイルエラー

Main.cpp: In function ‘int main()’:
Main.cpp:93:8: warning: unused variable ‘eJya’ [-Wunused-variable]
   93 |     ll eJya;
      |        ^~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 400
結果
AC × 3
AC × 66
WA × 1
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 01_handmade_10.txt, 01_handmade_11.txt, 01_handmade_12.txt, 01_handmade_13.txt, 01_handmade_14.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt, 02_random_25.txt, 02_random_26.txt, 02_random_27.txt, 02_random_28.txt, 02_random_29.txt, 02_random_30.txt, 02_random_31.txt, 02_random_32.txt, 02_random_33.txt, 02_random_34.txt, 02_random_35.txt, 02_random_36.txt, 02_random_37.txt, 02_random_38.txt, 02_random_39.txt, 02_random_40.txt, 02_random_41.txt, 02_random_42.txt, 02_random_43.txt, 02_random_44.txt, 02_random_45.txt, 02_random_46.txt, 02_random_47.txt, 02_random_48.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3484 KiB
00_sample_01.txt AC 1 ms 3368 KiB
00_sample_02.txt AC 1 ms 3348 KiB
01_handmade_00.txt AC 31 ms 17476 KiB
01_handmade_01.txt AC 30 ms 17428 KiB
01_handmade_02.txt AC 31 ms 17400 KiB
01_handmade_03.txt AC 29 ms 17400 KiB
01_handmade_04.txt AC 1 ms 3404 KiB
01_handmade_05.txt AC 1 ms 3412 KiB
01_handmade_06.txt AC 1 ms 3512 KiB
01_handmade_07.txt AC 1 ms 3448 KiB
01_handmade_08.txt AC 1 ms 3400 KiB
01_handmade_09.txt AC 17 ms 17280 KiB
01_handmade_10.txt AC 16 ms 17420 KiB
01_handmade_11.txt AC 22 ms 17432 KiB
01_handmade_12.txt AC 21 ms 17432 KiB
01_handmade_13.txt AC 21 ms 17508 KiB
01_handmade_14.txt AC 21 ms 17508 KiB
02_random_00.txt AC 1 ms 3636 KiB
02_random_01.txt AC 25 ms 13852 KiB
02_random_02.txt AC 2 ms 4056 KiB
02_random_03.txt AC 29 ms 15512 KiB
02_random_04.txt AC 2 ms 5088 KiB
02_random_05.txt WA 36 ms 17584 KiB
02_random_06.txt AC 28 ms 15232 KiB
02_random_07.txt AC 33 ms 17520 KiB
02_random_08.txt AC 4 ms 7012 KiB
02_random_09.txt AC 36 ms 17424 KiB
02_random_10.txt AC 12 ms 17632 KiB
02_random_11.txt AC 33 ms 17448 KiB
02_random_12.txt AC 11 ms 17480 KiB
02_random_13.txt AC 8 ms 6512 KiB
02_random_14.txt AC 28 ms 14724 KiB
02_random_15.txt AC 2 ms 3840 KiB
02_random_16.txt AC 36 ms 17612 KiB
02_random_17.txt AC 2 ms 4084 KiB
02_random_18.txt AC 35 ms 17488 KiB
02_random_19.txt AC 3 ms 4368 KiB
02_random_20.txt AC 36 ms 17412 KiB
02_random_21.txt AC 1 ms 3592 KiB
02_random_22.txt AC 36 ms 17384 KiB
02_random_23.txt AC 2 ms 3876 KiB
02_random_24.txt AC 13 ms 12936 KiB
02_random_25.txt AC 5 ms 8328 KiB
02_random_26.txt AC 10 ms 8848 KiB
02_random_27.txt AC 4 ms 5852 KiB
02_random_28.txt AC 22 ms 17416 KiB
02_random_29.txt AC 8 ms 7372 KiB
02_random_30.txt AC 29 ms 17380 KiB
02_random_31.txt AC 10 ms 14664 KiB
02_random_32.txt AC 16 ms 17384 KiB
02_random_33.txt AC 11 ms 10080 KiB
02_random_34.txt AC 22 ms 17440 KiB
02_random_35.txt AC 7 ms 5616 KiB
02_random_36.txt AC 27 ms 11460 KiB
02_random_37.txt AC 18 ms 8568 KiB
02_random_38.txt AC 50 ms 17540 KiB
02_random_39.txt AC 40 ms 15228 KiB
02_random_40.txt AC 47 ms 17428 KiB
02_random_41.txt AC 1 ms 3620 KiB
02_random_42.txt AC 1 ms 3740 KiB
02_random_43.txt AC 1 ms 3608 KiB
02_random_44.txt AC 1 ms 3680 KiB
02_random_45.txt AC 1 ms 3540 KiB
02_random_46.txt AC 1 ms 3540 KiB
02_random_47.txt AC 1 ms 3540 KiB
02_random_48.txt AC 1 ms 3628 KiB