답안 #641465

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
641465 2022-09-16T18:56:14 Z ggoh 고대 책들 (IOI17_books) C++14
0 / 100
15 ms 23896 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];
int d[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;
  int maxi=-1;
  for(int i=1;i<=sz;i++)
  {
    ans+=cost[i];
    sort(cycle[i].begin(),cycle[i].end());
    d[cycle[i][0]]++;
    d[cycle[i][sz(cycle[i])-1]]--;
    maxi=max(maxi,cycle[i][sz(cycle[i])-1]-1);
  }
  int c=0;
  for(int i=0;i<=maxi;i++)
  {
    c+=d[i];
    if(c==0)ans+=2;
  }
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23800 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 15 ms 23804 KB Output is correct
5 Incorrect 14 ms 23896 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23800 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 15 ms 23804 KB Output is correct
5 Incorrect 14 ms 23896 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23800 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 15 ms 23804 KB Output is correct
5 Incorrect 14 ms 23896 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23748 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23800 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 15 ms 23804 KB Output is correct
5 Incorrect 14 ms 23896 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -