Submission #200598

# Submission time Handle Problem Language Result Execution time Memory
200598 2020-02-07T13:57:59 Z Rakhmand Travelling Merchant (APIO17_merchant) C++14
100 / 100
92 ms 4600 KB
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 1e5 + 10;
const long long MNN = 1e6 + 200;
const long long MOD = 1e9 + 7;
const long long INF = 1e16;
const int OO = 1e9 + 10;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

void istxt(bool yes){
    if(yes == 1){
        freopen("balancing.in", "r", stdin);
        freopen("balancing.out", "w", stdout);
    }else{
        freopen("/Users/rakhmanabdirashov/Desktop/folder/Programming/Road2Master/Road2Master/input.txt", "r", stdin);
    }
}

int n, m, k;
llong b[110][1100], s[110][1100], ans[110][110], u[MXN], v[MXN], cost[MXN], dp[110][110];
llong g[110][110];
llong mx[110][110];

bool check(llong ans){
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(g[i][j] == INF){
                dp[i][j] = INF;
            }else{
                dp[i][j] = g[i][j] * ans - mx[i][j];
            }
        }
        dp[i][i] = INF;
    }
    for(int k = 1; k <= n; k++){
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }
    for(int i = 1; i <= n; i++){
        if(dp[i][i] <= 0){
            return true;
        }
    }
    return false;
}

int main () {
    ios;
    //istxt(0);
    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 <= n; i++){
        for(int j = 1; j <= n; j++){
            g[i][j] = INF;
        }
        g[i][i] = 0;
    }
    for(int i = 1; i <= m; i++){
        cin >> u[i] >> v[i] >> cost[i];
        g[u[i]][v[i]] = cost[i];
    }
    for(int k = 1; k <= n; k++){
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= k; j++){
            if(b[i][j] != -1){
                for(int nx = 1; nx <= n; nx++){
                    if(s[nx][j] != -1){
                        mx[i][nx] = max(mx[i][nx], s[nx][j] - b[i][j]);
                    }
                }
            }
        }
    }
    llong l = 0, r = 1e9;
    while(r - l > 1){
        llong  m = (r + l) / 2;
        if(check(m)){
            l = m;
        }else{
            r = m;
        }
    }
    cout << (check(r) ? r : l);
}

Compilation message

