답안 #641494

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
641494 2022-09-16T19:29:45 Z ggoh 고대 책들 (IOI17_books) C++14
50 / 100
267 ms 82480 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];
int le[1000002],ri[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,mini=1e9,tmp=0;
  for(int i=1;i<=sz;i++)
  {
    if(sz(cycle[i])==1)continue;
    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);
    mini=min(mini,cycle[i][0]);
    if(cycle[i][0]<s && s<cycle[i][sz(cycle[i])-1])
    {
      int ch=0;
      for(auto &k:cycle[i])
      {
        if(k==s)
        {
          ch=1;break;
        }
      }
      if(!ch)
      {
        for(auto &k:cycle[i])
        {
          if(!tmp)tmp=abs(s-k);
          else tmp=min(tmp,abs(s-k));
        }
      }
    }
  }
  ans+=2*tmp;
  int c=0;
  for(int i=0;i<n;i++)
  {
    c+=d[i];
    d[i]=c;
  }
  if(s<=mini)
  {
    for(int i=s;i<=maxi;i++)
    {
      if(!d[i])ans+=2;
    }
  }
  else if(s>maxi)
  {
    for(int i=mini;i<s;i++)
    {
      if(!d[i])ans+=2;
    }
  }
  else
  {
    for(int i=mini;i<=maxi;i++)
    {
      if(!d[i])ans+=2;
    }
  }
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 11 ms 23792 KB Output is correct
8 Correct 10 ms 23764 KB Output is correct
9 Correct 11 ms 23764 KB Output is correct
10 Correct 14 ms 23764 KB Output is correct
11 Correct 11 ms 23724 KB Output is correct
12 Correct 12 ms 23812 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 12 ms 23808 KB Output is correct
15 Correct 11 ms 23764 KB Output is correct
16 Correct 12 ms 23816 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 11 ms 23796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 11 ms 23792 KB Output is correct
8 Correct 10 ms 23764 KB Output is correct
9 Correct 11 ms 23764 KB Output is correct
10 Correct 14 ms 23764 KB Output is correct
11 Correct 11 ms 23724 KB Output is correct
12 Correct 12 ms 23812 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 12 ms 23808 KB Output is correct
15 Correct 11 ms 23764 KB Output is correct
16 Correct 12 ms 23816 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 11 ms 23796 KB Output is correct
19 Correct 11 ms 23764 KB Output is correct
20 Correct 13 ms 23756 KB Output is correct
21 Correct 12 ms 23864 KB Output is correct
22 Correct 13 ms 23824 KB Output is correct
23 Correct 12 ms 23780 KB Output is correct
24 Correct 12 ms 23764 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 12 ms 23764 KB Output is correct
27 Correct 12 ms 23768 KB Output is correct
28 Correct 12 ms 23764 KB Output is correct
29 Correct 13 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 11 ms 23792 KB Output is correct
8 Correct 10 ms 23764 KB Output is correct
9 Correct 11 ms 23764 KB Output is correct
10 Correct 14 ms 23764 KB Output is correct
11 Correct 11 ms 23724 KB Output is correct
12 Correct 12 ms 23812 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 12 ms 23808 KB Output is correct
15 Correct 11 ms 23764 KB Output is correct
16 Correct 12 ms 23816 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 11 ms 23796 KB Output is correct
19 Correct 11 ms 23764 KB Output is correct
20 Correct 13 ms 23756 KB Output is correct
21 Correct 12 ms 23864 KB Output is correct
22 Correct 13 ms 23824 KB Output is correct
23 Correct 12 ms 23780 KB Output is correct
24 Correct 12 ms 23764 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 12 ms 23764 KB Output is correct
27 Correct 12 ms 23768 KB Output is correct
28 Correct 12 ms 23764 KB Output is correct
29 Correct 13 ms 23764 KB Output is correct
30 Correct 267 ms 72624 KB Output is correct
31 Correct 248 ms 60224 KB Output is correct
32 Correct 168 ms 82480 KB Output is correct
33 Correct 175 ms 70580 KB Output is correct
34 Correct 175 ms 70584 KB Output is correct
35 Correct 178 ms 65340 KB Output is correct
36 Correct 167 ms 55864 KB Output is correct
37 Correct 169 ms 49720 KB Output is correct
38 Correct 174 ms 49208 KB Output is correct
39 Correct 180 ms 49080 KB Output is correct
40 Correct 186 ms 49332 KB Output is correct
41 Correct 219 ms 58328 KB Output is correct
42 Correct 208 ms 52736 KB Output is correct
43 Correct 183 ms 72356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 23772 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2746'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 11 ms 23792 KB Output is correct
8 Correct 10 ms 23764 KB Output is correct
9 Correct 11 ms 23764 KB Output is correct
10 Correct 14 ms 23764 KB Output is correct
11 Correct 11 ms 23724 KB Output is correct
12 Correct 12 ms 23812 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 12 ms 23808 KB Output is correct
15 Correct 11 ms 23764 KB Output is correct
16 Correct 12 ms 23816 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 11 ms 23796 KB Output is correct
19 Correct 11 ms 23764 KB Output is correct
20 Correct 13 ms 23756 KB Output is correct
21 Correct 12 ms 23864 KB Output is correct
22 Correct 13 ms 23824 KB Output is correct
23 Correct 12 ms 23780 KB Output is correct
24 Correct 12 ms 23764 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 12 ms 23764 KB Output is correct
27 Correct 12 ms 23768 KB Output is correct
28 Correct 12 ms 23764 KB Output is correct
29 Correct 13 ms 23764 KB Output is correct
30 Correct 267 ms 72624 KB Output is correct
31 Correct 248 ms 60224 KB Output is correct
32 Correct 168 ms 82480 KB Output is correct
33 Correct 175 ms 70580 KB Output is correct
34 Correct 175 ms 70584 KB Output is correct
35 Correct 178 ms 65340 KB Output is correct
36 Correct 167 ms 55864 KB Output is correct
37 Correct 169 ms 49720 KB Output is correct
38 Correct 174 ms 49208 KB Output is correct
39 Correct 180 ms 49080 KB Output is correct
40 Correct 186 ms 49332 KB Output is correct
41 Correct 219 ms 58328 KB Output is correct
42 Correct 208 ms 52736 KB Output is correct
43 Correct 183 ms 72356 KB Output is correct
44 Incorrect 14 ms 23772 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2746'
45 Halted 0 ms 0 KB -