/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 4ms 532.0 KiB
#3 Accepted 4ms 532.0 KiB
#4 Accepted 4ms 532.0 KiB
#5 Accepted 4ms 532.0 KiB
#6 Accepted 4ms 320.0 KiB
#7 Accepted 4ms 532.0 KiB
#8 Accepted 4ms 532.0 KiB
#9 Accepted 4ms 532.0 KiB
#10 Accepted 5ms 532.0 KiB
#11 Accepted 4ms 532.0 KiB
#12 Accepted 4ms 532.0 KiB
#13 Accepted 4ms 532.0 KiB
#14 Accepted 4ms 532.0 KiB
#15 Accepted 4ms 532.0 KiB
#16 Accepted 4ms 532.0 KiB
#17 Accepted 4ms 532.0 KiB
#18 Accepted 4ms 532.0 KiB
#19 Accepted 4ms 532.0 KiB
#20 Accepted 4ms 532.0 KiB
#21 Accepted 4ms 532.0 KiB
#22 Accepted 4ms 484.0 KiB
#23 Accepted 4ms 532.0 KiB
#24 Accepted 4ms 532.0 KiB
#25 Accepted 4ms 532.0 KiB
#26 Accepted 4ms 532.0 KiB
#27 Accepted 4ms 532.0 KiB
#28 Accepted 4ms 532.0 KiB
#29 Accepted 4ms 532.0 KiB
#30 Accepted 4ms 488.0 KiB
#31 Accepted 4ms 532.0 KiB
#32 Accepted 4ms 532.0 KiB
#33 Accepted 4ms 532.0 KiB
#34 Accepted 4ms 532.0 KiB
#35 Accepted 4ms 532.0 KiB
#36 Accepted 4ms 532.0 KiB
#37 Accepted 4ms 532.0 KiB
#38 Accepted 4ms 532.0 KiB
#39 Accepted 4ms 532.0 KiB
#40 Accepted 4ms 532.0 KiB
#41 Accepted 5ms 532.0 KiB
#42 Accepted 4ms 324.0 KiB
#43 Accepted 4ms 532.0 KiB
#44 Accepted 5ms 576.0 KiB
#45 Accepted 4ms 532.0 KiB
#46 Accepted 4ms 532.0 KiB
#47 Accepted 4ms 532.0 KiB
#48 Accepted 4ms 532.0 KiB
#49 Accepted 4ms 440.0 KiB
#50 Accepted 4ms 444.0 KiB
#51 Accepted 4ms 580.0 KiB
#52 Accepted 4ms 532.0 KiB
#53 Accepted 4ms 532.0 KiB
#54 Accepted 4ms 532.0 KiB
#55 Accepted 4ms 532.0 KiB
#56 Accepted 4ms 532.0 KiB
#57 Accepted 5ms 488.0 KiB
#58 Accepted 4ms 344.0 KiB
#59 Accepted 4ms 532.0 KiB
#60 Accepted 4ms 532.0 KiB
#61 Accepted 4ms 532.0 KiB
#62 Accepted 4ms 532.0 KiB
#63 Accepted 5ms 532.0 KiB
#64 Accepted 4ms 324.0 KiB
#65 Accepted 4ms 532.0 KiB
#66 Accepted 4ms 488.0 KiB
#67 Accepted 4ms 532.0 KiB
#68 Accepted 4ms 532.0 KiB
#69 Accepted 5ms 480.0 KiB
#70 Accepted 4ms 532.0 KiB
#71 Accepted 4ms 532.0 KiB
#72 Accepted 4ms 532.0 KiB
#73 Accepted 4ms 532.0 KiB
#74 Accepted 4ms 532.0 KiB
#75 Accepted 4ms 532.0 KiB
#76 Accepted 4ms 532.0 KiB
#77 Accepted 4ms 532.0 KiB
#78 Accepted 4ms 576.0 KiB
#79 Accepted 4ms 532.0 KiB
#80 Accepted 4ms 532.0 KiB
#81 Accepted 4ms 532.0 KiB
#82 Accepted 4ms 532.0 KiB
#83 Accepted 4ms 532.0 KiB
#84 Accepted 4ms 532.0 KiB
#85 Accepted 4ms 532.0 KiB
#86 Accepted 4ms 472.0 KiB
#87 Accepted 4ms 532.0 KiB
#88 Accepted 4ms 532.0 KiB
#89 Accepted 4ms 324.0 KiB
#90 Accepted 4ms 532.0 KiB
#91 Accepted 4ms 532.0 KiB
#92 Accepted 5ms 504.0 KiB
#93 Accepted 4ms 532.0 KiB
#94 Accepted 4ms 532.0 KiB
#95 Accepted 4ms 532.0 KiB
#96 Accepted 4ms 536.0 KiB
#97 Accepted 4ms 532.0 KiB
#98 Accepted 4ms 532.0 KiB
#99 Accepted 4ms 532.0 KiB
#100 Accepted 4ms 532.0 KiB

Code

/*
 *   Copyright (c) 2024 Emon Thakur
 *   All rights reserved.
 */
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
char a[2002][2002];
ll n,m,x,y,ans=1e18;

void find(int i,int j,int dir,ll cost)
{
    if(i>n || i<1 || j>m || j<1) return;
    if(i==n && j==m)
    {
        ans = min(ans,cost);
        return;
    }
    if(a[i][j]=='#') return;
    if(dir==0)
    {
        find(i,j+1,0,cost+x);
        find(i+1,j,2,cost+y);
    }
    else if(dir==1)
    {
        find(i,j-1,1,cost+x);
        find(i+1,j,2,cost+y);
    }
    else
    {
        find(i+1,j,2,cost+x);
        find(i,j+1,0,cost+y);
        find(i,j-1,1,cost+y);
    }
}

void solve()
{
    cin >> n >> m >> x >> y;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++) cin >> a[i][j];
    }
    find(1,2,0,0);
    find(2,1,2,0);
    if(ans >= 1e18) cout<<-1<<endl;
    else cout<<ans<<endl;
    ans = 1e18;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int t; cin >> t; while(t--)  solve(),ans =1e18;
}

Information

Submit By
Type
Submission
Problem
P1156 Low cost water management
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-30 09:45:10
Judged At
2024-12-30 09:45:10
Judged By
Score
100
Total Time
5ms
Peak Memory
580.0 KiB