답안 #1047216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1047216 2024-08-07T10:42:18 Z Ahmed57 고대 책들 (IOI17_books) C++17
50 / 100
86 ms 43744 KB
#include "bits/stdc++.h"
using namespace std;
vector<int> P;
int vis[1000001];
int mn = 1e9 ,mx = -1e9;
void dfs(int i){
    vis[i] = 1;
    mn = min(mn,i);
    mx = max(mx,i);
    if(!vis[P[i]])dfs(P[i]);
}
long long minimum_walk(vector<int> p, int s){
    long long ans = 0;
    int n = p.size();
    P.clear();
    for(int i = 0;i<n;i++){
        vis[i] = 0;
        P.push_back(p[i]);
        ans+=abs(i-p[i]);
    }
    vector<pair<int,int>> lol;
    for(int i = 0;i<n;i++){
        if(!vis[i]){
            mn = 1e9 , mx = -1e9;
            dfs(i);
            lol.push_back({mn,mx});
        }
    }
    sort(lol.begin(),lol.end());
    int R = -1e9;
    int L = -1e9;
    int sz = 0;
    vector<pair<int,int>> nah;
    for(int i = 0;i<lol.size();i++){
        if(R<lol[i].first){
            if(R>=0){
                nah.push_back({L,R});
            }
            R = lol[i].second;
            L = lol[i].first;
            sz++;
        }else{
            R = max(R,lol[i].second);
        }
    }
    nah.push_back({L,R});
    for(int i = nah.size()-1;i>=0;i--){
        if(nah[i].first==nah[i].second){
            sz--;
        }else break;
    }
    ans+=max(0,(sz-1))*2;
    return ans;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i = 0;i<lol.size();i++){
      |                   ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 73 ms 16520 KB Output is correct
31 Correct 83 ms 22976 KB Output is correct
32 Correct 85 ms 43744 KB Output is correct
33 Correct 85 ms 41536 KB Output is correct
34 Correct 82 ms 41792 KB Output is correct
35 Correct 86 ms 36960 KB Output is correct
36 Correct 83 ms 27836 KB Output is correct
37 Correct 61 ms 23488 KB Output is correct
38 Correct 61 ms 23232 KB Output is correct
39 Correct 61 ms 22720 KB Output is correct
40 Correct 65 ms 22752 KB Output is correct
41 Correct 70 ms 22988 KB Output is correct
42 Correct 73 ms 22960 KB Output is correct
43 Correct 76 ms 32864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 73 ms 16520 KB Output is correct
31 Correct 83 ms 22976 KB Output is correct
32 Correct 85 ms 43744 KB Output is correct
33 Correct 85 ms 41536 KB Output is correct
34 Correct 82 ms 41792 KB Output is correct
35 Correct 86 ms 36960 KB Output is correct
36 Correct 83 ms 27836 KB Output is correct
37 Correct 61 ms 23488 KB Output is correct
38 Correct 61 ms 23232 KB Output is correct
39 Correct 61 ms 22720 KB Output is correct
40 Correct 65 ms 22752 KB Output is correct
41 Correct 70 ms 22988 KB Output is correct
42 Correct 73 ms 22960 KB Output is correct
43 Correct 76 ms 32864 KB Output is correct
44 Incorrect 0 ms 344 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -