/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 784.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 1ms 548.0 KiB
#5 Accepted 1ms 764.0 KiB
#6 Accepted 2ms 532.0 KiB
#7 Accepted 4ms 324.0 KiB
#8 Accepted 4ms 532.0 KiB
#9 Accepted 4ms 532.0 KiB
#10 Accepted 4ms 532.0 KiB
#11 Accepted 4ms 532.0 KiB
#12 Accepted 4ms 532.0 KiB
#13 Accepted 4ms 532.0 KiB
#14 Accepted 2ms 324.0 KiB
#15 Accepted 1ms 532.0 KiB
#16 Accepted 1ms 532.0 KiB
#17 Accepted 1ms 532.0 KiB
#18 Accepted 1ms 388.0 KiB
#19 Accepted 1ms 324.0 KiB
#20 Accepted 1ms 320.0 KiB
#21 Accepted 1ms 520.0 KiB
#22 Accepted 1ms 364.0 KiB
#23 Accepted 1ms 532.0 KiB
#24 Accepted 1ms 532.0 KiB
#25 Accepted 1ms 532.0 KiB
#26 Accepted 1ms 532.0 KiB
#27 Accepted 1ms 328.0 KiB
#28 Accepted 1ms 532.0 KiB
#29 Accepted 1ms 340.0 KiB
#30 Accepted 1ms 532.0 KiB
#31 Accepted 1ms 532.0 KiB
#32 Accepted 1ms 532.0 KiB
#33 Accepted 1ms 760.0 KiB
#34 Accepted 1ms 344.0 KiB
#35 Accepted 1ms 532.0 KiB
#36 Accepted 1ms 532.0 KiB
#37 Accepted 1ms 480.0 KiB
#38 Accepted 1ms 764.0 KiB
#39 Accepted 1ms 484.0 KiB
#40 Accepted 1ms 532.0 KiB
#41 Accepted 1ms 532.0 KiB
#42 Accepted 4ms 532.0 KiB
#43 Accepted 4ms 532.0 KiB
#44 Accepted 4ms 532.0 KiB
#45 Accepted 2ms 524.0 KiB
#46 Accepted 2ms 532.0 KiB
#47 Accepted 2ms 532.0 KiB
#48 Accepted 2ms 444.0 KiB
#49 Accepted 2ms 516.0 KiB
#50 Accepted 2ms 468.0 KiB
#51 Accepted 2ms 532.0 KiB
#52 Accepted 2ms 532.0 KiB
#53 Accepted 2ms 528.0 KiB
#54 Accepted 2ms 532.0 KiB
#55 Accepted 2ms 532.0 KiB
#56 Accepted 2ms 532.0 KiB
#57 Accepted 1ms 532.0 KiB
#58 Accepted 1ms 532.0 KiB
#59 Accepted 1ms 484.0 KiB
#60 Accepted 1ms 532.0 KiB
#61 Accepted 1ms 440.0 KiB
#62 Accepted 1ms 532.0 KiB
#63 Accepted 1ms 324.0 KiB
#64 Wrong Answer 1ms 532.0 KiB
#65 Accepted 1ms 320.0 KiB
#66 Accepted 1ms 536.0 KiB
#67 Accepted 1ms 532.0 KiB
#68 Accepted 1ms 324.0 KiB
#69 Accepted 1ms 532.0 KiB
#70 Accepted 1ms 508.0 KiB
#71 Accepted 1ms 532.0 KiB
#72 Accepted 1ms 536.0 KiB
#73 Accepted 1ms 436.0 KiB
#74 Accepted 1ms 536.0 KiB
#75 Accepted 1ms 532.0 KiB
#76 Accepted 1ms 532.0 KiB
#77 Accepted 1ms 488.0 KiB
#78 Accepted 1ms 532.0 KiB
#79 Accepted 1ms 532.0 KiB
#80 Accepted 1ms 764.0 KiB
#81 Accepted 1ms 320.0 KiB
#82 Wrong Answer 1ms 320.0 KiB

Code

/*
 *   Copyright (c) 2024 Emon Thakur
 *   All rights reserved.
 */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int t; cin >> t; while(t--)
    {
        ll n,m,x,y; cin >> n >> m >> x >> y;
        char a[n+1][m+1];
        vector<vector<pair<ll,ll>>> dp(n+2,vector<pair<ll,ll>>(m+2,{1e18,1e18}));
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++) cin >> a[i][j];
        }
        dp[1][1] = {0,0};
        for(int j=2;j<=m;j++) 
        {
            if(a[1][j]=='#') break;
            dp[1][j] = {dp[1][j-1].first + x , dp[1][j-1].first+y};
        }
        for(ll i=2;i<=n;i++)
        {
            for(ll j=1;j<=m;j++)
            {
                if(a[i][j]=='#') continue;
                dp[i][j].first = min(dp[i][j-1].first+x , dp[i-1][j].second+y);
                dp[i][j].second = min(dp[i][j-1].first+y , dp[i-1][j].second+x);
            }
            for(ll j=m;j>=1;j--)
            {
                if(a[i][j]=='#') continue;
                dp[i][j].first = min({dp[i][j].first , dp[i][j+1].first+x, dp[i-1][j].second+y});
                dp[i][j].second = min({dp[i][j].second , dp[i][j+1].first+y , dp[i-1][j].second+x});
            }
        }
        ll ans = min(dp[n][m-1].first , dp[n-1][m].second);
        (ans==1e18)? cout<<-1<<endl: cout<<ans<<endl;
    }
}

Information

Submit By
Type
Submission
Problem
P1156 Low cost water management
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-30 07:22:05
Judged At
2024-12-30 07:22:05
Judged By
Score
80
Total Time
4ms
Peak Memory
784.0 KiB