답안 #641431

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
641431 2022-09-16T17:26:46 Z ggoh 고대 책들 (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;
}
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -