Submission #38203516


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ld = long double;
using pll = pair<ll, ll>;
// and so on
int arr[301];
char mp[301][301];
pll dist[301][301];
const ll INF = 1LL<<60;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int N; cin>>N;
    for(int i=0;i<N;i++){
        cin>>arr[i];
    }
    for(int i=0;i<N;i++) cin>>mp[i];
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(mp[i][j] == 'N') dist[i][j] = {INF, 0};
            else dist[i][j] = {1, arr[i] + arr[j]};
        } 
        dist[i][i] = {0, arr[i]};
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            for(int k=0;k<N;k++){
                pll np = {dist[j][i].first + dist[i][k].first, dist[j][i].second + dist[i][k].second - arr[i]};
                if(np.first < dist[j][k].first){
                    dist[j][k] = np;
                }
                else if(np.first == dist[j][k].first) dist[j][k].second = max(np.second, dist[j][k].second);
            }
        }
    }
    int Q;
    cin>>Q;
    while(Q--){
        int s, t;
        cin>>s>>t;
        s--;
        t--;
        auto [a, b] = dist[s][t];
        if(a == INF) cout<<"Impossible\n";
        else cout<<a<<' '<<b<<'\n';
    }
}

Submission Info

Submission Time
Task E - Souvenir
User jame0313
Language C++ (GCC 9.2.1)
Score 500
Code Size 1337 Byte
Status AC
Exec Time 97 ms
Memory 5092 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 46
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt
Case Name Status Exec Time Memory
example_00.txt AC 9 ms 3456 KiB
example_01.txt AC 2 ms 3544 KiB
hand_00.txt AC 67 ms 4944 KiB
hand_01.txt AC 65 ms 5060 KiB
hand_02.txt AC 57 ms 5036 KiB
hand_03.txt AC 65 ms 5092 KiB
hand_04.txt AC 4 ms 3396 KiB
random_00.txt AC 64 ms 4980 KiB
random_01.txt AC 62 ms 5028 KiB
random_02.txt AC 61 ms 4996 KiB
random_03.txt AC 62 ms 5072 KiB
random_04.txt AC 57 ms 4932 KiB
random_05.txt AC 66 ms 4880 KiB
random_06.txt AC 63 ms 4932 KiB
random_07.txt AC 63 ms 4956 KiB
random_08.txt AC 53 ms 4956 KiB
random_09.txt AC 56 ms 4988 KiB
random_10.txt AC 56 ms 4852 KiB
random_11.txt AC 59 ms 4956 KiB
random_12.txt AC 55 ms 4988 KiB
random_13.txt AC 54 ms 5052 KiB
random_14.txt AC 66 ms 5004 KiB
random_15.txt AC 77 ms 5008 KiB
random_16.txt AC 55 ms 5016 KiB
random_17.txt AC 54 ms 4996 KiB
random_18.txt AC 76 ms 4996 KiB
random_19.txt AC 77 ms 4956 KiB
random_20.txt AC 77 ms 4960 KiB
random_21.txt AC 63 ms 4960 KiB
random_22.txt AC 78 ms 5056 KiB
random_23.txt AC 62 ms 4944 KiB
random_24.txt AC 63 ms 5036 KiB
random_25.txt AC 64 ms 4956 KiB
random_26.txt AC 66 ms 4996 KiB
random_27.txt AC 66 ms 4964 KiB
random_28.txt AC 61 ms 5084 KiB
random_29.txt AC 65 ms 4968 KiB
random_30.txt AC 65 ms 5012 KiB
random_31.txt AC 54 ms 4960 KiB
random_32.txt AC 56 ms 5004 KiB
random_33.txt AC 53 ms 4920 KiB
random_34.txt AC 60 ms 4848 KiB
random_35.txt AC 69 ms 4992 KiB
random_36.txt AC 71 ms 4880 KiB
random_37.txt AC 97 ms 4964 KiB
random_38.txt AC 97 ms 5040 KiB