제출 #1114933

#제출 시각아이디문제언어결과실행 시간메모리
1114933AdamGSCollecting Stamps 3 (JOI20_ho_t3)C++17
0 / 100
1 ms592 KiB
#include <iostream>
#include <math.h>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

struct State{
    int l, r, res, t, side;
    bool first;
};

int GetDiff(int a, int b, int l, int side){
    if ((a<b&&side==1)||(a>b&&side==-1)) return abs(a-b);
    if (a<b) return a+l-b;
    return b+l-a;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, l;
    cin>>n>>l;
    vector<int> positions(n), times(n);
    for (int i=0;i<n;i++) cin>>positions[i];
    for (int i=0;i<n;i++) cin>>times[i];
    queue<State> q;
    q.push({0, 0, (times[0]>=positions[0]?1:0), positions[0], 1, true});
    q.push({n-1, n-1, (times[n-1]>=l-positions[n-1]?1:0), l-positions[n-1], -1, true});
    int out=0;
    while (!q.empty()){
        State sta1=q.front();
        q.pop();
        if (sta1.res==n){
            cout<<n<<'\n';
            return 0;
        }
        out=max(out, sta1.res);
        if (sta1.t>l*2+1||(sta1.l==sta1.r&&!sta1.first)) continue;
        sta1.first=false;
        State sta2=sta1;
        int pos=(sta1.side==1?sta1.r:sta1.l);
        sta1.r++;
        sta1.r%=n;
        sta1.t+=GetDiff(positions[pos], positions[sta1.r], l, 1);
        if (times[sta1.r]>=sta1.t) sta1.res++;
        sta2.l--;
        if (sta2.l<0) sta2.l+=n;
        sta2.t+=GetDiff(positions[pos], positions[sta2.l], l, -1);
        if (times[sta2.l]>=sta2.t) sta2.res++;
        q.push(sta1);
        q.push(sta2);
    }
    cout<<out<<'\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...