답안 #1077021

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077021 2024-08-26T20:57:56 Z lucri Tortoise (CEOI21_tortoise) C++17
73 / 100
3000 ms 17640 KB
#include <bits/stdc++.h>
using namespace std;
long long cost,n,v[1000020],l[1000020],r[1000020],jump[1000020],nr;
priority_queue<pair<int,int>>q;
bool candy(int time,int poz)
{
    bool ok=false;
    for(int i=poz;v[i]!=-1;++i)
        if(v[i]||jump[i])
            ok=true;
    if(ok==false)
        return true;
    for(int i=poz;v[i]!=-1;++i)
        if(v[i]&&time+i-poz<=(i-1)*2)
            return true;
    return false;
}
bool ok()
{
    int time=0;
    if(candy(0,1)==false)
        return false;
    time=r[1]-1;
    for(int i=1;i<=n;++i)
    {
        if(v[i]==-1)
        {
            if(v[i-1]==-1)
                ++time;
            continue;
        }
        if(r[i]-i==i-l[i]||r[i]-i==(i-1)-l[i])
        {
            if(candy(time-(i-1-l[i])+1,l[i]+1)==false)
                return false;
            time+=r[i]-(i-1);
        }
        if(r[i]-i<=i-l[i])
        {
            for(int j=1;j<=jump[i];++j)
            {
                if(time+r[i]-i>2*(i-1))
                    return false;
                time+=2*(r[i]-i);
            }
        }
        else
        {
            ++time;
            for(int j=1;j<=jump[i];++j)
            {
                if(time>2*(i-1))
                    return false;
                time+=2*(i-l[i]);
            }
        }
    }
    if(candy(time-(n-l[n])+1,l[n]+1)==false)
        return false;
    return true;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;++i)
        cin>>v[i];
    v[1000010]=-1;
    l[0]=-1000010;
    r[n+1]=1000010;
    for(int i=1;i<=n;++i)
    {
        l[i]=l[i-1];
        if(v[i]==-1)
            l[i]=i;
    }
    for(int i=n;i>=1;--i)
    {
        r[i]=r[i+1];
        if(v[i]==-1)
            r[i]=i;
    }
    for(int i=1;i<=n;++i)
        q.push({-min(r[i]-i,i-l[i]),i});
    while(!q.empty())
    {
        int ind=q.top().second;
        q.pop();
        if(v[ind]==-1)
            continue;
        while(v[ind])
        {
            --v[ind];
            ++jump[ind];
            if(ok()==false)
            {
                ++v[ind];
                --jump[ind];
                break;
            }
        }
    }
    for(int i=1;i<=1000010;++i)
        if(v[i]!=-1)
            nr+=v[i];
        else
        {
            if(nr)
                --cost;
            nr=0;
        }
    for(int i=1;i<=n;++i)
        if(v[i]!=-1)
            cost+=v[i];
    cout<<cost;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 3 ms 508 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 3 ms 344 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 3 ms 516 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 3 ms 508 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 3 ms 344 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 3 ms 516 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 36 ms 348 KB Output is correct
