Submission #641439

# Submission time Handle Problem Language Result Execution time Memory
641439 2022-09-16T18:10:26 Z ggoh Ancient Books (IOI17_books) C++14
12 / 100
2000 ms 312 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
#define sz(v) ((int)(v).size())
typedef long long lint;

int b,n,sz,cnt;
int v[1000002],rev[1000002];
vector<int>go;
lint ans=0;
void dfs(int p,int q)
{
  if(b==-1)
  {
    ans+=p;
    return ;
  }
  if(q==b)
  {
    if(p==b)
    {
      int tmp=go[p];
      go[p]=q;
      while(b-1>=0 && go[b-1]==b-1)b--;
      b--;
      dfs(p,tmp);
    }
    else
    {
      ans+=abs(p-b);
      dfs(b,q);
    }
    return ;
  }
  if(go[p]==p)
  {
    ans++;
    if(rev[b]>p)dfs(p+1,q);
    else dfs(p-1,q);
  }
  else
  {
    int tmp=go[p];
    go[p]=q;
    if(tmp==b)
    {
      dfs(p,tmp);
      return ;
    }
    ans++;
    if(rev[b]>p)dfs(p+1,tmp);
    else dfs(p-1,tmp);
  }
}

lint minimum_walk(vector<int> p, int s) {
  n=sz(p);
  go=p;
  for(int i=0;i<n;i++)rev[go[i]]=i;
  b=n;
  while(b-1>=0 && go[b-1]==b-1)b--;
  b--;
  dfs(0,-1);
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 0 ms 308 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 0 ms 308 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Execution timed out 2085 ms 212 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 0 ms 308 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Execution timed out 2085 ms 212 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 308 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2770'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 0 ms 308 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Execution timed out 2085 ms 212 KB Time limit exceeded
20 Halted 0 ms 0 KB -