이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define pb push_back
using namespace std;
int n, m, k, q;
map<pair<pii, pii>, int> dp;
int resi(int a, int b, int x, int y)
{
if (dp[{{a, b}, {x, y}}]) return dp[{{a, b}, {x, y}}];
if ((a+1)==b) return 1000000010;
int mid=a+(b-a)/2;
int ress=1000000010;
for (int i=0; i<k; i++)
{
ress=min(ress, resi(a, mid, x, i)+resi(mid, b, i, y));
}
dp[{{a, b}, {x, y}}]=ress;
return ress;
}
int main(){
cin>>k>>n>>m>>q;
for (int i=0; i<m; i++)
{
int u, v, t; cin>>u>>v>>t;
dp[{{u/k, v/k}, {u%k, v%k}}]=t;
}
while (q--)
{
int u, v; cin>>u>>v;
int ress=resi(u/k, v/k, u%k, v%k);
if (ress>=1000000010) cout<<-1<<endl;
else cout<<ress<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |