/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 584.0 KiB
#2 Accepted 1ms 556.0 KiB
#3 Accepted 1ms 768.0 KiB
#4 Accepted 2ms 488.0 KiB
#5 Accepted 1ms 328.0 KiB
#6 Accepted 2ms 516.0 KiB
#7 Accepted 1ms 544.0 KiB
#8 Accepted 1ms 540.0 KiB
#9 Accepted 2ms 332.0 KiB
#10 Accepted 1ms 556.0 KiB
#11 Wrong Answer 1ms 588.0 KiB
#12 Accepted 1ms 648.0 KiB
#13 Accepted 1ms 540.0 KiB
#14 Accepted 1ms 540.0 KiB
#15 Accepted 2ms 540.0 KiB
#16 Accepted 2ms 332.0 KiB
#17 Accepted 2ms 332.0 KiB
#18 Accepted 1ms 584.0 KiB
#19 Accepted 1ms 332.0 KiB
#20 Wrong Answer 2ms 452.0 KiB

Code

/*
 *   Copyright (c) 2024 Emon Thakur
 *   All rights reserved.
 */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr freopen("input52.txt","r",stdin);
//ofstream file("output52.txt");
char a[2001][2001];
int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //fr;
    int t;  cin >> t; while(t--)
    {
        ll n,m,x,y; cin >> n >> m >> x >> y;
        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<<'\n': cout<<ans<<'\n';
    }
}

Information

Submit By
Type
Submission
Problem
P1156 Low cost water management
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-30 10:10:29
Judged At
2024-12-30 10:10:29
Judged By
Score
18
Total Time
2ms
Peak Memory
768.0 KiB