QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#279663#7849. Journey of Recoverybachbeo2007AC ✓375ms112380kbC++233.5kb2023-12-08 22:57:552023-12-08 22:57:56

Judging History

你现在查看的是最新测评结果

  • [2023-12-08 22:57:56]
  • 评测
  • 测评结果:AC
  • 用时:375ms
  • 内存:112380kb
  • [2023-12-08 22:57:55]
  • 提交

answer

// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<pii,int>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int maxn=1000005;
const int bl=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=25;
const int maxa=1000000;
const int root=3;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
const int iroot=power(3,mod-2);
const int base=101;

int n,m,st[maxn],tt[maxn],Max[maxn];
vector<pii> edge[maxn];
int N,dist[maxn];
string sa[maxn],sb[maxn];
map<string,int> mp;

int get(string D){
    int cur=0,res=0;
    for(char c:D){
        if(c=='d'){
            res+=cur*1440;
            cur=0;
        }
        else if(c==':'){
            res+=cur*60;
            cur=0;
        }
        else cur=cur*10+c-'0';
    }
    res+=cur;
    return res;
}

void solve(){
    cin >> n;
    for(int i=1;i<=n;i++){
        string a,b,s,t;cin >> a >> s >> b >> t;
        sa[i]=a;sb[i]=b;
        if(mp.find(a)==mp.end()) mp[a]=++N;
        if(mp.find(b)==mp.end()) mp[b]=++N;
        st[i]=get(s)*2+1;tt[i]=get(t)*2;
        int xa=mp[a],xb=mp[b];
        edge[xb].push_back({xa,i});
    }
    cin >> m;
    int lst=0,T=-1;
    for(int i=1;i<=m;i++){
        int id;cin >> id;
        int ss=mp[sa[id]];
        Max[ss]=max(Max[ss],st[id]);
        st[id]--;
        lst=tt[id];
        T=mp[sb[id]];
    }
    auto check = [&](int x){
        for(int i=1;i<=N;i++) dist[i]=0;
        dist[T]=x;
        priority_queue<pii> pq;
        pq.push({x,T});
        while(!pq.empty()){
            auto [d,u]=pq.top();pq.pop();
            if(dist[u]!=d) continue;
            for(auto [v,id]:edge[u]){
                if(d<tt[id]) continue;
                if(st[id]>dist[v]){
                    dist[v]=st[id];
                    pq.push({st[id],v});
                }
            }
        }
        for(int i=1;i<=N;i++){
            if(dist[i]<Max[i]) return false;
        }
        return true;
    };
    int l=0,r=1050000,res=r;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid)) res=mid,r=mid-1;
        else l=mid+1;
    }
    if(res==1050000) cout << "stranded\n";
    else cout << max(res-lst,0LL)/2 << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 92152kb

input:

8
egnx 0d00:10 delft 0d01:00
delft 0d01:00 zad 0d09:00
zad 0d09:01 prg 0d15:30
prg 0d20:00 delft 1d02:15
prg 0d22:00 delft 1d04:15
zad 2d00:00 delft 3d00:00
egnx 2d00:00 delft 2d02:00
egnx 2d00:00 delft 2d02:00
4
1 2 3 4

output:

2745

result:

ok single line: '2745'

Test #2:

score: 0
Accepted
time: 8ms
memory: 92628kb

input:

3
ork 101d00:00 noc 101d00:01
ork 100d23:59 noc 101d00:02
dub 100d00:00 ork 101d00:00
2
3 1

output:

stranded

result:

ok single line: 'stranded'

Test #3:

score: 0
Accepted
time: 13ms
memory: 91428kb

input:

2
lax 0d00:30 hnl 0d06:20
lax 0d00:30 hnl 0d06:20
1
2

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 8ms
memory: 91144kb

input:

20
baa 0d00:31 bab 0d00:32
baa 0d00:15 bab 0d00:53
baa 0d00:44 bab 0d00:47
baa 0d00:11 bab 0d00:42
baa 0d00:15 bab 0d00:27
baa 0d00:19 bab 0d00:20
baa 0d00:16 bab 0d00:40
baa 0d00:07 bab 0d00:54
baa 0d00:25 bab 0d00:44
baa 0d00:32 bab 0d00:42
bab 0d00:56 bac 0d01:17
bab 0d01:10 bac 0d01:20
bab 0d01:...

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 11ms
memory: 93036kb

input:

90
baa 0d00:06 bab 0d00:37
baa 0d00:49 bab 0d00:52
baa 0d00:05 bab 0d00:27
baa 0d00:26 bab 0d00:27
baa 0d00:03 bab 0d00:36
baa 0d00:23 bab 0d00:31
baa 0d00:01 bab 0d00:55
baa 0d00:39 bab 0d00:42
baa 0d00:28 bab 0d00:44
baa 0d00:04 bab 0d00:38
bab 0d01:20 bac 0d01:35
bab 0d01:45 bac 0d01:52
bab 0d01:...

