이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// __builtin_popcount(x)
// __builtin_popcountll(x)
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;
#define maxn 105
#define maxk 10005
ll n,m,k;
ll a[maxn][maxk];
ll b[maxn][maxk];
ll p[maxn][maxk];
ll d[maxn][maxn];
ll c[maxn][maxn];
bool moe(ll x){
for(ll i = 1;i<=n;i++) for(ll j = 1;j<=n;j++) c[i][j] = x*min(llinf/x,d[i][j]) - p[i][j];
for(ll f = 1;f<=n;f++) for(ll i = 1;i<=n;i++) for(ll j = 1;j<=n;j++) c[i][j] = min(c[i][j],c[i][f]+c[f][j]);
for(ll i = 1;i<=n;i++) if(c[i][i]<=0) return 1;
return 0;
}
ll bs(){
ll l = 1,r = 1000000000,mid,rez;
while(l<=r){
mid = (l+r)/2;
if(moe(mid)){
l = mid + 1;
rez = mid;
}else r = mid - 1;
}
return rez;
}
int main(){
ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
cin >> n >> m >> k;
for(ll i = 1;i<=n;i++) for(ll j = 1;j<=n;j++) d[i][j] = llinf;
//for(ll i = 1;i<=n;i++) d[i][i] = 0;
for(ll i = 1;i<=n;i++) for(ll j = 1;j<=k;j++) cin >> a[i][j] >> b[i][j];
for(ll f = 1;f<=k;f++) for(ll i = 1;i<=n;i++) for(ll j = 1;j<=n;j++) if(a[i][f]!=-1&&b[j][f]!=-1) p[i][j] = max(p[i][j],b[j][f]-a[i][f]);
for(ll i = 1;i<=m;i++){
ll x,y; cin >> x >> y;
cin >> d[x][y];
}
for(ll f = 1;f<=n;f++){
for(ll i = 1;i<=n;i++){
for(ll j = 1;j<=n;j++){
d[i][j] = min(d[i][j],d[i][f] + d[f][j]);
}
}
}
cout<<bs()<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
merchant.cpp: In function 'long long int bs()':
merchant.cpp:45:12: warning: 'rez' may be used uninitialized in this function [-Wmaybe-uninitialized]
45 | return rez;
| ^~~
# | 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... |