답안 #660337

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660337 2022-11-21T16:30:16 Z urosk 고대 책들 (IOI17_books) C++14
12 / 100
15 ms 23892 KB
#include "books.h"
#define dbg(x) cerr<<#x<<": "<<x<<endl
#define here cerr<<"================================\n"
#include <bits/stdc++.h>
#define ll long long
#define llinf 1000000000000000000LL
#define pb push_back
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define fi first
#define sc second
#define endl '\n'
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}

using namespace std;
#define maxn 1000005
ll n,st,it;
ll a[maxn],col[maxn],mx[maxn],mn[maxn];
vector<ll> g[maxn];
long long minimum_walk(vector<int> p, int s) {
    n = sz(p);
    for(ll i = 1;i<=n;i++) a[i] = p[i-1]+1;
    reverse(all(p));
    //if(is_sorted(all(p))&&n==4) return 8;
    st = s+1;
    ll ans = 0;
    for(ll i = 1;i<=n;i++){
        if(col[i]) continue;
        if(i==a[i]) continue;
        ll x = a[i];
        ans+=abs(i-a[i]);
        it++;
        col[i] = it;
        mx[it] = i;
        mn[it] = i;
        while(x!=i){
            mx[it] = max(mx[it],x);
            col[x] = it;
            ans+=abs(x-a[x]);
            x = a[x];
        }
    }
    set<ll> cur;
    for(ll i = 1;i<=n;i++){
        if(col[i]){
            for(ll j = 1;j<=it;j++) if(mn[j]>=mn[col[i]]&&mn[j]<=mx[col[i]]) cur.insert(j);
        }
        if(sz(cur)==it){
            ans+=2*(i-1);
            break;
        }
    }
	return ans;
}
/*
4 0
0 2 3 1

4 0
3 2 1 0

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23816 KB Output is correct
2 Correct 15 ms 23800 KB Output is correct
3 Correct 14 ms 23764 KB Output is correct
4 Correct 15 ms 23816 KB Output is correct
5 Correct 15 ms 23816 KB Output is correct
6 Correct 13 ms 23764 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23704 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23892 KB Output is correct
11 Correct 13 ms 23676 KB Output is correct
12 Correct 14 ms 23796 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 13 ms 23804 KB Output is correct
15 Correct 13 ms 23816 KB Output is correct
16 Correct 12 ms 23752 KB Output is correct
17 Correct 13 ms 23764 KB Output is correct
18 Correct 12 ms 23784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23816 KB Output is correct
2 Correct 15 ms 23800 KB Output is correct
3 Correct 14 ms 23764 KB Output is correct
4 Correct 15 ms 23816 KB Output is correct
5 Correct 15 ms 23816 KB Output is correct
6 Correct 13 ms 23764 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23704 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23892 KB Output is correct
11 Correct 13 ms 23676 KB Output is correct
12 Correct 14 ms 23796 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 13 ms 23804 KB Output is correct
15 Correct 13 ms 23816 KB Output is correct
16 Correct 12 ms 23752 KB Output is correct
17 Correct 13 ms 23764 KB Output is correct
18 Correct 12 ms 23784 KB Output is correct
19 Correct 13 ms 23808 KB Output is correct
20 Correct 12 ms 23764 KB Output is correct
21 Correct 14 ms 23784 KB Output is correct
22 Incorrect 15 ms 23756 KB 3rd lines differ - on the 1st token, expected: '2082', found: '2782'
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23816 KB Output is correct
2 Correct 15 ms 23800 KB Output is correct
3 Correct 14 ms 23764 KB Output is correct
4 Correct 15 ms 23816 KB Output is correct
5 Correct 15 ms 23816 KB Output is correct
6 Correct 13 ms 23764 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23704 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23892 KB Output is correct
11 Correct 13 ms 23676 KB Output is correct
12 Correct 14 ms 23796 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 13 ms 23804 KB Output is correct
15 Correct 13 ms 23816 KB Output is correct
16 Correct 12 ms 23752 KB Output is correct
17 Correct 13 ms 23764 KB Output is correct
18 Correct 12 ms 23784 KB Output is correct
19 Correct 13 ms 23808 KB Output is correct
20 Correct 12 ms 23764 KB Output is correct
21 Correct 14 ms 23784 KB Output is correct
22 Incorrect 15 ms 23756 KB 3rd lines differ - on the 1st token, expected: '2082', found: '2782'
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 23832 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23816 KB Output is correct
2 Correct 15 ms 23800 KB Output is correct
3 Correct 14 ms 23764 KB Output is correct
4 Correct 15 ms 23816 KB Output is correct
5 Correct 15 ms 23816 KB Output is correct
6 Correct 13 ms 23764 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23704 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23892 KB Output is correct
11 Correct 13 ms 23676 KB Output is correct
12 Correct 14 ms 23796 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 13 ms 23804 KB Output is correct
15 Correct 13 ms 23816 KB Output is correct
16 Correct 12 ms 23752 KB Output is correct
17 Correct 13 ms 23764 KB Output is correct
18 Correct 12 ms 23784 KB Output is correct
19 Correct 13 ms 23808 KB Output is correct
20 Correct 12 ms 23764 KB Output is correct
21 Correct 14 ms 23784 KB Output is correct
22 Incorrect 15 ms 23756 KB 3rd lines differ - on the 1st token, expected: '2082', found: '2782'
23 Halted 0 ms 0 KB -