제출 #999386

#제출 시각아이디문제언어결과실행 시간메모리
999386ByeWorld여행하는 상인 (APIO17_merchant)C++14
21 / 100
87 ms2160 KiB
#include <bits/stdc++.h> // #pragma GCC optimize("O3", "unroll-loops") #define ll long long #define int long long #define pb push_back #define fi first #define se second #define lf (id<<1) #define rg ((id<<1)|1) #define md ((l+r)>>1) #define ld long double using namespace std; typedef pair<ll,ll> pii; typedef pair<pii, int> ipii; const int MAXN = 110; const int MAXK = 1010; const int INF = 1e13+20; const int LOG = 20; const int MOD = 998244353; const int SQRT = 450; const vector<int> NOL = {}; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const vector<int> dx = {1, -1, 0, 0}; const vector<int> dy = {0, 0, 1, -1}; void chmn(int &a, int b){ a = min(a, b); } void chmx(int &a, int b){ a = max(a, b); } int n, m, k; int b[MAXN][MAXK], s[MAXN][MAXK]; int dis[MAXN][MAXN], prof[MAXN][MAXN], mat[MAXN][MAXN]; bool cek(int x){ for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ if(dis[i][j]>=INF-10 || i==j) mat[i][j] = -INF; else mat[i][j] = prof[i][j] - (x * dis[i][j]); } } for(int k=1; k<=n; k++) for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) chmx(mat[i][j], mat[i][k]+mat[k][j]); for(int i=1; i<=n; i++) if(mat[i][i] >= 0) return 1; return 0; } signed main(){ // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> m >> k; for(int i=1; i<=n; i++){ for(int j=1; j<=k; j++) cin >> b[i][j] >> s[i][j]; } for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ if(i==j) dis[i][j] = 0; else dis[i][j] = INF; } } for(int i=1; i<=m; i++){ int x, y, w; cin >> x >> y >> w; chmn(dis[x][y], w); } for(int k=1; k<=n; k++) for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) chmn(dis[i][j], dis[i][k]+dis[k][j]); for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ prof[i][j] = 0; for(int p=1; p<=k; p++){ if(b[i][p]==-1 || s[j][p]==-1) continue; chmx(prof[i][j], -b[i][p]+s[j][p]); } } } int l=0, r=INF, mid=0, cnt=0; while(l<=r){ mid = md; if(cek(mid)){ cnt = mid; l = mid+1; } else r = mid-1; } cout << cnt << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...