Submission #58363

# Submission time Handle Problem Language Result Execution time Memory
58363 2018-07-17T14:50:50 Z E869120 Sorting (IOI15_sorting) C++14
20 / 100
1000 ms 992 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++) {
		while (true) {
			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]);
			}
			swap(B[X[cx]], B[Y[cx]]);
			for (int j = pos - 1; j >= cx + 1; 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) break;
			// s1 -> s2 にムーブする
			if (C[s1] < i) {
				Z.push_back(make_pair(0, 0));
				cx++;
				continue;
			}
			Z.push_back(make_pair(s1, s2)); cx++;
			break;
		}
	}
	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 = M + 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:25:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     if (B[j] == i) s1 = j; if (C[j] == i) s2 = j;
     ^~
sorting.cpp:25:28: 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:39: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:62: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:63: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 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 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 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
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 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Incorrect 2 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1059 ms 992 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1059 ms 992 KB Time limit exceeded
2 Halted 0 ms 0 KB -