답안 #784076

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
784076 2023-07-15T15:53:00 Z ZHIRDILBILDIZ 사이버랜드 (APIO23_cyberland) C++17
49 / 100
341 ms 14056 KB
#include<bits/stdc++.h>
#include "cyberland.h"
#define ll long long
#define fi first
#define se second
using namespace std ;
const int N = 1e5, iu = 3 ;
bool us[N], fl[iu][31] ;
double dist[N], ds[iu][31] ;
vector<int> abu ;
vector<pair<int, int>> v[N] ;
set<pair<double, int>> s ;
set<pair<pair<double, int>, int>> pq ;
void deikstra()
{
    for(int i = 0 ; i < N ; i++)
        dist[i] = 1e18 ;
    for(auto i : s)
        dist[i.se] = 0 ;
    while(s.size())
    {
        pair<double, int> p = *s.begin() ;
        s.erase(s.begin()) ;
        if(us[p.se])
            continue ;
        us[p.se] = 1 ;
        for(auto i : v[p.se])
        {
            if(us[i.fi] || dist[i.fi] <= p.fi + i.se)
                continue ;
            dist[i.fi] = p.fi + i.se ;
            s.insert({dist[i.fi], i.fi}) ;
        }
    }
}
void for_more_point(int k)
{
    for(int i = 0 ; i < iu ; i++)
        for(int j = 0 ; j <= k ; j++)
            ds[i][j] = 1e18, fl[i][j] = 0 ;
    ds[0][k] = 0 ;
    pq.insert({{0, 0}, k}) ;
    while(pq.size())
    {
        auto p = *pq.begin() ;
        double dis = p.fi.fi ;
        int city = p.fi.se, kn = p.se ;
        pq.erase(pq.begin()) ;
        if(us[city] || fl[city][kn])
            continue ;
        fl[city][kn] = 1 ;
        for(auto i : v[city])
        {
            if(dis + i.se < ds[i.fi][kn])
            {
                ds[i.fi][kn] = dis + i.se ;
                pq.insert({{ds[i.fi][kn], i.fi}, kn}) ;
            }
            if(kn && !abu[i.fi] && ds[i.fi][kn - 1])
            {
                ds[i.fi][kn - 1] = 0 ;
                pq.insert({{0, i.fi}, kn - 1}) ;
            }
            if(kn && abu[i.fi] == 2 && ds[i.fi][kn - 1] >= (dis + i.se) / 2)
            {
                ds[i.fi][kn - 1] = (dis + i.se) / 2 ;
                pq.insert({{ds[i.fi][kn - 1], i.fi}, kn - 1}) ;
            }
        }
    }
}
double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr)
{
    bool flag1 = 0, flag2 = 0 ;
    s.clear() ;
    for(int i = 0 ; i < n ; i++)
    {
        us[i] = 0 ;
        dist[i] = 0 ;
        v[i].clear() ;
        if(arr[i] != 1)flag1 = 1 ;
        if(arr[i] == 2)flag2 = 1 ;
    }
    for(int i = 0 ; i < m ; i++)
    {
        v[x[i]].push_back({y[i], c[i]}) ;
        v[y[i]].push_back({x[i], c[i]}) ;
    }
    if(!flag1)
    {
        s.insert({0, 0}) ;
        deikstra() ;
        if(dist[h] == 1e18)
            return -1 ;
        else
            return dist[h] ;
    }
    if(!flag2)
    {
        us[h] = 1 ;
        s.insert({0, 0}) ;
        deikstra() ;
        for(int i = 0 ; i < n ; i++)
        {
            if(us[i] && !arr[i] || !i)
                s.insert({0, i}) ;
            us[i] = 0 ;
        }
        deikstra() ;
        if(dist[h] == 1e18)
            return -1 ;
        else
            return dist[h] ;
    }
    abu = arr ;
    us[h] = 1 ;
    for_more_point(k) ;
    double ans = 1e18 ;
    for(int i = 0 ; i <= k ; i++)
        ans = min(ans, ds[h][i]) ;
    if(ans == 1e18)return -1 ;
    else return ans ;
}
//signed main()
//{
//    freopen("rsub1_01.in", "r", stdin) ;
//    ios_base::sync_with_stdio( 0 ) ;
//    cin.tie( 0 ) ;
//    cout.tie( 0 ) ;
//    int t ;
//    cin >> t ;
//    while(t--)
//    {
//        int n, m, k, h ;
//        cin >> n >> m >> k >> h ;
//        vector<int> a(m), b(m), c(m), arr(n) ;
//        for(int i = 0 ; i < n ; i++)
//            cin >> arr[i] ;
//        for(int i = 0 ; i < m ; i++)
//            cin >> a[i] >> b[i] >> c[i] ;
//        cout << fixed << setprecision(9) << solve(n, m, k, h, a, b, c, arr) << '\n' ;
//    }
//    return 0 ;
//}

Compilation message

cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:105:22: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  105 |             if(us[i] && !arr[i] || !i)
# 결과 실행 시간 메모리 Grader output
1 Correct 341 ms 3532 KB Correct.
2 Correct 332 ms 3800 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 3596 KB Correct.
2 Correct 28 ms 3584 KB Correct.
3 Correct 25 ms 3540 KB Correct.
4 Correct 26 ms 3540 KB Correct.
5 Correct 33 ms 3540 KB Correct.
6 Correct 20 ms 4232 KB Correct.
7 Correct 25 ms 4180 KB Correct.
8 Correct 12 ms 4820 KB Correct.
9 Correct 54 ms 3496 KB Correct.
10 Correct 71 ms 3488 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 3588 KB Correct.
2 Correct 36 ms 3540 KB Correct.
3 Correct 39 ms 3740 KB Correct.
4 Correct 93 ms 3488 KB Correct.
5 Correct 92 ms 3496 KB Correct.
6 Correct 7 ms 4180 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Runtime error 35 ms 14056 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 3660 KB Correct.
2 Correct 24 ms 3572 KB Correct.
3 Correct 23 ms 3612 KB Correct.
4 Correct 21 ms 4284 KB Correct.
5 Correct 63 ms 3720 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 3584 KB Correct.
2 Correct 37 ms 3540 KB Correct.
3 Correct 32 ms 8588 KB Correct.
4 Correct 17 ms 4256 KB Correct.
5 Correct 92 ms 3412 KB Correct.
6 Correct 30 ms 3628 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 2776 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 6868 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -