답안 #43215

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
43215 2018-03-10T23:53:17 Z smu201111192 버스 (JOI14_bus) C++14
35 / 100
391 ms 63004 KB
#include <iostream>
#include <cstdio>
#include <cassert>
#include <bitset>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int MAXN = 100005;
const int MAXV = 500005;
int n,m,id = 0;
map<pair<int,int>,int> dict;
pair<int,int> cv[MAXV];
vector<int> adj[MAXV];
vector<int> node[MAXN];
struct edge{
    int u,v,st,ed;
    void read(){cin>>u>>v>>st>>ed;}
}e[MAXN];
int dp[MAXV];
void addEdge(int u,int v){
    adj[v].push_back(u);
}
//n에 도착할 수 있는 가장 늦은 시점을 구하자.
int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        e[i].read();
        dict[{e[i].u,e[i].st}];
        dict[{e[i].v,e[i].ed}];
        node[e[i].u].push_back(e[i].st);
        node[e[i].v].push_back(e[i].ed);
    }
    for(int i = 1; i <= n; i++) {
        sort(node[i].begin(),node[i].end());
        node[i].erase(unique(node[i].begin(),node[i].end()),node[i].end());
    }
    vector<pair<int,int> > ord;
    for(auto it = dict.begin(); it!= dict.end(); it++){
        it->second = ++id;
        cv[id] = it->first;
        ord.push_back({it->first.second,id});
    }
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < (int)node[i].size() - 1; j++){
            int tu = node[i][j];
            int tv = node[i][j+1];
            addEdge(dict[make_pair(i,tu)],dict[make_pair(i,tv)]);
        }
    }
    for(int i = 1; i <= m; i++){
        int u = e[i].u; int v = e[i].v;
        int st = e[i].st; int ed = e[i].ed;
        addEdge(dict[{u,st}],dict[{v,ed}]);
    }
    sort(ord.begin(),ord.end());
    reverse(ord.begin(),ord.end());
    memset(dp,0x3f3f3f3f,sizeof(dp));
    
    for(int i = 0; i<ord.size();i++){
        int x = ord[i].second;
        int tm = ord[i].first;
        int pv = cv[x].first;
        if(pv == n)
            dp[x] = tm;
        for(auto y:adj[x])
            dp[y] = min(dp[y],dp[x]);
    }
    
    int Q; cin>> Q;
    if(Q > 10000){
        assert(1);
    }
    for(int i = 1; i <= Q; i++){
        int tm; cin >> tm;
        if(node[1].size() == 0) {
            cout<<-1; continue;
        }
        int lo = 0; int hi = node[1].size() - 1;
        int ret = -1;
        while(lo <= hi){
            int mid = (lo + hi)/2;
            int t = node[1][mid];
            //요시간에 출발하면 언제 도착혀?
            int v = dict[{1,t}];
            if(dp[v] <= tm){
                ret = max(ret,t);
                lo = mid + 1;
            }
            else hi = mid - 1;
        }
        cout<<ret<<"\n";
    }
    
    return 0;
}

Compilation message

bus.cpp: In function 'int main()':
bus.cpp:73:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i<ord.size();i++){
                     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 16504 KB Output is correct
2 Correct 15 ms 16608 KB Output is correct
3 Correct 17 ms 16608 KB Output is correct
4 Correct 16 ms 16608 KB Output is correct
5 Correct 15 ms 16752 KB Output is correct
6 Correct 16 ms 16752 KB Output is correct
7 Correct 16 ms 16752 KB Output is correct
8 Correct 15 ms 16752 KB Output is correct
9 Correct 15 ms 16752 KB Output is correct
10 Correct 16 ms 16752 KB Output is correct
11 Correct 20 ms 17132 KB Output is correct
12 Correct 19 ms 17184 KB Output is correct
13 Correct 18 ms 17184 KB Output is correct
14 Correct 20 ms 17184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 17184 KB Output is correct
2 Correct 57 ms 17516 KB Output is correct
3 Correct 54 ms 17540 KB Output is correct
4 Correct 20 ms 17540 KB Output is correct
5 Correct 19 ms 17540 KB Output is correct
6 Correct 20 ms 17540 KB Output is correct
7 Correct 44 ms 17540 KB Output is correct
8 Correct 15 ms 17540 KB Output is correct
9 Correct 61 ms 17540 KB Output is correct
10 Correct 74 ms 17836 KB Output is correct
11 Correct 38 ms 17836 KB Output is correct
12 Correct 102 ms 18092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 391 ms 62896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 313 ms 63004 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -