Submission #197981

# Submission time Handle Problem Language Result Execution time Memory
197981 2020-01-24T12:39:14 Z stefdasca Travelling Merchant (APIO17_merchant) C++14
12 / 100
917 ms 13688 KB
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9

// #define fisier 1

using namespace std;

typedef long long ll;

int n, m, k, buy[102][1002], sell[102][1002], rf[102][102];

int maxdif[102][102];

ll bst[102], bst2[102];

map<ll, ll> ok[102];

vector<int> adj[102];
int main()
{

    #ifdef fisier
        ifstream f("input.in");
        ofstream g("output.out");
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m >> k;
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= k; ++j)
            cin >> buy[i][j] >> sell[i][j];
    }
    for(int i = 1; i <= m; ++i)
    {
        int a, b, c;
        cin >> a >> b >> c;
        rf[a][b] = c;
    }
    for(int k = 1; k <= n; ++k)
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= n; ++j)
                if(i != j && rf[i][k] && rf[k][j])
                {
                    if(rf[i][j] == 0 || rf[i][j] > rf[i][k] + rf[k][j])
                        rf[i][j] = rf[i][k] + rf[k][j];
                }

    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            if(i != j && rf[i][j])
            {
                for(int x = 1; x <= k; ++x)
                    if(i != j && rf[i][j] && buy[i][x] != -1 && sell[j][x] != -1)
                        maxdif[i][j] = max(maxdif[i][j], sell[j][x] - buy[i][x]);
                if(maxdif[i][j])
                    adj[i].pb(j);
            }
    ll ans = 0;
    int dif = 0;
    for(int start = 1; start <= n; ++start)
    {
        int states = dif + 250000 / n;
        deque<pair<int, pair<ll, ll> > >d;
        memset(bst, 0, sizeof(bst));
        memset(bst2, 0, sizeof(bst2));
        for(int i = 1; i <= n; ++i)
            ok[i].clear();
        d.pb({start, {0, 0}});
        while(!d.empty())
        {
            pair<int, pair<ll, ll> > nod = d[0];
            d.pop_front();
            if(bst[nod.fi] == 0 && nod.se.fi)
                bst[nod.fi] = nod.se.fi, bst2[nod.fi] = nod.se.se;
            else
                if(nod.se.fi * bst2[nod.fi] > nod.se.se * bst[nod.fi])
                    bst[nod.fi] = nod.se.fi, bst2[nod.fi] = nod.se.se;
                else
                    if(nod.se.se > bst2[nod.fi])
                        continue;
            if(ok[nod.fi].find(nod.se.se) == ok[nod.fi].end() || nod.se.fi > ok[nod.fi][nod.se.se])
                ok[nod.fi][nod.se.se] = nod.se.fi;
            else
                continue;
            --states;
            for(int x = 0; x < adj[nod.fi].size(); ++x)
            {
                int vec = adj[nod.fi][x];
                if(rf[vec][start] || vec == start)
                {
                    d.pb({vec, {nod.se.fi + maxdif[nod.fi][vec], nod.se.se + rf[nod.fi][vec]}});
                    ans = max(ans, (nod.se.fi + maxdif[nod.fi][vec]) / (nod.se.se + rf[nod.fi][vec] + rf[vec][start]));
                }
            }
            if(states == 0)
                break;
        }
        dif = states;
    }
    cout << ans;
    return 0;
}

Compilation message

merchant.cpp: In function 'int main()':
merchant.cpp:97:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int x = 0; x < adj[nod.fi].size(); ++x)
                            ~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 35 ms 2552 KB Output is correct
2 Correct 4 ms 1144 KB Output is correct
3 Correct 4 ms 1144 KB Output is correct
4 Correct 3 ms 760 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 3 ms 760 KB Output is correct
7 Correct 8 ms 860 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 1 ms 816 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 9264 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 95 ms 13688 KB Output is correct
5 Incorrect 258 ms 4324 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 917 ms 5272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 168 ms 9264 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 95 ms 13688 KB Output is correct
5 Incorrect 258 ms 4324 KB Output isn't correct
6 Halted 0 ms 0 KB -