Submission #65669

# Submission time Handle Problem Language Result Execution time Memory
65669 2018-08-08T11:15:01 Z mirbek01 Sorting (IOI15_sorting) C++17
0 / 100
3 ms 768 KB
#include "sorting.h"

# include <bits/stdc++.h>

using namespace std;

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      int sz = 0;

      set <int> st;

      for(int i = N - 1; i >= 0; i --)
      {
            assert( S[i] >= 0 && S[i] < N );
            st.insert(S[i]);
      }
      assert(st.size() == N && M == N * N);

      for(int i = 0; i < M; i ++){
            assert(!X[i] && !Y[i]);
      }

      for(int i = N - 1; i > 0; i --){
            bool fl = 1;
            for(int j = 0; j < N; j ++){
                  if(j != S[j]) fl = 0;
            }
            if(fl) break;
//            swap(S[X[sz]], S[Y[sz]]);
            int pos;
            for(int j = 0; j < N; j ++){
                  if(S[j] == i){
                        pos = j;
                        break;
                  }
            }
            swap(S[pos], S[i]);
            P[sz] = pos, Q[sz] = i;
            sz ++;
      }

	return sz;
}

Compilation message

In file included from /usr/include/c++/7/cassert:44:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from sorting.cpp:3:
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:17:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       assert(st.size() == N && M == N * N);
              ~~~~~~~~~~^~~~
sorting.cpp:30:17: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
             int pos;
                 ^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Incorrect 3 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Incorrect 3 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Incorrect 3 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -