Submission #143510

#TimeUsernameProblemLanguageResultExecution timeMemory
143510kig9981버스 (JOI14_bus)C++17
100 / 100
514 ms35832 KiB
#include <bits/stdc++.h> #ifdef NON_SUBMIT #define TEST(n) (n) #define tout cerr #else #define TEST(n) ((void)0) #define tout cin #endif using namespace std; vector<tuple<int,int,int>> adj[100000]; vector<int> D[100000], x[100000]; int solve(int c, int t) { if(c==0) return x[c][t]; if(D[c][t]!=0x7fffffff) return D[c][t]; if(t) D[c][t]=solve(c,t-1); else D[c][t]=-1; for(int i=lower_bound(adj[c].begin(),adj[c].end(),make_tuple(x[c][t],-1,-1))-adj[c].begin();i<adj[c].size() && get<0>(adj[c][i])==x[c][t];i++) { int tmp, n, v; tie(tmp,n,v)=adj[c][i]; v=lower_bound(x[n].begin(),x[n].end(),v)-x[n].begin(); D[c][t]=max(D[c][t],solve(n,v)); } return D[c][t]; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); TEST(freopen("input.txt", "r", stdin)); TEST(freopen("output.txt", "w", stdout)); TEST(freopen("debug.txt", "w", stderr)); int N, M; for(cin>>N>>M;M--;) { int A, B, X, Y; cin>>A>>B>>X>>Y; adj[--B].emplace_back(Y,--A,X); x[A].push_back(X); x[B].push_back(Y); } for(int i=0;i<N;i++) { sort(adj[i].begin(),adj[i].end()); sort(x[i].begin(),x[i].end()); x[i].resize(unique(x[i].begin(),x[i].end())-x[i].begin()); D[i].resize(x[i].size(),0x7fffffff); } for(int i=0;i<x[N-1].size();i++) solve(N-1,i); for(cin>>M;M--;) { int L; cin>>L; L=upper_bound(x[N-1].begin(),x[N-1].end(),L)-x[N-1].begin()-1; if(L==-1 || D[N-1][L]==-1) cout<<"-1\n"; else cout<<D[N-1][L]<<'\n'; } return 0; }

Compilation message (stderr)

bus.cpp: In function 'int solve(int, int)':
bus.cpp:22:95: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=lower_bound(adj[c].begin(),adj[c].end(),make_tuple(x[c][t],-1,-1))-adj[c].begin();i<adj[c].size() && get<0>(adj[c][i])==x[c][t];i++) {
                                                                                              ~^~~~~~~~~~~~~~
bus.cpp: In function 'int main()':
bus.cpp:52:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<x[N-1].size();i++) solve(N-1,i);
              ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...