제출 #727219

#제출 시각아이디문제언어결과실행 시간메모리
727219josanneo22여행하는 상인 (APIO17_merchant)C++17
100 / 100
54 ms1364 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...