답안 #136512

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
136512 2019-07-25T12:04:05 Z Milki 여행하는 상인 (APIO17_merchant) C++14
0 / 100
130 ms 2120 KB
#include<bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int, int> point;

const int MAXN = 105, MAXK = 1e3 + 5;
const ll inf = 1e18;

ll n, m, items;
ll dist[MAXN][MAXN];
ll buy[MAXN][MAXK], sell[MAXN][MAXK], profit[MAXN][MAXN];

bool check(ll x){
  ll d[MAXN][MAXN];
  REP(i, n) REP(j, n)
    d[i][j] = -inf;

  REP(i, n) REP(j, n)
    d[i][j] = max(d[i][j], profit[i][j] - dist[i][j] * x);

  REP(k, n) REP(i, n) REP(j, n)
    d[i][j] = max(d[i][j], d[i][k] + d[k][j]);

  REP(i, n)
    if(d[i][i] >= 0)
      return true;
  return false;
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);

  REP(i, MAXN) REP(j, MAXN) dist[i][j] = inf;

  cin >> n >> m >> items;
  REP(i, n) REP(j, items){ cin >> buy[i][j] >> sell[i][j]; }
  REP(i, m){
    ll a, b, c; cin >> a >> b >> c;
    a --; b --;
    dist[a][b] = min(dist[a][b], c);
  }

  REP(k, n) REP(i, n) REP(j, n)
    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

  REP(i, n) REP(j, n) REP(k, items)
    if(buy[i][k] != -1 && sell[j][k] != -1)
      profit[i][j] = max(profit[i][j], sell[j][k] - buy[i][k]);

  ll lo = 0, hi = 1e16;
  while(lo < hi){
    ll mid = (lo + hi + 1) >> 1;
    if(check(mid))
      lo = mid;
    else
      hi = mid - 1;
  }
  cout << lo;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 103 ms 2040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 888 KB Output is correct
2 Correct 13 ms 892 KB Output is correct
3 Correct 14 ms 1016 KB Output is correct
4 Correct 13 ms 888 KB Output is correct
5 Correct 15 ms 892 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Incorrect 13 ms 888 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 1528 KB Output is correct
2 Incorrect 130 ms 2120 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 888 KB Output is correct
2 Correct 13 ms 892 KB Output is correct
3 Correct 14 ms 1016 KB Output is correct
4 Correct 13 ms 888 KB Output is correct
5 Correct 15 ms 892 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Incorrect 13 ms 888 KB Output isn't correct
8 Halted 0 ms 0 KB -