이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize(Ofast)
#pragma GCC optimization (unroll-loops)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int maxn = int(1e2) + 11;
const int maxk = int(1e3) + 11;
const ll inf = 0x3f3f3f3f * ((1ll<<32)+1);
int n, m, knd;
int buy[maxn][maxk], sell[maxn][maxk];
ll de[maxn][maxn];
int mxsell[maxn][maxn];
#define Floyd(d) { \
for (int j=1; j<=n; ++j) { \
for (int i=1; i<=n; ++i) for (int k=1; k<=n; ++k) \
d[i][k] = min(d[i][k], d[i][j] + d[j][k]); \
} \
}
inline int rd(){
int x=0,w=1;
char ch=getchar();
for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') w=-1;
for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1) +(x<<3) +ch-'0';
return x*w;
}
int main() {
cin.tie(0)->sync_with_stdio(0); cout.tie(0);
n=rd(),m=rd(),knd=rd();
for (int i=1; i<=n; ++i) for (int j=1; j<=knd; ++j) {
buy[i][j]=rd();sell[i][j]=rd();
}
memset(de, 0x3f, sizeof(de));
for (int i=1; i<=m; ++i) {
int f=rd(), t=rd(), v=rd();
de[f][t] = min(de[f][t], ll(v));
}
Floyd(de);
for (int t=1; t<=knd; ++t) {
for (int i=1; i<=n; ++i) if (buy[i][t] != -1)
for (int j=1; j<=n; ++j) if (sell[j][t] != -1) {
mxsell[i][j] = max(mxsell[i][j], sell[j][t]-buy[i][t]);
}
}
//compare profit/time>=some value
//profit>=some value *time
//profit-some_value*time>=0
int ql=-1, qr=int(1e9)+10;
while (ql+1 < qr) {
int c = (ql+qr)>>1;
static ll dc[maxn][maxn];
for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j) {
if (de[i][j] == inf) dc[i][j] = inf;
else dc[i][j] = c*1ll*de[i][j]-mxsell[i][j];
}
Floyd(dc);
bool loop = false;
for (int i=1; i<=n; ++i) if (dc[i][i] <= 0) { loop = true; break; }
//if i to go i is negative,meaning there is a negative loop
(loop ? ql : qr) = c;
}
printf("%d",ql);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
merchant.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
3 | #pragma GCC optimization (unroll-loops)
|
merchant.cpp:2:22: warning: '#pragma GCC optimize' is not a string or number [-Wpragmas]
2 | #pragma GCC optimize(Ofast)
| ^~~~~
# | 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... |