28 Correct 44 ms 344 KB Output is correct
29 Correct 35 ms 344 KB Output is correct
30 Correct 29 ms 532 KB Output is correct
31 Correct 32 ms 348 KB Output is correct
32 Correct 22 ms 344 KB Output is correct
33 Correct 35 ms 348 KB Output is correct
34 Correct 28 ms 348 KB Output is correct
35 Correct 26 ms 344 KB Output is correct
36 Correct 25 ms 344 KB Output is correct
37 Correct 28 ms 348 KB Output is correct
38 Correct 31 ms 344 KB Output is correct
39 Correct 30 ms 348 KB Output is correct
40 Correct 24 ms 600 KB Output is correct
41 Correct 23 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 3 ms 508 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 3 ms 344 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 3 ms 516 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 36 ms 348 KB Output is correct
28 Correct 44 ms 344 KB Output is correct
29 Correct 35 ms 344 KB Output is correct
30 Correct 29 ms 532 KB Output is correct
31 Correct 32 ms 348 KB Output is correct
32 Correct 22 ms 344 KB Output is correct
33 Correct 35 ms 348 KB Output is correct
34 Correct 28 ms 348 KB Output is correct
35 Correct 26 ms 344 KB Output is correct
36 Correct 25 ms 344 KB Output is correct
37 Correct 28 ms 348 KB Output is correct
38 Correct 31 ms 344 KB Output is correct
39 Correct 30 ms 348 KB Output is correct
40 Correct 24 ms 600 KB Output is correct
41 Correct 23 ms 344 KB Output is correct
42 Correct 20 ms 348 KB Output is correct
43 Correct 24 ms 348 KB Output is correct
44 Correct 33 ms 344 KB Output is correct
45 Correct 39 ms 348 KB Output is correct
46 Correct 15 ms 348 KB Output is correct
47 Correct 24 ms 528 KB Output is correct
48 Correct 35 ms 344 KB Output is correct
49 Correct 43 ms 348 KB Output is correct
50 Correct 67 ms 344 KB Output is correct
51 Correct 72 ms 348 KB Output is correct
52 Correct 50 ms 348 KB Output is correct
53 Correct 85 ms 344 KB Output is correct
54 Correct 133 ms 348 KB Output is correct
55 Correct 78 ms 344 KB Output is correct
56 Correct 5 ms 348 KB Output is correct
57 Correct 35 ms 348 KB Output is correct
58 Correct 50 ms 344 KB Output is correct
59 Correct 43 ms 348 KB Output is correct
60 Correct 64 ms 508 KB Output is correct
61 Correct 41 ms 344 KB Output is correct
62 Correct 46 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 3 ms 508 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 3 ms 344 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 3 ms 516 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 36 ms 348 KB Output is correct
28 Correct 44 ms 344 KB Output is correct
29 Correct 35 ms 344 KB Output is correct
30 Correct 29 ms 532 KB Output is correct
31 Correct 32 ms 348 KB Output is correct
32 Correct 22 ms 344 KB Output is correct
33 Correct 35 ms 348 KB Output is correct
34 Correct 28 ms 348 KB Output is correct
35 Correct 26 ms 344 KB Output is correct
36 Correct 25 ms 344 KB Output is correct
37 Correct 28 ms 348 KB Output is correct
38 Correct 31 ms 344 KB Output is correct
39 Correct 30 ms 348 KB Output is correct
40 Correct 24 ms 600 KB Output is correct
41 Correct 23 ms 344 KB Output is correct
42 Correct 20 ms 348 KB Output is correct
43 Correct 24 ms 348 KB Output is correct
44 Correct 33 ms 344 KB Output is correct
45 Correct 39 ms 348 KB Output is correct
46 Correct 15 ms 348 KB Output is correct
47 Correct 24 ms 528 KB Output is correct
48 Correct 35 ms 344 KB Output is correct
49 Correct 43 ms 348 KB Output is correct
50 Correct 67 ms 344 KB Output is correct
51 Correct 72 ms 348 KB Output is correct
52 Correct 50 ms 348 KB Output is correct
53 Correct 85 ms 344 KB Output is correct
54 Correct 133 ms 348 KB Output is correct
55 Correct 78 ms 344 KB Output is correct
56 Correct 5 ms 348 KB Output is correct
57 Correct 35 ms 348 KB Output is correct
58 Correct 50 ms 344 KB Output is correct
59 Correct 43 ms 348 KB Output is correct
60 Correct 64 ms 508 KB Output is correct
61 Correct 41 ms 344 KB Output is correct
62 Correct 46 ms 512 KB Output is correct
63 Correct 481 ms 604 KB Output is correct
64 Correct 1239 ms 604 KB Output is correct
65 Correct 776 ms 768 KB Output is correct
66 Correct 1022 ms 856 KB Output is correct
67 Correct 619 ms 600 KB Output is correct
68 Correct 965 ms 852 KB Output is correct
69 Correct 1012 ms 600 KB Output is correct
70 Correct 935 ms 600 KB Output is correct
71 Correct 1344 ms 748 KB Output is correct
72 Correct 1395 ms 736 KB Output is correct
73 Correct 1310 ms 604 KB Output is correct
74 Correct 1331 ms 604 KB Output is correct
75 Correct 7 ms 604 KB Output is correct
76 Correct 884 ms 744 KB Output is correct
77 Correct 848 ms 604 KB Output is correct
78 Correct 856 ms 748 KB Output is correct
79 Correct 872 ms 600 KB Output is correct
80 Correct 743 ms 848 KB Output is correct
81 Correct 823 ms 600 KB Output is correct
82 Correct 817 ms 736 KB Output is correct
83 Correct 1045 ms 848 KB Output is correct
84 Correct 1305 ms 744 KB Output is correct
85 Correct 1373 ms 600 KB Output is correct
86 Correct 1389 ms 604 KB Output is correct
87 Correct 1328 ms 740 KB Output is correct
88 Correct 1327 ms 752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 3 ms 508 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 3 ms 344 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 3 ms 516 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 36 ms 348 KB Output is correct
28 Correct 44 ms 344 KB Output is correct
29 Correct 35 ms 344 KB Output is correct
30 Correct 29 ms 532 KB Output is correct
31 Correct 32 ms 348 KB Output is correct
32 Correct 22 ms 344 KB Output is correct
33 Correct 35 ms 348 KB Output is correct
34 Correct 28 ms 348 KB Output is correct
35 Correct 26 ms 344 KB Output is correct
36 Correct 25 ms 344 KB Output is correct
37 Correct 28 ms 348 KB Output is correct
38 Correct 31 ms 344 KB Output is correct
39 Correct 30 ms 348 KB Output is correct
40 Correct 24 ms 600 KB Output is correct
41 Correct 23 ms 344 KB Output is correct
42 Correct 20 ms 348 KB Output is correct
43 Correct 24 ms 348 KB Output is correct
44 Correct 33 ms 344 KB Output is correct
45 Correct 39 ms 348 KB Output is correct
46 Correct 15 ms 348 KB Output is correct
47 Correct 24 ms 528 KB Output is correct
48 Correct 35 ms 344 KB Output is correct
49 Correct 43 ms 348 KB Output is correct
50 Correct 67 ms 344 KB Output is correct
51 Correct 72 ms 348 KB Output is correct
52 Correct 50 ms 348 KB Output is correct
53 Correct 85 ms 344 KB Output is correct
54 Correct 133 ms 348 KB Output is correct
55 Correct 78 ms 344 KB Output is correct
56 Correct 5 ms 348 KB Output is correct
57 Correct 35 ms 348 KB Output is correct
58 Correct 50 ms 344 KB Output is correct
59 Correct 43 ms 348 KB Output is correct
60 Correct 64 ms 508 KB Output is correct
61 Correct 41 ms 344 KB Output is correct
62 Correct 46 ms 512 KB Output is correct
63 Correct 481 ms 604 KB Output is correct
64 Correct 1239 ms 604 KB Output is correct
65 Correct 776 ms 768 KB Output is correct
66 Correct 1022 ms 856 KB Output is correct
67 Correct 619 ms 600 KB Output is correct
68 Correct 965 ms 852 KB Output is correct
69 Correct 1012 ms 600 KB Output is correct
70 Correct 935 ms 600 KB Output is correct
71 Correct 1344 ms 748 KB Output is correct
72 Correct 1395 ms 736 KB Output is correct
73 Correct 1310 ms 604 KB Output is correct
74 Correct 1331 ms 604 KB Output is correct
75 Correct 7 ms 604 KB Output is correct
76 Correct 884 ms 744 KB Output is correct
77 Correct 848 ms 604 KB Output is correct
78 Correct 856 ms 748 KB Output is correct
79 Correct 872 ms 600 KB Output is correct
80 Correct 743 ms 848 KB Output is correct
81 Correct 823 ms 600 KB Output is correct
82 Correct 817 ms 736 KB Output is correct
83 Correct 1045 ms 848 KB Output is correct
84 Correct 1305 ms 744 KB Output is correct
85 Correct 1373 ms 600 KB Output is correct
86 Correct 1389 ms 604 KB Output is correct
87 Correct 1328 ms 740 KB Output is correct
88 Correct 1327 ms 752 KB Output is correct
89 Execution timed out 3060 ms 17640 KB Time limit exceeded
90 Halted 0 ms 0 KB -