이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int N = 1e2 + 2;
const int K = 1e3 + 3;
const long long INF = LONG_LONG_MAX / 2;
long long buy[N][K] , sel[N][K] , d[N][N] , sod[N][N] , dp[N][N] , val;
int n , m , k;
bool f(int x){
for(int u = 1 ; u <= n ; u++)
for(int v = 1 ; v <= n ; v++){
if(d[u][v] == INF)
dp[u][v] = INF;
else
dp[u][v] = d[u][v] * x - sod[u][v];
}
for(int w = 1 ; w <= n ; w++)
for(int u = 1 ; u <= n ; u++)
for(int v = 1 ; v <= n ; v++)
dp[u][v] = min(dp[u][v] , dp[u][w] + dp[w][v]);
bool ch = false;
for(int u = 1 ; u <= n ; u++)
if(dp[u][u] <= 0)
ch = true;
return ch;
}
int main(){
ios::sync_with_stdio(0), cout.tie(0), cin.tie(0);
memset(buy , -1 , sizeof(buy));
memset(sel , -1 , sizeof(sel));
val = d[0][0];
cin >> n >> m >> k;
for(int i = 1 ; i <= n ; i++)
for(int j = 1 ; j <= k ; j++)
cin >> buy[i][j] >> sel[i][j];
for(int i = 1 ; i <= n ; i++)
for(int j = 1 ; j <= n ; j++)
for(int p = 1 ; p <= k ; p++)
if(buy[i][p] != -1 && sel[j][p] != -1)
sod[i][j] = max(sod[i][j] , sel[j][p] - buy[i][p]);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
d[i][j] = INF;
for(int i = 1 ; i <= m ; i++){
int u , v;
long long w;
cin >> u >> v >> w;
d[u][v] = w;
}
for(int w = 1 ; w <= n ; w++)
for(int u = 1 ; u <= n ; u++)
for(int v = 1 ; v <= n ; v++)
d[u][v] = min(d[u][v] , d[u][w] + d[w][v]);
int low = 0 , high = 1e9;
while(high - low > 1){
int mid = (high + low) >> 1;
if(f(mid))
low = mid;
else
high = mid;
}
cout << low << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
merchant.cpp: In function 'int main()':
merchant.cpp:38:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
38 | for(int i = 1 ; i <= n ; i++)
| ^~~
merchant.cpp:43:4: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
43 | for(int i = 1; i <= n; i++)
| ^~~
# | 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... |