답안 #1114933

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114933 2024-11-19T19:58:37 Z AdamGS Collecting Stamps 3 (JOI20_ho_t3) C++17
0 / 100
1 ms 592 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Incorrect 1 ms 336 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Incorrect 1 ms 336 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Incorrect 1 ms 336 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Incorrect 1 ms 336 KB Output isn't correct
17 Halted 0 ms 0 KB -