답안 #764841

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
764841 2023-06-24T05:39:48 Z SanguineChameleon 정렬하기 (IOI15_sorting) C++17
36 / 100
62 ms 852 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 1 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 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
6 Correct 1 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 0 ms 212 KB Output is correct
10 Correct 1 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 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
6 Correct 1 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 0 ms 212 KB Output is correct
10 Correct 1 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 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 308 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Runtime error 42 ms 852 KB Execution killed with signal 6
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -