Submission #370708

# Submission time Handle Problem Language Result Execution time Memory
370708 2021-02-24T13:46:55 Z hackxsaras Dreaming (IOI13_dreaming) C++14
47 / 100
117 ms 20192 KB
#include "bits/stdc++.h"
#include "dreaming.h"
// #include "chrono"
// #define int long long
using namespace std;
// using namespace std::chrono; 
 
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define pb push_back
#define galen_colin {ios_base::sync_with_stdio(false);}
#define orz {cin.tie(NULL); cout.tie(NULL);}
#define fix(prec) {cout << setprecision(prec) << fixed;}
#define mp make_pair
#define f first
#define s second
#define all(v) v.begin(), v.end()
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
 
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
    cout << ""; for(int i = 0; i < v.size(); i++) {if (i) cout << " "; cout << v[i];} return cout << "\n";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
    cin >> p.first;
    return cin >> p.second;
}
template<typename A> istream& operator>>(istream& cin, vector<A> &v) {
    for(auto &x:v)cin>>x;
    return cin;
}
 
// ll min(ll a, int b){return min(a, (ll) b);}
// ll min(int a, ll b){return min(b, (ll) a);}
// ll max(ll a, int b){return max(a, (ll) b);}
// ll max(int a, ll b){return max(b, (ll) a);}
 
void usaco(string filename) {
  // #pragma message("be careful, freopen may be wrong")
    freopen((filename + ".in").c_str(), "r", stdin);
    freopen((filename + ".out").c_str(), "w", stdout);
}
 
const ld pi = 3.14159265358979323846;
const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;
const ll INF = 1e9+7;
 
 
 
ll n, m, k, q, l, r, x, y, z;
 
const ll sz = 1e5 + 1;
string s, t;
ll ans = 0, gc = 0;
 
vector<pair<ll,ll>> far;
vector<ll> full, half;
vpl adj[sz];
vl path, vis(sz);
 
void getccs(int no, int dep){
    vis[no]=1;
    
    if(dep>far[gc].second){
        far[gc]=make_pair(no,dep);
    }
    for(auto i:adj[no]){
        if(!vis[i.f]){
            getccs(i.f,dep+i.s);
        }
    }
    
}
//the max.....in this cc
//if sum > anything else up till now, but say there are only two edges we can't do better ig
 
ll binary_searc(vl& v){
    ll halfdiff = v.back()/2;
    ll l=0, r = v.size()-1;
    ll ret = v.back();
    while(l<=r){
        ll m = (l+r)/2;
        if(max(v.back() - v[m], v[m]) < ret){
            ret = max(v.back() - v[m], v[m]);
        }
        if(v[m] < v.back() - v[m]){
            l = m+1;
        } else {
            r = m-1;
        }
    }
    return ret;
}
void farfar(ll no, ll dep){
    
    vis[no]=1;
    
    path.push_back(dep);
 
    full[gc] = max(full[gc], path.back());
    half[gc] = max(half[gc], binary_searc(path));
 
    for(auto i:adj[no]){
        if(!vis[i.f]){
            farfar(i.f, dep + i.s);
        }
    }
    path.pop_back();
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for(int i=0;i<M;i++){
        adj[A[i]].pb({B[i], T[i]});
        adj[B[i]].pb({A[i], T[i]});
    }
 
    n = N;
    for(int i=0;i<n;i++){
 
        if(!vis[i]){
            far.push_back(make_pair(-1,-1));
            getccs(i,0);
            gc++;
        }
    }
 
    gc=0;
 
    vis.clear();
    vis.resize(sz, 0);
    //aare yrr, notanki
    if(far.size() == n){
        return (N-1)*L;
    }
    for(int i=0;i<far.size();i++){
        full.pb(0), half.pb(0);
        farfar(far[i].first, 0);
        gc++;
    }
 
    
    sort(all(full));
    sort(all(half));
 
    ans = full.back();
    if(half.size() >= 2)
        ans = max(ans, half[half.size()-1] + half[half.size()-2] + L);
 
    return ans;
}
 
// int main() {
//     int N,M,L;
//     cin>>N>>M>>L;
//     int A[M], B[M], T[M];
//     for(int i=0;i<M;i++)cin>>A[i]>>B[i]>>T[i];
//     cout<< travelTime(N, M, L, A, B, T);
// } 
 
