답안 #65064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
65064 2018-08-06T14:02:08 Z Bodo171 정렬하기 (IOI15_sorting) C++14
20 / 100
3 ms 512 KB
#include "sorting.h"
#include <iostream>
const int nmax=200005;
using namespace std;
int i,n,idx,u;
int en[nmax],v[nmax],p[nmax],poz[nmax],a[3*nmax],b[3*nmax],A[3*nmax],B[3*nmax];
bool check(int val)
{
     for(i=0;i<n;i++)
        poz[v[i]]=i,p[i]=v[i];
     for(i=0;i<val;i++)
        swap(v[a[i]],v[b[i]]);
     for(i=0;i<n;i++)
        en[v[i]]=i;//en[i]-pozitia pe care ajunge elementul i;
    idx=0;u=0;
    for(i=0;i<val;i++)
    {
        while(idx<n&&en[idx]==idx) idx++;
        if(idx<n)
        {
            en[v[idx]]=en[idx];//acum elementul care era pe pozitia noastra ajunge unde ar fi ajuns al noostru
            v[en[idx]]=v[idx];//facem asta si la nivelul sirului
            A[u]=poz[idx];B[u]=poz[v[idx]];
            ++u;
            swap(poz[idx],poz[v[idx]]);
            swap(p[poz[idx]],p[poz[v[idx]]]);
            idx++;
        }
        swap(p[a[i]],p[b[i]]);
        swap(poz[p[a[i]]],poz[p[b[i]]]);
    }
    while(idx<n&&en[idx]==idx) idx++;
    return (idx==n);
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    int ans=M;
    n=N;
    for(i=0;i<M;i++)
        a[i]=X[i],b[i]=Y[i];
    for(int p=19;p>=0;p--)
    {
        for(i=0;i<N;i++)
          v[i]=S[i];
        if(ans-(1<<p)>=0&&check(ans-(1<<p)))
            ans-=(1<<p);
    }
    for(i=0;i<N;i++)
          v[i]=S[i];
    int okceva=check(ans);
    for(i=0;i<u;i++)
        P[i]=A[i],Q[i]=B[i];
    for(i=u;i<ans;i++)
        P[i]=Q[i]=0;
	return ans;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:40:13: warning: declaration of 'p' shadows a global declaration [-Wshadow]
     for(int p=19;p>=0;p--)
             ^
sorting.cpp:6:22: note: shadowed declaration is here
 int en[nmax],v[nmax],p[nmax],poz[nmax],a[3*nmax],b[3*nmax],A[3*nmax],B[3*nmax];
                      ^
sorting.cpp:52:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(i=u;i<ans;i++)
     ^~~
sorting.cpp:54:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  return ans;
  ^~~~~~
sorting.cpp:49:9: warning: unused variable 'okceva' [-Wunused-variable]
     int okceva=check(ans);
         ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 300 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 3 ms 300 KB Output is correct
14 Incorrect 2 ms 384 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -