Submission #446450

# Submission time Handle Problem Language Result Execution time Memory
446450 2021-07-22T00:54:04 Z stat0r1c Robot (JOI21_ho_t4) C++11
0 / 100
3000 ms 62072 KB
#include <bits/stdc++.h>
/* #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> */
using namespace std;
// using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned ll;
template<typename T> using vt = vector<T>;
using vi = vt<int>;
using vvi = vt<vi>;
using ii = pair<int, int>;
using vii = vt<ii>;
/* template<typename T>
using indexed_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; */
/* struct chash {
    static ull hash_f(ull x) {x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(ull x) const {static const ull RANDOM = chrono::steady_clock::now().time_since_epoch().count();return hash_f(x + RANDOM);}
};
struct iihash {
    template <class T1, class T2>
    size_t operator () (const pair<T1,T2> &p) const {auto h1 = hash<T1>{}(p.first);auto h2 = hash<T2>{}(p.second);return h1 ^ h2;}
};
template<class T1, class T2, class T3> using ii_umap = gp_hash_table<pair<T1,T2>,T3,iihash>;
template<class T1, class T2> using f_umap = gp_hash_table<T1,T2,chash>;
template<class T1, class T2> using o_umap = gp_hash_table<T1,T2>; */
#define sqr(x) (x)*(x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define debug(x) cerr << #x << " -> " << x << '\n'
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int inf = 1e9 + 7;
const ll infll = 1e18 + 10;
template <typename T> inline T fgcd(T a, T b) {while(b) swap(b, a %= b); return a;}
ll fpow(ll a, ll b) {ll o = 1; for(;b;b >>= 1) {if(b & 1) o = o * a;a = a * a;} return o;}
ll fpow(ll a, ll b, ll m) {ll o = 1; a %= m; for(;b;b >>= 1) {if(b & 1) o = o * a % m;a = a * a % m;} return o;}
template<class T> void uniq(vt<T> &a) {sort(all(a));a.resize(unique(all(a)) - a.begin());}
void setIO(string name = "", string inp = "inp", string out = "out") {
    cin.tie(0)->sync_with_stdio(0);
    if(sz(name)) {
        if(sz(inp)) freopen((name+"."+inp).c_str(), "r", stdin);
        if(sz(out)) freopen((name+"."+out).c_str(), "w", stdout);
    }
}
using iii = pair<int, ii>;
using pli = pair<pair<ll, ll>, ii>;
int n,m,x,y,c,p;
ll ans = infll;
int main() {
    setIO();
    cin >> n >> m;
    vt<map<int, ll>> price(n + 1), d(n + 1);
    vt<vt<iii>> a(n + 1);
    while(m--) {
        cin >> x >> y >> c >> p;
        price[x][c] += p;
        price[y][c] += p;
        d[x][0] = d[y][0] = d[x][c] = d[y][c] = infll;
        a[x].eb(y, mp(c, p));
        a[y].eb(x, mp(c, p));
    }
    priority_queue<pli, vt<pli>, greater<pli>> pq;
    pq.push({{0, 0}, {1, 0}});
    d[1][0] = 0;
    while(!pq.empty()) {
        tie(x, c) = pq.top().S;
        ll du = pq.top().F.F, e = pq.top().F.S;
        pq.pop();
        if(d[x][c] != du) continue;
        for(iii v : a[x]) {
            ll k = min(ll(v.S.S), price[x][v.S.F] - v.S.S);
            if(2 * v.S.S > price[x][v.S.F]) {
                if(c == v.S.F && d[v.F][0] > du + k - e) {
                    pq.push({{d[v.F][0] = du + k - e, 0}, {v.F, 0}});
                }
                else if(c != v.S.F && d[v.F][0] > du + k) {
                    pq.push({{d[v.F][0] = du + k, 0}, {v.F, 0}});
                }
            }
            else {
                if(d[v.F][v.S.F] > du + k) {
                    pq.push({{d[v.F][v.S.F] = du + k, k}, {v.F, v.S.F}});
                }
            }
        }
    }
    for(auto i : d[n]) ans = min(ans, i.S);
    cout << (ans == infll ? -1 : ans);
    return 0;
}

Compilation message

Main.cpp: In function 'void setIO(std::string, std::string, std::string)':
Main.cpp:45:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         if(sz(inp)) freopen((name+"."+inp).c_str(), "r", stdin);
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:46:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         if(sz(out)) freopen((name+"."+out).c_str(), "w", stdout);
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 3 ms 492 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Incorrect 101 ms 844 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 218 ms 19388 KB Output is correct
2 Correct 79 ms 10500 KB Output is correct
3 Correct 181 ms 16728 KB Output is correct
4 Correct 115 ms 14208 KB Output is correct
5 Execution timed out 3078 ms 62072 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 3 ms 492 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Incorrect 101 ms 844 KB Output isn't correct
10 Halted 0 ms 0 KB -