Submission #200336

# Submission time Handle Problem Language Result Execution time Memory
200336 2020-02-06T11:05:42 Z BThero Travelling Merchant (APIO17_merchant) C++17
12 / 100
1000 ms 1272 KB
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()
                                                  
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
 
#define pb push_back
#define mp make_pair
 
#define all(x) (x).begin(), (x).end()
 
#define fi first
#define se second
 
using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;   
typedef pair<int, int> pii;
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
const int MAXN = (int)1e2 + 5;
const int MAXK = (int)1e3 + 5;
const ll LINF = (ll)1e17;
 
int buy[MAXN][MAXK], sell[MAXN][MAXK];

ll dist[MAXN][MAXN], mx[MAXN][MAXN];
 
int adj[MAXN][MAXN];

ll dp[MAXN][2];
 
int n, m, k;
 
bool check(int x) {
    for (int st = 1; st <= n; ++st) {
        for (int i = 1; i <= n; ++i) {
            dp[i][0] = dp[i][1] = -LINF;
        }

        dp[st][0] = 0;
        queue<pii> q;
        q.push(mp(st, 0));

        while (!q.empty()) {
            int v = q.front().fi;
            int tp = q.front().se;
            q.pop();

            if (dp[st][1] >= 0) {
                return 1;
            }

            for (int to = 1; to <= n; ++to) {                
                if (to != v && dist[v][to] != LINF) {
                    ll w = mx[v][to] - dist[v][to] * x;

                    if (dp[v][tp] + w > dp[to][1]) {
                        dp[to][1] = dp[v][tp] + w;
                        q.push(mp(to, 1));
                    }
                }
            }            
        }
    }
 
    return 0; 
}
 
void solve() {
    scanf("%d %d %d", &n, &m, &k);
 
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= k; ++j) {
            scanf("%d %d", &buy[i][j], &sell[i][j]);
        }
    }
 
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            adj[i][j] = -1;
            dist[i][j] = LINF;
        }

        dist[i][i] = 0;
    }
 
    for (int i = 1; i <= m; ++i) {
        int u, v, w;
        scanf("%d %d %d", &u, &v, &w);
        adj[u][v] = dist[u][v] = w;
    }
 
    for (int k = 1; k <= n; ++k) {
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }    

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            mx[i][j] = 0;

            for (int ii = 1; ii <= k; ++ii) {
                if (buy[i][ii] != -1 && sell[j][ii] != -1) {
                    mx[i][j] = max(mx[i][j], (ll)sell[j][ii] - buy[i][ii]);
                }
            }
        }
    }

    int l = 1, r = (int)1e9, ans = 0;

    while (l <= r) {
        int mid = (l + r) >> 1;

        if (check(mid)) {
            l = mid + 1;
            ans = mid;
        }
        else {
            r = mid - 1;
        }
    }
 
    printf("%d\n", ans);
}
 
int main() {
    int tt = 1;
 
    while (tt--) {
        solve();
    }
 
    return 0;
}

Compilation message

merchant.cpp: In function 'void solve()':
merchant.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &m, &k);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:77:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d", &buy[i][j], &sell[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:92:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &u, &v, &w);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 102 ms 1272 KB Output is correct
2 Correct 76 ms 1272 KB Output is correct
3 Correct 51 ms 1272 KB Output is correct
4 Correct 13 ms 760 KB Output is correct
5 Correct 11 ms 888 KB Output is correct
6 Correct 13 ms 888 KB Output is correct
7 Correct 15 ms 760 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 12 ms 888 KB Output is correct
10 Correct 12 ms 760 KB Output is correct
11 Correct 15 ms 760 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 11 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 888 KB Output is correct
2 Execution timed out 1085 ms 888 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 1272 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 888 KB Output is correct
2 Execution timed out 1085 ms 888 KB Time limit exceeded
3 Halted 0 ms 0 KB -