이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define fi first
#define se second
int const N=50+3;
int const K=50+3;
ll b[N][K],s[N][K];
vpi adj[N];
int n,m,k;
ll dp[N][N][N];
int d[N][N];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>m>>k;
assert(n!=1);
F0R(i,n)
{
F0R(j,k)
{
cin>>b[i][j]>>s[i][j];
}
}
F0R(i,m)
{
int a,u,t;
cin>>a>>u>>t;
--a;--u;
adj[a].pb({u,t});
}
F0R(i,n)fill(d[i],d[i]+n,1e9);
F0R(i,n)
{
trav(e,adj[i])d[i][e.fi]=1;
}
F0R(x,n)
{
F0R(i,n)
{
F0R(j,n)
{
d[i][j]=min(d[i][j],d[i][x]+d[x][j]);
}
}
}
F0R(i,n)F0R(j,n)fill(dp[i][j],dp[i][j]+n+1,-1);
F0R(i,n)
{
F0R(j,n)
{
if(d[i][j]==1e9)continue;
dp[i][j][d[i][j]]=0;
F0R(p,k)
{
if(b[i][p]==-1||s[j][p]==-1)continue;
dp[i][j][d[i][j]]=max(dp[i][j][d[i][j]],s[j][p]-b[i][p]);
}
}
}
FOR(p,2,n+1)
{
FOR(p2,1,p)
{
F0R(x,n)
{
F0R(i,n)
{
if(dp[i][x][p2]==-1)continue;
F0R(j,n)
{
if(dp[x][j][p-p2]==-1)continue;
dp[i][j][p]=max(dp[i][j][p],dp[i][x][p2]+dp[x][j][p-p2]);
}
}
}
}
}
ll ans=0;
F0R(i,n)
{
FOR(p,1,n+1)
{
ll cand=dp[i][i][p]/(ll)p;
//if(cand>ans)
//{
//cout<<i<<' '<<p<<' '<<dp[i][i][p]<<'\n';
//}
ans=max(ans,cand);
}
}
cout<<ans<<'\n';
return 0;
}
# | 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... |