답안 #1017508

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017508 2024-07-09T08:33:34 Z bachhoangxuan Giraffes (JOI22_giraffes) C++17
100 / 100
1698 ms 1436 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 8005;
const int S = 600;
int n,p[maxn],s[maxn][4];

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> p[i];
        s[i][0]=min(n-i,n-p[i]);
        s[i][1]=min(i-1,n-p[i]);
        s[i][2]=min(n-i,p[i]-1);
        s[i][3]=min(i-1,p[i]-1);
    }
    int k=0;
    while(true){
        vector<array<int,3>> sq;
        for(int i=1;i<=n;i++) for(int j=0;j<=3;j++) if(s[i][j]!=-1) sq.push_back({-s[i][j],i,j}),s[i][j]=-1;
        if(sq.empty()) break;
        sort(sq.begin(),sq.end());
        if((int)sq.size()>S) sq.erase(sq.begin()+S,sq.end());
        for(auto [d,i,j]:sq){
            d=-d;
            int x=-1,y=-1,u=-1,v=-1;
            if(j&1) x=i-d,u=i-1;
            else x=i+1,u=i+d;
            if(j&2) y=p[i]-d,v=p[i]-1;
            else y=p[i]+1,v=p[i]+d;
            for(int t=x;t<=u;t++){
                if(p[t]<y || p[t]>v) continue;
                s[t][0]=max(s[t][0],min(u-t,v-p[t]));
                s[t][1]=max(s[t][1],min(t-x,v-p[t]));
                s[t][2]=max(s[t][2],min(u-t,p[t]-y));
                s[t][3]=max(s[t][3],min(t-x,p[t]-y));
            }
        }
        k++;
    }
    cout << n-k << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 4 ms 344 KB Output is correct
24 Correct 7 ms 348 KB Output is correct
25 Correct 8 ms 348 KB Output is correct
26 Correct 8 ms 508 KB Output is correct
27 Correct 9 ms 348 KB Output is correct
28 Correct 9 ms 348 KB Output is correct
29 Correct 9 ms 348 KB Output is correct
30 Correct 9 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 4 ms 344 KB Output is correct
24 Correct 7 ms 348 KB Output is correct
25 Correct 8 ms 348 KB Output is correct
26 Correct 8 ms 508 KB Output is correct
27 Correct 9 ms 348 KB Output is correct
28 Correct 9 ms 348 KB Output is correct
29 Correct 9 ms 348 KB Output is correct
30 Correct 9 ms 508 KB Output is correct
31 Correct 228 ms 828 KB Output is correct
32 Correct 976 ms 1224 KB Output is correct
33 Correct 1575 ms 1380 KB Output is correct
34 Correct 1660 ms 1404 KB Output is correct
35 Correct 1600 ms 1436 KB Output is correct
36 Correct 1684 ms 1384 KB Output is correct
37 Correct 1652 ms 1380 KB Output is correct
38 Correct 1698 ms 1376 KB Output is correct
39 Correct 1606 ms 1368 KB Output is correct
40 Correct 1676 ms 1436 KB Output is correct