merchant.cpp: In function 'void istxt(bool)':
merchant.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("balancing.in", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("balancing.out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("/Users/rakhmanabdirashov/Desktop/folder/Programming/Road2Master/Road2Master/input.txt", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 67 ms 2296 KB Output is correct
2 Correct 41 ms 1276 KB Output is correct
3 Correct 42 ms 1272 KB Output is correct
4 Correct 10 ms 888 KB Output is correct
5 Correct 10 ms 888 KB Output is correct
6 Correct 10 ms 888 KB Output is correct
7 Correct 11 ms 888 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 10 ms 888 KB Output is correct
10 Correct 10 ms 888 KB Output is correct
11 Correct 11 ms 888 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 11 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 888 KB Output is correct
2 Correct 10 ms 888 KB Output is correct
3 Correct 10 ms 888 KB Output is correct
4 Correct 10 ms 888 KB Output is correct
5 Correct 11 ms 1016 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 12 ms 888 KB Output is correct
8 Correct 11 ms 992 KB Output is correct
9 Correct 10 ms 888 KB Output is correct
10 Correct 13 ms 1016 KB Output is correct
11 Correct 12 ms 1020 KB Output is correct
12 Correct 11 ms 1016 KB Output is correct
13 Correct 11 ms 1016 KB Output is correct
14 Correct 11 ms 1016 KB Output is correct
15 Correct 12 ms 1016 KB Output is correct
16 Correct 10 ms 892 KB Output is correct
17 Correct 11 ms 888 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 12 ms 1016 KB Output is correct
20 Correct 11 ms 888 KB Output is correct
21 Correct 15 ms 888 KB Output is correct
22 Correct 11 ms 888 KB Output is correct
23 Correct 10 ms 888 KB Output is correct
24 Correct 10 ms 888 KB Output is correct
25 Correct 11 ms 888 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 10 ms 888 KB Output is correct
28 Correct 10 ms 888 KB Output is correct
29 Correct 11 ms 888 KB Output is correct
30 Correct 5 ms 504 KB Output is correct
31 Correct 11 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 1528 KB Output is correct
2 Correct 87 ms 2300 KB Output is correct
3 Correct 44 ms 1528 KB Output is correct
4 Correct 48 ms 1528 KB Output is correct
5 Correct 48 ms 1656 KB Output is correct
6 Correct 45 ms 1528 KB Output is correct
7 Correct 11 ms 888 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 12 ms 1016 KB Output is correct
10 Correct 11 ms 888 KB Output is correct
11 Correct 15 ms 888 KB Output is correct
12 Correct 11 ms 888 KB Output is correct
13 Correct 10 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 888 KB Output is correct
2 Correct 10 ms 888 KB Output is correct
3 Correct 10 ms 888 KB Output is correct
4 Correct 10 ms 888 KB Output is correct
5 Correct 11 ms 1016 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 12 ms 888 KB Output is correct
8 Correct 11 ms 992 KB Output is correct
9 Correct 10 ms 888 KB Output is correct
10 Correct 13 ms 1016 KB Output is correct
11 Correct 12 ms 1020 KB Output is correct
12 Correct 11 ms 1016 KB Output is correct
13 Correct 11 ms 1016 KB Output is correct
14 Correct 11 ms 1016 KB Output is correct
15 Correct 12 ms 1016 KB Output is correct
16 Correct 10 ms 892 KB Output is correct
17 Correct 45 ms 1528 KB Output is correct
18 Correct 87 ms 2300 KB Output is correct
19 Correct 44 ms 1528 KB Output is correct
20 Correct 48 ms 1528 KB Output is correct
21 Correct 48 ms 1656 KB Output is correct
22 Correct 45 ms 1528 KB Output is correct
23 Correct 11 ms 888 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 12 ms 1016 KB Output is correct
26 Correct 11 ms 888 KB Output is correct
27 Correct 15 ms 888 KB Output is correct
28 Correct 11 ms 888 KB Output is correct
29 Correct 10 ms 888 KB Output is correct
30 Correct 43 ms 1400 KB Output is correct
31 Correct 48 ms 1656 KB Output is correct
32 Correct 57 ms 2808 KB Output is correct
33 Correct 43 ms 1704 KB Output is correct
34 Correct 45 ms 1656 KB Output is correct
35 Correct 46 ms 1656 KB Output is correct
36 Correct 87 ms 4344 KB Output is correct
37 Correct 6 ms 376 KB Output is correct
38 Correct 5 ms 376 KB Output is correct
39 Correct 42 ms 1528 KB Output is correct
40 Correct 46 ms 1784 KB Output is correct
41 Correct 44 ms 1528 KB Output is correct
42 Correct 43 ms 1400 KB Output is correct
43 Correct 47 ms 1400 KB Output is correct
44 Correct 5 ms 376 KB Output is correct
45 Correct 12 ms 1016 KB Output is correct
46 Correct 12 ms 1016 KB Output is correct
47 Correct 12 ms 1016 KB Output is correct
48 Correct 89 ms 4600 KB Output is correct
49 Correct 92 ms 4600 KB Output is correct
50 Correct 5 ms 376 KB Output is correct
51 Correct 67 ms 2296 KB Output is correct
52 Correct 41 ms 1276 KB Output is correct
53 Correct 42 ms 1272 KB Output is correct
54 Correct 10 ms 888 KB Output is correct
55 Correct 10 ms 888 KB Output is correct
56 Correct 10 ms 888 KB Output is correct
57 Correct 11 ms 888 KB Output is correct
58 Correct 5 ms 376 KB Output is correct
59 Correct 10 ms 888 KB Output is correct
60 Correct 10 ms 888 KB Output is correct
61 Correct 11 ms 888 KB Output is correct
62 Correct 5 ms 504 KB Output is correct
63 Correct 11 ms 888 KB Output is correct