이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 1; (i) <= (n); ++i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define ford(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define FORD(i, n) for(int i = ((n) - 1); i >= 0; --i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task "merchant"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
inline int readInt() {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();int n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline ll readLong() {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();ll n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline string readString() {char c;while(c=getchar(),c==' '||c=='\n'||c=='\t');string s({c});while(c=getchar(),c!=EOF&&c!=' '&&c!='\n'&&c!='\t')s+=c;return s;}
const int N = 100 + 33;
const int M = 9900 + 33;
const int N1 = 2e3 + 10;
const int K = 1e3 + 10;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LINF = 1e17 + 2;
const int block_size = 500;
const int LOG = 40;
const int offset = N;
const int LIM = 11 ;
const int AL = 26;
int n, m, num_market;
int b[N][K], s[N][K], w[M];
pii e[M];
ll max_path[N][N], d[N][N];
ll d_[N][N];
bool check(ll val)
{
rep(i, n) rep(j, n)
{
if(d[i][j] != LINF)
d_[i][j] = max_path[i][j] - val * d[i][j];
else d_[i][j] = -LINF;
}
rep(k, n) rep(i, n) rep(j, n)
maximize(d_[i][j], d_[i][k] + d_[k][j]);
rep(i, n) if(d_[i][i] >= 0) return 1;
return 0;
}
void solve()
{
cin >> n >> m >> num_market;
rep(i, n) rep(j, num_market) cin >> b[i][j] >> s[i][j];
rep(i, m) cin >> e[i].fi >> e[i].se >> w[i];
rep(i, n)
{
rep(j, n) d[i][j] = LINF;
d[i][i] = 0;
}
rep(i, m)
d[e[i].fi][e[i].se] = w[i];
rep(k, n) rep(i, n) rep(j, n)
minimize(d[i][j], d[i][k] + d[k][j]);
rep(i, n) d[i][i] = LINF;
rep(i, n) rep(j, n)
{
max_path[i][j] = 0;
rep(k, num_market)
if(b[i][k] != -1 && s[j][k] != -1)
maximize(max_path[i][j], 1ll * s[j][k] - b[i][k]);
}
ll l = 1, r = 1e9, res = 0;
while(l <= r)
{
ll mid = l + r >> 1;
if(check(mid)) res = mid, l = mid + 1;
else r = mid - 1;
}
cout << res;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int TC = 1;
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
while(TC--)
{
solve();
cout << endl;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
merchant.cpp: In function 'void solve()':
merchant.cpp:97:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
97 | ll mid = l + r >> 1;
| ~~^~~
merchant.cpp: In function 'int main()':
merchant.cpp:113:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
113 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:114:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
114 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |