Submission #73673

# Submission time Handle Problem Language Result Execution time Memory
73673 2018-08-28T17:13:22 Z MKopchev Ancient Books (IOI17_books) C++14
22 / 100
2000 ms 20324 KB
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e6+42;
int in[nmax],out[nmax];
long long minimum_walk(vector<int> p, int s)
{
    int n=p.size();
    while(n-1>s&&p[n-1]==n-1){p.pop_back();n--;}
    vector<int> help={};
    int where=0;
    for(where=0;where<s;where++)
    {
        if(p[where]!=where)break;
    }
    for(int i=where;i<n;i++)
        help.push_back(p[i]-where);
    p=help;
    n=p.size();

    if(n==0)return 0;

    help=p;
    sort(help.begin(),help.end());
    for(int i=0;i<n;i++)
        assert(help[i]==i);
    for(int i=0;i<n;i++)
        if(i!=p[i])
        {
            if(i<p[i])
            for(int j=i;j<p[i];j++)
                out[j]++,in[j+1]++;
            else
            for(int j=i;j>p[i];j--)
                out[j]++,in[j-1]++;
        }
    /*
    for(int i=0;i<n;i++)
        cout<<in[i]<<" "<<out[i]<<endl;
    */
    if(s==0)
    {

      int maxi=0;
      for(int i=0;i<n;i++)
      {
            maxi=max(maxi,p[i]);
            if(i==maxi)
            {
                if(i!=n-1)
                {
                    in[i]++;
                    out[i]++;
                    in[i+1]++;
                    out[i+1]++;
                }
                maxi=0;
            }
      }
    }
      for(int i=1;i<n;i++)
      {
            if(in[i-1]<out[i-1])
            {
                assert(0==1);
                out[i]+=out[i-1]-in[i-1];
                in[i-1]=out[i-1];
            }
            else if(in[i-1]>out[i-1])
            {
                assert(0==1);
                in[i]+=in[i-1]-out[i-1];
                out[i-1]=in[i-1];
            }
      }
      assert(in[n-1]==out[n-1]);
      long long ans=0;
      for(int i=0;i<n;i++)
      {
            ans=ans+in[i]+out[i];
      }
      return ans/2;
}
/*
int main()
{
//cout<<minimum_walk({0,2,1,3},2)<<endl;
//cout<<minimum_walk({0, 2, 3, 1}, 0)<<endl;
//cout<<minimum_walk({1,0,3,2}, 0)<<endl;
//cout<<minimum_walk({2,3,0,1}, 0)<<endl;
return 0;
}
*/
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Correct 2 ms 616 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 2 ms 616 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 2 ms 616 KB Output is correct
10 Correct 3 ms 616 KB Output is correct
11 Correct 2 ms 616 KB Output is correct
12 Correct 2 ms 616 KB Output is correct
13 Correct 3 ms 616 KB Output is correct
14 Correct 3 ms 616 KB Output is correct
15 Correct 3 ms 616 KB Output is correct
16 Correct 3 ms 616 KB Output is correct
17 Correct 2 ms 616 KB Output is correct
18 Correct 3 ms 616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Correct 2 ms 616 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 2 ms 616 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 2 ms 616 KB Output is correct
10 Correct 3 ms 616 KB Output is correct
11 Correct 2 ms 616 KB Output is correct
12 Correct 2 ms 616 KB Output is correct
13 Correct 3 ms 616 KB Output is correct
14 Correct 3 ms 616 KB Output is correct
15 Correct 3 ms 616 KB Output is correct
16 Correct 3 ms 616 KB Output is correct
17 Correct 2 ms 616 KB Output is correct
18 Correct 3 ms 616 KB Output is correct
19 Correct 3 ms 616 KB Output is correct
20 Correct 3 ms 616 KB Output is correct
21 Correct 2 ms 616 KB Output is correct
22 Correct 2 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 5 ms 620 KB Output is correct
25 Correct 2 ms 620 KB Output is correct
26 Correct 3 ms 620 KB Output is correct
27 Correct 2 ms 620 KB Output is correct
28 Correct 2 ms 620 KB Output is correct
29 Correct 2 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Correct 2 ms 616 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 2 ms 616 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 2 ms 616 KB Output is correct
10 Correct 3 ms 616 KB Output is correct
11 Correct 2 ms 616 KB Output is correct
12 Correct 2 ms 616 KB Output is correct
13 Correct 3 ms 616 KB Output is correct
14 Correct 3 ms 616 KB Output is correct
15 Correct 3 ms 616 KB Output is correct
16 Correct 3 ms 616 KB Output is correct
17 Correct 2 ms 616 KB Output is correct
18 Correct 3 ms 616 KB Output is correct
19 Correct 3 ms 616 KB Output is correct
20 Correct 3 ms 616 KB Output is correct
21 Correct 2 ms 616 KB Output is correct
22 Correct 2 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 5 ms 620 KB Output is correct
25 Correct 2 ms 620 KB Output is correct
26 Correct 3 ms 620 KB Output is correct
27 Correct 2 ms 620 KB Output is correct
28 Correct 2 ms 620 KB Output is correct
29 Correct 2 ms 636 KB Output is correct
30 Execution timed out 2076 ms 20324 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 20324 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Correct 2 ms 616 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 2 ms 616 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 2 ms 616 KB Output is correct
10 Correct 3 ms 616 KB Output is correct
11 Correct 2 ms 616 KB Output is correct
12 Correct 2 ms 616 KB Output is correct
13 Correct 3 ms 616 KB Output is correct
14 Correct 3 ms 616 KB Output is correct
15 Correct 3 ms 616 KB Output is correct
16 Correct 3 ms 616 KB Output is correct
17 Correct 2 ms 616 KB Output is correct
18 Correct 3 ms 616 KB Output is correct
19 Correct 3 ms 616 KB Output is correct
20 Correct 3 ms 616 KB Output is correct
21 Correct 2 ms 616 KB Output is correct
22 Correct 2 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 5 ms 620 KB Output is correct
25 Correct 2 ms 620 KB Output is correct
26 Correct 3 ms 620 KB Output is correct
27 Correct 2 ms 620 KB Output is correct
28 Correct 2 ms 620 KB Output is correct
29 Correct 2 ms 636 KB Output is correct
30 Execution timed out 2076 ms 20324 KB Time limit exceeded
31 Halted 0 ms 0 KB -