Submission #930876

# Submission time Handle Problem Language Result Execution time Memory
930876 2024-02-20T14:54:06 Z AndiR Voting Cities (NOI22_votingcity) C++11
20 / 100
1000 ms 4416 KB
// Author: Tanasescu Andrei-Rares
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <iomanip>
#include <vector>
#include <cassert>

#pragma GCC optimize("O3")

#define fi first
#define se second
#define pb push_back
#define pf push_front

using namespace std;

ifstream fin ("");
ofstream fout ("");

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll Nmax=5e3, inf=(ll)1e18;

int n, m, k, q, st, p[5];
bool fn[Nmax];
ll dist[32][Nmax];
vector<pii> ad[Nmax];
struct info{
    int nod, tip;
    ll cost;
    bool operator<(const info &nxt)const{
        return cost>nxt.cost;
    }
};
priority_queue<info> pq;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>m>>k;
    int nr;
    for (int i=0; i<k; i++){
        cin>>nr;
        fn[nr]=1;
    }
    int a, b, c;
    for (int i=0; i<m; i++){
        cin>>a>>b>>c;
        ad[a].pb({b, c});
    }
    cin>>q;
    while (q--){
        cin>>st;
        for (int i=0; i<5; i++)
            cin>>p[i];
        for (int i=0; i<n; i++)
            for (int j=0; j<32; j++)
                dist[j][i]=inf;
        dist[0][st]=0;
        pq.push({st, 0, 0});
        while (!pq.empty() && !fn[pq.top().nod]){
            info crt=pq.top();
            //cout<<crt.nod<<' '<<crt.tip<<' '<<crt.cost<<'\n';
            pq.pop();
            for (auto it:ad[crt.nod]){
                if (dist[crt.tip][it.fi]>crt.cost+it.se){
                    dist[crt.tip][it.fi]=crt.cost+it.se;
                    pq.push({it.fi, crt.tip, crt.cost+it.se});
                }
                for (int t=0; t<5; t++){
                    int newtip=(crt.tip | (1<<t));
                    ll newcost=crt.cost+it.se-it.se*(t+1)/10+p[t];
                    if (p[t]!=-1 && newtip!=crt.tip && dist[newtip][it.fi]>newcost){
                        dist[newtip][it.fi]=newcost;
                        pq.push({it.fi, newtip, newcost});
                    }
                }
            }
        }
        if (pq.empty())
            cout<<"-1\n";
        else{
            cout<<pq.top().cost<<'\n';
            while (!pq.empty())
                pq.pop();
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2140 KB Output is correct
2 Correct 2 ms 1884 KB Output is correct
3 Correct 4 ms 2176 KB Output is correct
4 Correct 1 ms 576 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2140 KB Output is correct
2 Correct 2 ms 1884 KB Output is correct
3 Correct 4 ms 2176 KB Output is correct
4 Correct 1 ms 576 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 25 ms 2204 KB Output is correct
7 Correct 16 ms 1884 KB Output is correct
8 Correct 37 ms 2136 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2140 KB Output is correct
2 Correct 2 ms 1884 KB Output is correct
3 Correct 4 ms 2176 KB Output is correct
4 Correct 1 ms 576 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 25 ms 2204 KB Output is correct
7 Correct 16 ms 1884 KB Output is correct
8 Correct 37 ms 2136 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 9 ms 2136 KB Output is correct
12 Correct 11 ms 1880 KB Output is correct
13 Correct 11 ms 2124 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2140 KB Output is correct
2 Correct 2 ms 1884 KB Output is correct
3 Correct 4 ms 2176 KB Output is correct
4 Correct 1 ms 576 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 50 ms 4300 KB Output is correct
7 Correct 6 ms 1884 KB Output is correct
8 Correct 11 ms 2776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2140 KB Output is correct
2 Correct 2 ms 1884 KB Output is correct
3 Correct 4 ms 2176 KB Output is correct
4 Correct 1 ms 576 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 25 ms 2204 KB Output is correct
7 Correct 16 ms 1884 KB Output is correct
8 Correct 37 ms 2136 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 50 ms 4300 KB Output is correct
12 Correct 6 ms 1884 KB Output is correct
13 Correct 11 ms 2776 KB Output is correct
14 Execution timed out 1054 ms 4416 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 2140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2140 KB Output is correct
2 Correct 2 ms 1884 KB Output is correct
3 Correct 4 ms 2176 KB Output is correct
4 Correct 1 ms 576 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 25 ms 2204 KB Output is correct
7 Correct 16 ms 1884 KB Output is correct
8 Correct 37 ms 2136 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 9 ms 2136 KB Output is correct
12 Correct 11 ms 1880 KB Output is correct
13 Correct 11 ms 2124 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 50 ms 4300 KB Output is correct
17 Correct 6 ms 1884 KB Output is correct
18 Correct 11 ms 2776 KB Output is correct
19 Execution timed out 1054 ms 4416 KB Time limit exceeded
20 Halted 0 ms 0 KB -