제출 #568538

#제출 시각아이디문제언어결과실행 시간메모리
568538jeqcho여행하는 상인 (APIO17_merchant)C++17
100 / 100
96 ms2224 KiB
#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 n,m,k; int const N=1e2+3; int const K=1e3+3; ll b[N][K], s[N][K]; ll p[N][N]; ll d[N][N]; vpi adj[N]; ll d2[N][N]; int const INF=1e9+4; bool ok(int r) { //cout<<"try "<<r<<'\n'; F0R(i,n)fill(d2[i],d2[i]+n,4e18); F0R(i,n) { F0R(j,n) { if(d[i][j]==INF)continue; d2[i][j]=r*d[i][j]-p[i][j]; } } //F0R(i,n) //{ //F0R(j,n)cout<<d2[i][j]<<' '; //cout<<'\n'; //} F0R(x,n) { F0R(i,n) { F0R(j,n)d2[i][j]=min(d2[i][j],d2[i][x]+d2[x][j]); } } //F0R(i,n) //{ //F0R(j,n)cout<<d2[i][j]<<' '; //cout<<'\n'; //} F0R(i,n)if(d2[i][i]<=0)return 1; return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m>>k; F0R(i,n) { F0R(j,k) { cin>>b[i][j]>>s[i][j]; } } F0R(i,m) { int v,w,t; cin>>v>>w>>t; --v;--w; adj[v].pb({w,t}); } F0R(i,n) { fill(p[i],p[i]+n,0); F0R(j,n) { F0R(u,k) { if(s[j][u]==-1||b[i][u]==-1)continue; p[i][j]=max(p[i][j],s[j][u]-b[i][u]); } } } F0R(i,n)fill(d[i],d[i]+n,INF); F0R(i,n)trav(e,adj[i])d[i][e.fi]=e.se; F0R(x,n) { F0R(i,n) { F0R(j,n) { d[i][j]=min(d[i][j],d[i][x]+d[x][j]); } } } int R=0; R0F(i,30) { if(ok(R+(1<<i)))R+=(1<<i); } cout<<R<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...