답안 #764846

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
764846 2023-06-24T05:40:54 Z SanguineChameleon 정렬하기 (IOI15_sorting) C++17
20 / 100
165 ms 660 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;

const int maxN = 2e5 + 20;
int cnt[maxN];

bool cmp(int i, int j) {
	return cnt[i] > cnt[j];
}

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	for (int i = 0; i < M; i++) {
		cnt[X[i]]++;
		cnt[Y[i]]++;
	}
	int len = 0;
	for (int i = 0; ; i++) {
		bool ok = true;
		for (int j = 0; j < N; j++) {
			if (S[j] != j) {
				ok = false;
				break;
			}
		}
		if (ok) {
			return len;
		}
		assert(i < M);
		cnt[X[i]]--;
		cnt[Y[i]]--;
		swap(S[X[i]], S[Y[i]]);
		vector<int> wrong;
		for (int j = 0; j < N; j++) {
			if (S[j] != j) {
				wrong.push_back(j);
			}
		}
		if (wrong.empty()) {
			P[len] = 0;
			Q[len] = 0;
		}
		else {
			sort(wrong.begin(), wrong.end(), cmp);
			P[len] = wrong[0];
			for (int j = 0; j < N; j++) {
				if (S[j] == wrong[0]) {
					Q[len] = j;
					break;
				}
			}
		}
		swap(S[P[len]], S[Q[len]]);
		len++;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Runtime error 1 ms 468 KB Execution killed with signal 6
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 165 ms 660 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 165 ms 660 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -