제출 #639349

#제출 시각아이디문제언어결과실행 시간메모리
639349shmad여행하는 상인 (APIO17_merchant)C++17
100 / 100
114 ms4364 KiB
#pragma GCC optimize("O3", "unroll-loops") // "Ofast" #pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt") #include <bits/stdc++.h> //#define int long long #define vt vector #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define ff first #define ss second #define dbg(x) cerr << #x << " = " << x << '\n' #define bit(x, i) ((x) >> (i) & 1) using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vvt = vt< vt<ll> >; const int N = 1e3 + 5, mod = 1e9 + 7, B = 500; const ll inf = 1e18 + 7, LIM = (1ll << 60); const double eps = 1e-6; int n; ll b[105][N], s[105][N], p[105][N]; void floyd (vvt &d) { for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) if (d[i][k] != inf && d[k][j] != inf) d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } int m, k; vvt d(105, vt<ll>(N, inf)), g(105, vt<ll>(N, inf)); bool check (ll x) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) g[i][j] = (d[i][j] == inf ? inf : (x * d[i][j]) - p[i][j]); g[i][i] = inf; } floyd(g); for (int i = 1; i <= n; i++) if (g[i][i] <= 0) return true; return false; } void solve () { cin >> n >> m >> k; for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) cin >> b[i][j] >> s[i][j]; } for (int i = 1; i <= m; i++) { ll x, y, w; cin >> x >> y >> w; d[x][y] = w; } floyd(d); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { for (int x = 1; x <= k; x++) { if (b[i][x] != -1 && s[j][x] != -1) p[i][j] = max(p[i][j], (s[j][x] - b[i][x])); } } } ll l = 1, r = 1e9, ans = 0; while (l <= r) { ll mid = l + r >> 1; if (check(mid)) ans = mid, l = mid + 1; else r = mid - 1; } cout << ans; cout << '\n'; } bool testcases = 0; signed main() { #ifdef ONLINE_JUDGE freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif cin.tie(0) -> sync_with_stdio(0); int test = 1; if (testcases) cin >> test; for (int cs = 1; cs <= test; cs++) { solve(); } }

컴파일 시 표준 에러 (stderr) 메시지

merchant.cpp: In function 'void solve()':
merchant.cpp:70:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   70 |   ll mid = l + r >> 1;
      |            ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...