답안 #314569

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
314569 2020-10-20T10:17:29 Z juggernaut 정렬하기 (IOI15_sorting) C++14
100 / 100
381 ms 28444 KB
#include"sorting.h"
#include<bits/stdc++.h>
//#include"grader.cpp"
using namespace std;
int n,s[800005],x[800005],y[800005],tmp[800005],pos[800005];
vector<pair<int,int>>res;
bool check(int m){
    int i;
    for(i=0;i<n;i++)tmp[i]=s[i];
    for(i=0;i<m;i++)swap(tmp[x[i]],tmp[y[i]]);
    for(i=0;i<n;i++)pos[tmp[i]]=i;
    vector<pair<int,int>>sw;
    res.clear();
    for(i=0;i<n;i++){
        if(pos[i]==i)continue;
        sw.push_back({tmp[i],tmp[pos[i]]});
        swap(tmp[pos[i]],tmp[i]);
        swap(pos[tmp[pos[i]]],pos[tmp[i]]);
    }
    if(sw.size()>m)return 0;
    for(i=0;i<n;i++)tmp[i]=s[i],pos[tmp[i]]=i;
    for(i=0;i<sw.size();i++){
        swap(tmp[x[i]],tmp[y[i]]);
        swap(pos[tmp[x[i]]],pos[tmp[y[i]]]);
        res.push_back({pos[sw[i].first],pos[sw[i].second]});
        swap(tmp[pos[sw[i].first]],tmp[pos[sw[i].second]]);
        swap(pos[tmp[pos[sw[i].first]]],pos[tmp[pos[sw[i].second]]]);
    }
    for(;i<m;i++)res.push_back({0,0});
    return 1;
}
int findSwapPairs(int N,int S[],int m,int X[],int Y[],int P[],int Q[]){
    n=N;
    int i;
    for(i=0;i<n;i++)s[i]=S[i];
    for(i=0;i<m;i++)x[i]=X[i];
    for(i=0;i<m;i++)y[i]=Y[i];
    int l=0,r=m;
    while(l<r){
        int mid=(l+r)>>1;
        if(check(mid))r=mid;
        else l=mid+1;
    }
    check(l);
    for(i=0;i<l;i++)P[i]=res[i].first,Q[i]=res[i].second;
    return l;
}

Compilation message

sorting.cpp: In function 'bool check(int)':
sorting.cpp:20:17: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |     if(sw.size()>m)return 0;
      |        ~~~~~~~~~^~
sorting.cpp:22:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(i=0;i<sw.size();i++){
      |             ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 2 ms 768 KB Output is correct
22 Correct 2 ms 768 KB Output is correct
23 Correct 2 ms 768 KB Output is correct
24 Correct 2 ms 768 KB Output is correct
25 Correct 2 ms 768 KB Output is correct
26 Correct 2 ms 768 KB Output is correct
27 Correct 2 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 3 ms 616 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 3 ms 616 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 303 ms 17316 KB Output is correct
16 Correct 322 ms 25636 KB Output is correct
17 Correct 369 ms 27204 KB Output is correct
18 Correct 129 ms 25576 KB Output is correct
19 Correct 251 ms 27244 KB Output is correct
20 Correct 241 ms 28376 KB Output is correct
21 Correct 229 ms 28252 KB Output is correct
22 Correct 292 ms 22432 KB Output is correct
23 Correct 356 ms 28052 KB Output is correct
24 Correct 363 ms 27756 KB Output is correct
25 Correct 359 ms 27340 KB Output is correct
26 Correct 236 ms 28264 KB Output is correct
27 Correct 204 ms 27084 KB Output is correct
28 Correct 331 ms 27492 KB Output is correct
29 Correct 346 ms 26780 KB Output is correct
30 Correct 165 ms 26088 KB Output is correct
31 Correct 381 ms 27452 KB Output is correct
32 Correct 303 ms 26988 KB Output is correct
33 Correct 370 ms 27604 KB Output is correct
34 Correct 365 ms 27428 KB Output is correct
35 Correct 254 ms 27056 KB Output is correct
36 Correct 87 ms 25708 KB Output is correct
37 Correct 377 ms 28444 KB Output is correct
38 Correct 349 ms 27344 KB Output is correct
39 Correct 375 ms 27404 KB Output is correct