Submission #641431

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

int n,sz;
int v[1000002];
vector<int>go;
vector<int>cycle[1000002];
lint cost[1000002];
void dfs(int p,int par)
{
  cycle[sz].push_back(p);
  cost[sz]+=abs(par-p);
  v[p]=1;
  if(!v[go[p]])dfs(go[p],p);
  else cost[sz]+=abs(go[p]-p);
}
lint minimum_walk(vector<int> p, int s) {
  n=sz(p);
  go=p;
  for(int i=0;i<n;i++)
  {
    if(!v[i])
    {
      sz++;
      dfs(i,i);
    }
  }
  vector<int>X;
  lint ans=0;
  for(int i=1;i<=sz;i++)
  {
    ans+=cost[i];
    sort(cycle[i].begin(),cycle[i].end());
    X.push_back(cycle[i][0]);
  }
  sort(X.begin(),X.end());
  for(int i=1;i<sz;i++)
  {
    ans+=2*(X[i]-X[i-1]);
  }
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Incorrect 14 ms 23764 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Incorrect 14 ms 23764 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Incorrect 14 ms 23764 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23752 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4736'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Incorrect 14 ms 23764 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -