Submission #58340

# Submission time Handle Problem Language Result Execution time Memory
58340 2018-07-17T13:53:25 Z E869120 Sorting (IOI15_sorting) C++14
20 / 100
313 ms 536 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int N, S[200009], M, X[200009], Y[200009], A[200009];

vector<pair<int, int>> solve(int pos) {
	// 74 点解法

	vector<pair<int, int>>Z; int cx = 0;
	for (int i = 0; i < N; i++) {
		vector<int>B(N, 0), C(N, 0);
		for (int j = 0; j < N; j++) { B[j] = S[j]; C[j] = j; }
		for (int j = 0; j < cx; j++) {
			swap(B[X[j]], B[Y[j]]);
			swap(B[Z[j].first], B[Z[j].second]);
		}
		for (int j = pos - 1; j >= cx; j--) swap(C[X[j]], C[Y[j]]);
		
		int s1 = 0, s2 = 0;
		for (int j = 0; j < N; j++) {
			if (B[j] == i) s1 = j; if (C[j] == i) s2 = j;
		}
		if (s1 == s2) continue;
		Z.push_back(make_pair(s1, s2)); cx++;
	}
	for (int i = 0; i < N; i++) A[i] = S[i];
	while (Z.size() < pos) Z.push_back(make_pair(0, 0));
	for (int i = 0; i < pos; i++) {
		swap(A[X[i]], A[Y[i]]);
		swap(A[Z[i].first], A[Z[i].second]);
	}
	for (int i = 0; i < N; i++) {
		if (A[i] != i) return vector<pair<int, int>>{make_pair(-1, -1)};
	}
	return Z;
}

int findSwapPairs(int NN, int SS[], int MM, int XX[], int YY[], int P[], int Q[]) {
	N = NN; M = MM;
	for (int i = 0; i < NN; i++) S[i] = SS[i];
	for (int i = 0; i < MM; i++) { X[i] = XX[i]; Y[i] = YY[i]; }

	int L = 0, R = N + 1, M_; vector<pair<int, int>>ret;
	for (int i = 0; i < 20; i++) {
		M_ = (L + R) / 2;
		vector<pair<int, int>> z = solve(M_);
		if (z == vector<pair<int, int>>{make_pair(-1, -1)}) L = M_;
		else { R = M_; ret = z; }
	}
	for (int i = 0; i < ret.size(); i++) { P[i] = ret[i].first; Q[i] = ret[i].second; }
	return ret.size();
}

Compilation message

sorting.cpp: In function 'std::vector<std::pair<int, int> > solve(int)':
sorting.cpp:23:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
    if (B[j] == i) s1 = j; if (C[j] == i) s2 = j;
    ^~
sorting.cpp:23:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
    if (B[j] == i) s1 = j; if (C[j] == i) s2 = j;
                           ^~
sorting.cpp:29:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while (Z.size() < pos) Z.push_back(make_pair(0, 0));
         ~~~~~~~~~^~~~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:52:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < ret.size(); i++) { P[i] = ret[i].first; Q[i] = ret[i].second; }
                  ~~^~~~~~~~~~~~
sorting.cpp:53:17: warning: conversion to 'int' from 'std::vector<std::pair<int, int> >::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  return ret.size();
         ~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 428 KB Output is correct
4 Correct 2 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 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 428 KB Output is correct
4 Correct 2 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 3 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 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Incorrect 3 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 428 KB Output is correct
4 Correct 2 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 3 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 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Incorrect 3 ms 256 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 313 ms 536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 313 ms 536 KB Output isn't correct
2 Halted 0 ms 0 KB -