output:

21

result:

ok single line: '21'

Test #6:

score: 0
Accepted
time: 3ms
memory: 91904kb

input:

7
bac 3d00:06 bab 39d22:17
bab 74d04:02 baa 81d19:39
baa 12d18:01 bab 86d01:31
baa 48d07:23 bac 67d05:42
bac 34d21:56 bab 50d08:26
bac 0d05:31 baa 1d05:40
bac 0d01:38 baa 0d15:10
1
7

output:

870

result:

ok single line: '870'

Test #7:

score: 0
Accepted
time: 13ms
memory: 91376kb

input:

17
bac 74d16:04 bae 98d19:52
bad 8d22:44 bab 12d05:58
bac 13d19:03 bae 77d05:09
baa 65d12:55 bad 98d21:21
baa 44d00:55 bae 85d14:23
bab 16d16:49 baa 82d09:17
bac 22d11:24 baa 56d11:42
bad 52d19:22 bab 95d14:48
bac 87d05:01 bae 99d06:27
bad 11d00:59 bae 40d23:57
bad 49d23:49 bac 51d04:56
bab 87d16:37...

output:

121500

result:

ok single line: '121500'

Test #8:

score: 0
Accepted
time: 5ms
memory: 91208kb

input:

1292
bda 27d03:01 bbh 84d17:32
bdd 29d08:34 bdg 79d12:41
beb 58d02:11 bdh 83d03:09
bcd 25d22:40 bdj 54d04:08
bbf 61d05:55 bbi 66d03:11
bbf 55d17:45 bcj 69d08:21
bcf 77d08:04 bea 97d14:00
bah 67d00:16 bbc 68d00:51
bdj 33d00:22 bcd 78d09:32
bej 33d00:36 beb 74d23:07
bee 44d05:33 bdc 54d14:34
bbc 11d04...

output:

stranded

result:

ok single line: 'stranded'

Test #9:

score: 0
Accepted
time: 15ms
memory: 93032kb

input:

5084
bfi 30d16:18 bhb 53d00:34
bhb 13d00:48 bee 35d05:13
bdf 31d15:19 bda 51d18:11
bgi 85d12:26 bjj 87d17:41
bdi 81d19:03 bdf 97d21:24
bbj 35d13:39 bda 57d08:21
bbf 9d01:40 baj 91d13:52
bhc 30d03:05 bfd 96d00:19
bbh 82d22:44 bbd 91d21:34
bhe 18d20:16 bje 85d17:38
bad 45d03:58 bag 98d00:20
bba 33d04:...

output:

71921

result:

ok single line: '71921'

Test #10:

score: 0
Accepted
time: 375ms
memory: 112380kb

input:

500834
gfg 51d23:48 jhh 90d07:46
iee 39d21:18 cga 71d19:14
dha 86d16:25 hih 97d06:29
gef 20d02:03 djj 90d15:23
bgb 12d20:08 bjc 15d23:38
cgc 17d02:37 ede 94d06:39
cjj 47d10:47 fbb 93d23:36
cjf 61d20:43 hba 74d15:30
ibe 27d14:46 ice 57d22:24
cgj 57d08:11 hdc 63d17:09
hcj 28d08:25 ghe 51d14:40
hcf 33d...

output:

stranded

result:

ok single line: 'stranded'

Test #11:

score: 0
Accepted
time: 15ms
memory: 92220kb

input:

9990
baa 0d00:49 bab 0d00:51
baa 0d00:35 bab 0d00:36
baa 0d00:20 bab 0d00:34
baa 0d00:01 bab 0d00:03
baa 0d00:35 bab 0d00:41
baa 0d00:30 bab 0d00:43
baa 0d00:09 bab 0d00:59
baa 0d00:12 bab 0d00:42
baa 0d00:10 bab 0d00:27
baa 0d00:43 bab 0d00:44
bab 0d00:26 bac 0d00:46
bab 0d00:41 bac 0d00:58
bab 0d0...

output:

stranded

result:

ok single line: 'stranded'

Test #12:

score: 0
Accepted
time: 79ms
memory: 97872kb

input:

99990
baa 0d00:07 bab 0d00:23
baa 0d00:45 bab 0d00:47
baa 0d00:07 bab 0d00:42
baa 0d00:04 bab 0d00:32
baa 0d00:15 bab 0d00:46
baa 0d00:14 bab 0d00:40
baa 0d00:10 bab 0d00:29
baa 0d00:01 bab 0d00:45
baa 0d00:18 bab 0d00:22
baa 0d00:06 bab 0d00:45
bab 0d00:45 bac 0d01:01
bab 0d00:59 bac 0d01:05
bab 0d...

output:

stranded

result:

ok single line: 'stranded'