답안 #987163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987163 2024-05-22T07:12:49 Z AdamGS 고대 책들 (IOI17_books) C++17
50 / 100
463 ms 85704 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll INF=1e9+7;
const int LIM=1e6+7;
ll F[LIM], mi[LIM], ma[LIM], l, r;
set<ll>S;
ll fnd(ll x) {
  if(F[x]==x) return x;
  return F[x]=fnd(F[x]);
}
void uni(int a, int b) {
  if(fnd(a)==fnd(b)) return;
  ma[fnd(a)]=max(ma[fnd(a)], ma[fnd(b)]);
  mi[fnd(a)]=min(mi[fnd(a)], mi[fnd(b)]);
  F[fnd(b)]=fnd(a);
}
ll solve(ll aktl, ll aktr, ll aktmi, ll aktma) {
  if(aktl>aktmi) {
    --aktl;
    aktmi=min(aktmi, mi[fnd(aktl)]);
    aktma=max(aktma, ma[fnd(aktr)]);
    return solve(aktl, aktr, aktmi, aktma);
  }
  if(aktr<aktma) {
    ++aktr;
    aktmi=min(aktmi, mi[fnd(aktr)]);
    aktma=max(aktma, ma[fnd(aktr)]);
    return solve(aktl, aktr, aktmi, aktma);
  }
  if(aktl==l && aktr==r) return 0;
  ++aktr;
  aktmi=min(aktmi, mi[fnd(aktr)]);
  aktma=max(aktma, ma[fnd(aktr)]);
  return solve(aktl, aktr, aktmi, aktma)+2;
}
ll minimum_walk(vector<int>p, int s) {
  ll n=p.size();
  rep(i, n) {
    F[i]=ma[i]=mi[i]=i;
    S.insert(i);
  }
  rep(i, n) uni(i, p[i]);
  vector<pair<pair<ll,ll>,pair<ll,ll>>>V;
  l=0; r=n-1;
  while(l<s && p[l]==l) ++l;
  while(r>s && p[r]==r) --r;
  ll ans=0;
  rep(i, n) ans+=abs(p[i]-i);
  return ans+solve(s, s, mi[fnd(s)], ma[fnd(s)]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 444 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 444 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 444 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 463 ms 85428 KB Output is correct
31 Correct 418 ms 85360 KB Output is correct
32 Correct 286 ms 85332 KB Output is correct
33 Correct 295 ms 85640 KB Output is correct
34 Correct 302 ms 85248 KB Output is correct
35 Correct 292 ms 85332 KB Output is correct
36 Correct 291 ms 85332 KB Output is correct
37 Correct 300 ms 85324 KB Output is correct
38 Correct 312 ms 85372 KB Output is correct
39 Correct 312 ms 85332 KB Output is correct
40 Correct 329 ms 85328 KB Output is correct
41 Correct 344 ms 85704 KB Output is correct
42 Correct 344 ms 85332 KB Output is correct
43 Correct 293 ms 85348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3506'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 444 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 463 ms 85428 KB Output is correct
31 Correct 418 ms 85360 KB Output is correct
32 Correct 286 ms 85332 KB Output is correct
33 Correct 295 ms 85640 KB Output is correct
34 Correct 302 ms 85248 KB Output is correct
35 Correct 292 ms 85332 KB Output is correct
36 Correct 291 ms 85332 KB Output is correct
37 Correct 300 ms 85324 KB Output is correct
38 Correct 312 ms 85372 KB Output is correct
39 Correct 312 ms 85332 KB Output is correct
40 Correct 329 ms 85328 KB Output is correct
41 Correct 344 ms 85704 KB Output is correct
42 Correct 344 ms 85332 KB Output is correct
43 Correct 293 ms 85348 KB Output is correct
44 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3506'
45 Halted 0 ms 0 KB -