답안 #469697

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469697 2021-09-01T15:43:57 Z MohamedAliSaidane Robot (JOI21_ho_t4) C++14
0 / 100
282 ms 21628 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> ti;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ld,ld> pld;
#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front
#define ff first
#define ss second
#define MOD (int)(1e8)
#define INF (ll) (1e18)
#define all(v) (v).begin(),(v).end()
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;}
ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);}
ld pointdist(ld x, ld y, ld point) { return ((x-point)*(y-point))/abs(x-y); }
//ld dist(ld x, ld y, ld a, ld b){ return sqrt((x-a)*(x-a) + (y-b)*(y-b)); }
const int nx[8] = {0, 0, 1, -1,1,1,-1,-1}, ny[8] = {1, -1, 0, 0,1,-1,1,-1}; //East, West, South, North+
////////////******SOLUTION******\\\\\\\\\\\

struct edge
{
    ll arv = 1;
    ll col = 1;
    ll cost = 1;
};
const int MAX_N = 1e5 + 4;
const int MAX_M = 2e5 + 4;
bool visited[MAX_N];
ll dist[MAX_N];
ll n, m;
vector<edge> adj[MAX_N];
ll sp()
{
    set<pll> pq;
    pq.insert({0,1});
    while(!pq.empty())
    {
        pll pr = *(pq.begin());
        pq.erase(pq.begin());
        ll node = pr.ss;
        ll d = pr.ff;
        if(visited[node])
            continue;
        dist[node] =d;
        visited[node] = true;
        if(node == n)
            return d;
        for(auto e: adj[node])
        {
            if(visited[e.arv]) continue;
            if(dist[e.arv] > dist[node] + e.cost)
            {
                dist[e.arv] = dist[node] + e.cost;
                pq.insert({dist[node]+e.cost,e.arv});
            }
        }
    }
    return -1;
}

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 0; i <m; i ++)
    {
        ll a, b, c, p;
        cin >> a >> b >> c >> p;
        edge na, nb;
        na.arv = b; nb.arv = a;
        na.col = nb.col = c;
        na.cost = nb.cost  = p;
        adj[a].pb(na);
        adj[b].pb(nb);
    }
    for(ll i = 1; i <=n; i ++)
    {
        dist[i] = i == 1? 0: INF;
        map<ll,ll> cou;
        for(auto e: adj[i])
        {
            cou[e.col] += e.cost;
        }
        for(int j = 0; j < adj[i].size(); j ++)
        {
            adj[i][j].cost = min(adj[i][j].cost,cou[adj[i][j].col]-adj[i][j].cost);
        }
    }
    cout << sp();

}
/*
Identify problem diagram: Brute force, Greedy, Dynamic Programming, Divide and Conquer
Reformulate the problem into something more theoretical
!!!!! IMPLICIT GRAPH ??????
!!!!! PAY ATTENTION TO THE CONSTRAINTS: DP nD ? BF ? BITMASKING ?
!!!!! SOLVE THE SUBTASKS FIRST: IT'S TOTALLY OK NOT TO SOLVE THE PROBLEM ENTIRELY
Search for multiple approaches: select the seemingly optimal one
Remember that you're the king of CP
Change your approach
Imagine Corner cases before submitting
Don't spend too much time on the problem: move on !
*/

Compilation message

Main.cpp:26:1: warning: multi-line comment [-Wcomment]
   26 | ////////////******SOLUTION******\\\\\\\\\\\
      | ^
Main.cpp: In function 'int main()':
Main.cpp:93:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |         for(int j = 0; j < adj[i].size(); j ++)
      |                        ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 3 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Incorrect 4 ms 2764 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 9192 KB Output is correct
2 Correct 30 ms 6252 KB Output is correct
3 Correct 88 ms 15804 KB Output is correct
4 Correct 43 ms 8040 KB Output is correct
5 Incorrect 282 ms 21628 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 3 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Incorrect 4 ms 2764 KB Output isn't correct
10 Halted 0 ms 0 KB -