이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define vi vector<int>
#define vpii vector<pii>
#define vp3i vector<p3i>
#define vpll vector<pll>
#define vp3l vector<p3l>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() ((rand() << 14)+rand())
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846
#define startrng mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m, k, a, c, w;
int s[105][1005], b[105][1005], best[105][105];
ll path[105][105], dp[105][105][105], path2[105][105];
bool check(int M){
//cout << endl << ' ' << M << ' ' << endl;
fox1(l, n){
fox1(l2, n){
path2[l][l2] = best[l][l2] - (path[l][l2]>(1LL<<50)/M?(1LL<<50):path[l][l2]*M);
//cout << path2[l][l2] << ' ';
//if (M<200 && path2[l][l2] > 0) cout << path2[l][l2] << ' ' << l << ' ' << l2 <<endl;
}
//if (M<200) cout << endl;
//cout << endl;
}
//fox1(T, 10)
fox1(l3, n){
fox1(l, n){
fox1(l2, n){
if (path2[l][l3] < -(1LL<<50)-path2[l3][l2]) continue;
path2[l][l2] = max(path2[l][l2], path2[l][l3] + path2[l3][l2]);
}
}
}
fox1(l, n){
//if (M < 200) cout << path2[l][l] << ' ';
if (path2[l][l] >= 0) return 1;
}
//cout << endl;
return 0;
}
int32_t main(){
//freopen("test.txt", "r", stdin);
flood(path);
scanf("%i%i%i", &n, &m, &k);
fox1(l, n){
fox(l2, k){
scanf("%i%i", &b[l][l2], &s[l][l2]);
//if (b[l][l2] == -1) b[l][l2] = (1<<30);
}
/*fox(l2, k){
scanf("%i", &s[l][l2]);
//if (s[l][l2] == -1) s[l][l2] = -(1<<30);
}*/
}
fox1(l, n){
fox1(l2, n){
best[l][l2] = 0;
fox(l3, k){
if (s[l2][l3]!=-1 && b[l][l3]!=-1)
best[l][l2] = max(best[l][l2], s[l2][l3]-b[l][l3]);
}
}
}
fox(l, m){
scanf("%i%i%i", &a, &c, &w);
path[a][c] = w;
}
ll ans = 0;
fox1(T, n)
fox1(l3, n){
fox1(l, n){
fox1(l2, n){
path[l][l2] = min(path[l][l2], path[l][l3] + path[l3][l2]);
}
}
}
/*fox1(l, n){
ans = max(ans, best[1][l]/(path[1][l]+path[l][1]));
cout << best[1][l] << ' ' << path[1][l] << ' ' << path[l][1] << endl;
}
cout << ans; return 0;*/
//}
/*fox1(l, n){
fox1(l2, n){
cout << path[l][l2] << ' ';
}cout << endl;
}*/
int lo = 0, mid, hi = 1000000000;
while(lo<hi){
//cout << lo << ' ' << hi << endl;
mid=(lo+hi+1)/2;
if (check(mid)) lo=mid;
else hi=mid-1;
}
cout << lo << endl;
return 0;
}
/*
4 5 2
10 9 5 2
6 4 20 15
9 7 10 9
-1 -1 16 11
1 2 3
2 3 3
1 4 1
4 3 1
3 1 1
4 4 1
1 1
-1 -1
-1 -1
1000000000 1000000000
1 2 1000000000
2 3 1000000000
3 4 1000000000
4 1 1000000000
4 4 1
-1 -1
-1 10
-1 20000
-1 1000000000
1 2 1
2 3 1
3 4 1
4 1 1
*/
컴파일 시 표준 에러 (stderr) 메시지
merchant.cpp: In function 'int32_t main()':
merchant.cpp:93:6: warning: unused variable 'ans' [-Wunused-variable]
ll ans = 0;
^~~
merchant.cpp:69:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i%i", &n, &m, &k);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:72:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i", &b[l][l2], &s[l][l2]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:90:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i%i", &a, &c, &w);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |