답안 #73669

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
73669 2018-08-28T17:06:17 Z MKopchev 고대 책들 (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;
    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;
    */
      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])
            {
                out[i]+=out[i-1]-in[i-1];
                out[i-1]=in[i-1];
            }
            else//in[i-1]>out[i-1]
            {
                in[i]+=in[i-1]-out[i-1];
                in[i-1]=out[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;
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 2 ms 516 KB Output is correct
8 Correct 3 ms 516 KB Output is correct
9 Correct 3 ms 516 KB Output is correct
10 Correct 2 ms 516 KB Output is correct
11 Correct 3 ms 516 KB Output is correct
12 Correct 2 ms 516 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 3 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 2 ms 516 KB Output is correct
8 Correct 3 ms 516 KB Output is correct
9 Correct 3 ms 516 KB Output is correct
10 Correct 2 ms 516 KB Output is correct
11 Correct 3 ms 516 KB Output is correct
12 Correct 2 ms 516 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 3 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 4 ms 620 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 3 ms 620 KB Output is correct
25 Correct 2 ms 620 KB Output is correct
26 Correct 2 ms 620 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
28 Correct 3 ms 748 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 2 ms 516 KB Output is correct
8 Correct 3 ms 516 KB Output is correct
9 Correct 3 ms 516 KB Output is correct
10 Correct 2 ms 516 KB Output is correct
11 Correct 3 ms 516 KB Output is correct
12 Correct 2 ms 516 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 3 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 4 ms 620 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 3 ms 620 KB Output is correct
25 Correct 2 ms 620 KB Output is correct
26 Correct 2 ms 620 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
28 Correct 3 ms 748 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Execution timed out 2053 ms 20324 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 2 ms 516 KB Output is correct
8 Correct 3 ms 516 KB Output is correct
9 Correct 3 ms 516 KB Output is correct
10 Correct 2 ms 516 KB Output is correct
11 Correct 3 ms 516 KB Output is correct
12 Correct 2 ms 516 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 3 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 4 ms 620 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 3 ms 620 KB Output is correct
25 Correct 2 ms 620 KB Output is correct
26 Correct 2 ms 620 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
28 Correct 3 ms 748 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Execution timed out 2053 ms 20324 KB Time limit exceeded
31 Halted 0 ms 0 KB -