/*
 
12 8 2
0 8 4
8 2 2
2 7 4
5 11 3
5 1 7
1 3 1
1 9 5
10 6 3 
 
*/

Compilation message

dreaming.cpp: In function 'll binary_searc(vl&)':
dreaming.cpp:97:8: warning: unused variable 'halfdiff' [-Wunused-variable]
   97 |     ll halfdiff = v.back()/2;
      |        ^~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:150:19: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
  150 |     if(far.size() == n){
      |        ~~~~~~~~~~~^~~~
dreaming.cpp:153:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  153 |     for(int i=0;i<far.size();i++){
      |                 ~^~~~~~~~~~~
dreaming.cpp: In function 'void usaco(std::string)':
dreaming.cpp:57:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   57 |     freopen((filename + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dreaming.cpp:58:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   58 |     freopen((filename + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 68 ms 18144 KB Output is correct
2 Correct 65 ms 18016 KB Output is correct
3 Correct 43 ms 13156 KB Output is correct
4 Correct 11 ms 5740 KB Output is correct
5 Correct 10 ms 4992 KB Output is correct
6 Correct 17 ms 7016 KB Output is correct
7 Correct 3 ms 3564 KB Output is correct
8 Correct 40 ms 8828 KB Output is correct
9 Correct 44 ms 10984 KB Output is correct
10 Correct 3 ms 3564 KB Output is correct
11 Correct 82 ms 13284 KB Output is correct
12 Correct 109 ms 15972 KB Output is correct
13 Correct 4 ms 3564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3436 KB Output is correct
2 Correct 3 ms 3584 KB Output is correct
3 Correct 3 ms 3436 KB Output is correct
4 Correct 3 ms 3436 KB Output is correct
5 Correct 3 ms 3436 KB Output is correct
6 Correct 3 ms 3436 KB Output is correct
7 Correct 3 ms 3436 KB Output is correct
8 Correct 3 ms 3436 KB Output is correct
9 Correct 3 ms 3436 KB Output is correct
10 Correct 3 ms 3436 KB Output is correct
11 Correct 3 ms 3436 KB Output is correct
12 Correct 3 ms 3564 KB Output is correct
13 Correct 4 ms 3436 KB Output is correct
14 Correct 3 ms 3436 KB Output is correct
15 Correct 3 ms 3436 KB Output is correct
16 Correct 3 ms 3436 KB Output is correct
17 Correct 3 ms 3436 KB Output is correct
18 Correct 3 ms 3436 KB Output is correct
19 Correct 3 ms 3436 KB Output is correct
20 Correct 3 ms 3436 KB Output is correct
21 Correct 3 ms 3436 KB Output is correct
22 Correct 3 ms 3584 KB Output is correct
23 Correct 3 ms 3436 KB Output is correct
24 Correct 3 ms 3436 KB Output is correct
25 Correct 3 ms 3436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 18144 KB Output is correct
2 Correct 65 ms 18016 KB Output is correct
3 Correct 43 ms 13156 KB Output is correct
4 Correct 11 ms 5740 KB Output is correct
5 Correct 10 ms 4992 KB Output is correct
6 Correct 17 ms 7016 KB Output is correct
7 Correct 3 ms 3564 KB Output is correct
8 Correct 40 ms 8828 KB Output is correct
9 Correct 44 ms 10984 KB Output is correct
10 Correct 3 ms 3564 KB Output is correct
11 Correct 82 ms 13284 KB Output is correct
12 Correct 109 ms 15972 KB Output is correct
13 Correct 4 ms 3564 KB Output is correct
14 Correct 3 ms 3436 KB Output is correct
15 Correct 3 ms 3584 KB Output is correct
16 Correct 3 ms 3436 KB Output is correct
17 Correct 3 ms 3436 KB Output is correct
18 Correct 3 ms 3436 KB Output is correct
19 Correct 3 ms 3436 KB Output is correct
20 Correct 3 ms 3436 KB Output is correct
21 Correct 3 ms 3436 KB Output is correct
22 Correct 3 ms 3436 KB Output is correct
23 Correct 3 ms 3436 KB Output is correct
24 Correct 3 ms 3436 KB Output is correct
25 Correct 3 ms 3564 KB Output is correct
26 Correct 4 ms 3436 KB Output is correct
27 Correct 3 ms 3436 KB Output is correct
28 Correct 3 ms 3436 KB Output is correct
29 Correct 3 ms 3436 KB Output is correct
30 Correct 3 ms 3436 KB Output is correct
31 Correct 3 ms 3436 KB Output is correct
32 Correct 3 ms 3436 KB Output is correct
33 Correct 3 ms 3436 KB Output is correct
34 Correct 3 ms 3436 KB Output is correct
35 Correct 3 ms 3584 KB Output is correct
36 Correct 3 ms 3436 KB Output is correct
37 Correct 3 ms 3436 KB Output is correct
38 Correct 3 ms 3436 KB Output is correct
39 Correct 63 ms 18016 KB Output is correct
40 Correct 66 ms 18016 KB Output is correct
41 Correct 48 ms 13156 KB Output is correct
42 Correct 10 ms 5740 KB Output is correct
43 Correct 3 ms 3436 KB Output is correct
44 Correct 3 ms 3436 KB Output is correct
45 Correct 3 ms 3436 KB Output is correct
46 Correct 3 ms 3436 KB Output is correct
47 Correct 3 ms 3436 KB Output is correct
48 Correct 3 ms 3436 KB Output is correct
49 Correct 3 ms 3436 KB Output is correct
50 Correct 3 ms 3436 KB Output is correct
51 Correct 3 ms 3436 KB Output is correct
52 Correct 3 ms 3436 KB Output is correct
53 Correct 3 ms 3436 KB Output is correct
54 Correct 3 ms 3436 KB Output is correct
55 Correct 3 ms 3436 KB Output is correct
56 Correct 3 ms 3436 KB Output is correct
57 Correct 94 ms 11884 KB Output is correct
58 Correct 102 ms 11884 KB Output is correct
59 Correct 99 ms 11628 KB Output is correct
60 Correct 97 ms 11628 KB Output is correct
61 Correct 89 ms 11628 KB Output is correct
62 Correct 92 ms 11660 KB Output is correct
63 Correct 84 ms 11116 KB Output is correct
64 Correct 93 ms 11244 KB Output is correct
65 Correct 94 ms 11372 KB Output is correct
66 Correct 88 ms 11628 KB Output is correct
67 Correct 93 ms 11628 KB Output is correct
68 Correct 112 ms 11756 KB Output is correct
69 Correct 100 ms 12012 KB Output is correct
70 Correct 98 ms 11884 KB Output is correct
71 Correct 3 ms 3436 KB Output is correct
72 Correct 4 ms 3692 KB Output is correct
73 Correct 5 ms 3692 KB Output is correct
74 Correct 4 ms 3692 KB Output is correct
75 Correct 4 ms 3692 KB Output is correct
76 Correct 4 ms 3692 KB Output is correct
77 Correct 5 ms 3692 KB Output is correct
78 Correct 4 ms 3692 KB Output is correct
79 Correct 4 ms 3692 KB Output is correct
80 Correct 93 ms 11652 KB Output is correct
81 Correct 106 ms 11628 KB Output is correct
82 Correct 102 ms 11628 KB Output is correct
83 Correct 95 ms 11628 KB Output is correct
84 Correct 4 ms 3692 KB Output is correct
85 Correct 4 ms 3564 KB Output is correct
86 Correct 4 ms 3652 KB Output is correct
87 Correct 5 ms 3692 KB Output is correct
88 Correct 4 ms 3692 KB Output is correct
89 Correct 4 ms 3692 KB Output is correct
90 Correct 4 ms 3692 KB Output is correct
91 Correct 4 ms 3692 KB Output is correct
92 Correct 5 ms 3692 KB Output is correct
93 Correct 4 ms 3692 KB Output is correct
94 Correct 3 ms 3436 KB Output is correct
95 Correct 3 ms 3584 KB Output is correct
96 Correct 3 ms 3436 KB Output is correct
97 Correct 3 ms 3436 KB Output is correct
98 Correct 3 ms 3436 KB Output is correct
99 Correct 3 ms 3436 KB Output is correct
100 Correct 3 ms 3436 KB Output is correct
101 Correct 3 ms 3436 KB Output is correct
102 Correct 3 ms 3436 KB Output is correct
103 Correct 3 ms 3564 KB Output is correct
104 Correct 11 ms 4844 KB Output is correct
105 Correct 16 ms 6888 KB Output is correct
106 Correct 3 ms 3564 KB Output is correct
107 Correct 32 ms 8816 KB Output is correct
108 Correct 49 ms 10984 KB Output is correct
109 Correct 4 ms 3564 KB Output is correct
110 Correct 73 ms 13412 KB Output is correct
111 Correct 83 ms 16100 KB Output is correct
112 Correct 3 ms 3564 KB Output is correct
113 Correct 117 ms 20192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 8512 KB Output is correct
2 Incorrect 36 ms 8548 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3436 KB Output is correct
2 Correct 3 ms 3584 KB Output is correct
3 Correct 3 ms 3436 KB Output is correct
4 Correct 3 ms 3436 KB Output is correct
5 Correct 3 ms 3436 KB Output is correct
6 Correct 3 ms 3436 KB Output is correct
7 Correct 3 ms 3436 KB Output is correct
8 Correct 3 ms 3436 KB Output is correct
9 Correct 3 ms 3436 KB Output is correct
10 Correct 3 ms 3436 KB Output is correct
11 Correct 3 ms 3436 KB Output is correct
12 Correct 3 ms 3564 KB Output is correct
13 Correct 4 ms 3436 KB Output is correct
14 Correct 3 ms 3436 KB Output is correct
15 Correct 3 ms 3436 KB Output is correct
16 Correct 3 ms 3436 KB Output is correct
17 Correct 3 ms 3436 KB Output is correct
18 Correct 3 ms 3436 KB Output is correct
19 Correct 3 ms 3436 KB Output is correct
20 Correct 3 ms 3436 KB Output is correct
21 Correct 3 ms 3436 KB Output is correct
22 Correct 3 ms 3584 KB Output is correct
23 Correct 3 ms 3436 KB Output is correct
24 Correct 3 ms 3436 KB Output is correct
25 Correct 3 ms 3436 KB Output is correct
26 Correct 3 ms 3564 KB Output is correct
27 Correct 4 ms 3596 KB Output is correct
28 Correct 4 ms 3692 KB Output is correct
29 Correct 3 ms 3564 KB Output is correct
30 Correct 4 ms 3700 KB Output is correct
31 Correct 4 ms 3692 KB Output is correct
32 Incorrect 3 ms 3712 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 68 ms 18144 KB Output is correct
2 Correct 65 ms 18016 KB Output is correct
3 Correct 43 ms 13156 KB Output is correct
4 Correct 11 ms 5740 KB Output is correct
5 Correct 10 ms 4992 KB Output is correct
6 Correct 17 ms 7016 KB Output is correct
7 Correct 3 ms 3564 KB Output is correct
8 Correct 40 ms 8828 KB Output is correct
9 Correct 44 ms 10984 KB Output is correct
10 Correct 3 ms 3564 KB Output is correct
11 Correct 82 ms 13284 KB Output is correct
12 Correct 109 ms 15972 KB Output is correct
13 Correct 4 ms 3564 KB Output is correct
14 Correct 3 ms 3436 KB Output is correct
15 Correct 3 ms 3584 KB Output is correct
16 Correct 3 ms 3436 KB Output is correct
17 Correct 3 ms 3436 KB Output is correct
18 Correct 3 ms 3436 KB Output is correct
19 Correct 3 ms 3436 KB Output is correct
20 Correct 3 ms 3436 KB Output is correct
21 Correct 3 ms 3436 KB Output is correct
22 Correct 3 ms 3436 KB Output is correct
23 Correct 3 ms 3436 KB Output is correct
24 Correct 3 ms 3436 KB Output is correct
25 Correct 3 ms 3564 KB Output is correct
26 Correct 4 ms 3436 KB Output is correct
27 Correct 3 ms 3436 KB Output is correct
28 Correct 3 ms 3436 KB Output is correct
29 Correct 3 ms 3436 KB Output is correct
30 Correct 3 ms 3436 KB Output is correct
31 Correct 3 ms 3436 KB Output is correct
32 Correct 3 ms 3436 KB Output is correct
33 Correct 3 ms 3436 KB Output is correct
34 Correct 3 ms 3436 KB Output is correct
35 Correct 3 ms 3584 KB Output is correct
36 Correct 3 ms 3436 KB Output is correct
37 Correct 3 ms 3436 KB Output is correct
38 Correct 3 ms 3436 KB Output is correct
39 Correct 63 ms 18016 KB Output is correct
40 Correct 66 ms 18016 KB Output is correct
41 Correct 48 ms 13156 KB Output is correct
42 Correct 10 ms 5740 KB Output is correct
43 Correct 3 ms 3436 KB Output is correct
44 Correct 3 ms 3436 KB Output is correct
45 Correct 3 ms 3436 KB Output is correct
46 Correct 3 ms 3436 KB Output is correct
47 Correct 3 ms 3436 KB Output is correct
48 Correct 3 ms 3436 KB Output is correct
49 Correct 3 ms 3436 KB Output is correct
50 Correct 3 ms 3436 KB Output is correct
51 Correct 3 ms 3436 KB Output is correct
52 Correct 3 ms 3436 KB Output is correct
53 Correct 3 ms 3436 KB Output is correct
54 Correct 3 ms 3436 KB Output is correct
55 Correct 3 ms 3436 KB Output is correct
56 Correct 3 ms 3436 KB Output is correct
57 Correct 94 ms 11884 KB Output is correct
58 Correct 102 ms 11884 KB Output is correct
59 Correct 99 ms 11628 KB Output is correct
60 Correct 97 ms 11628 KB Output is correct
61 Correct 89 ms 11628 KB Output is correct
62 Correct 92 ms 11660 KB Output is correct
63 Correct 84 ms 11116 KB Output is correct
64 Correct 93 ms 11244 KB Output is correct
65 Correct 94 ms 11372 KB Output is correct
66 Correct 88 ms 11628 KB Output is correct
67 Correct 93 ms 11628 KB Output is correct
68 Correct 112 ms 11756 KB Output is correct
69 Correct 100 ms 12012 KB Output is correct
70 Correct 98 ms 11884 KB Output is correct
71 Correct 3 ms 3436 KB Output is correct
72 Correct 4 ms 3692 KB Output is correct
73 Correct 5 ms 3692 KB Output is correct
74 Correct 4 ms 3692 KB Output is correct
75 Correct 4 ms 3692 KB Output is correct
76 Correct 4 ms 3692 KB Output is correct
77 Correct 5 ms 3692 KB Output is correct
78 Correct 4 ms 3692 KB Output is correct
79 Correct 4 ms 3692 KB Output is correct
80 Correct 93 ms 11652 KB Output is correct
81 Correct 106 ms 11628 KB Output is correct
82 Correct 102 ms 11628 KB Output is correct
83 Correct 95 ms 11628 KB Output is correct
84 Correct 4 ms 3692 KB Output is correct
85 Correct 4 ms 3564 KB Output is correct
86 Correct 4 ms 3652 KB Output is correct
87 Correct 5 ms 3692 KB Output is correct
88 Correct 4 ms 3692 KB Output is correct
89 Correct 4 ms 3692 KB Output is correct
90 Correct 4 ms 3692 KB Output is correct
91 Correct 4 ms 3692 KB Output is correct
92 Correct 5 ms 3692 KB Output is correct
93 Correct 4 ms 3692 KB Output is correct
94 Correct 3 ms 3436 KB Output is correct
95 Correct 3 ms 3584 KB Output is correct
96 Correct 3 ms 3436 KB Output is correct
97 Correct 3 ms 3436 KB Output is correct
98 Correct 3 ms 3436 KB Output is correct
99 Correct 3 ms 3436 KB Output is correct
100 Correct 3 ms 3436 KB Output is correct
101 Correct 3 ms 3436 KB Output is correct
102 Correct 3 ms 3436 KB Output is correct
103 Correct 3 ms 3564 KB Output is correct
104 Correct 11 ms 4844 KB Output is correct
105 Correct 16 ms 6888 KB Output is correct
106 Correct 3 ms 3564 KB Output is correct
107 Correct 32 ms 8816 KB Output is correct
108 Correct 49 ms 10984 KB Output is correct
109 Correct 4 ms 3564 KB Output is correct
110 Correct 73 ms 13412 KB Output is correct
111 Correct 83 ms 16100 KB Output is correct
112 Correct 3 ms 3564 KB Output is correct
113 Correct 117 ms 20192 KB Output is correct
114 Correct 38 ms 8512 KB Output is correct
115 Incorrect 36 ms 8548 KB Output isn't correct
116 Halted 0 ms 0 KB -