답안 #1018712

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1018712 2024-07-10T08:48:08 Z AmirAli_H1 정렬하기 (IOI15_sorting) C++17
54 / 100
7 ms 860 KB
// In the name of Allah

#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;

typedef		long long int			ll;
typedef		long double				ld;
typedef		pair<int, int>			pii;
typedef		pair<ll, ll>			pll;
typedef		complex<ld>				cld;

#define		all(x)					(x).begin(),(x).end()
#define		len(x)					((ll) (x).size())
#define		F						first
#define		S						second
#define		pb						push_back
#define		sep						' '
#define		endl					'\n'
#define		Mp						make_pair
#define		kill(x)					cout << x << '\n', exit(0)
#define		set_dec(x)				cout << fixed << setprecision(x);
#define		file_io(x,y)			freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, q;
const int maxn = 2e5 + 7;
int A1[maxn], A2[maxn];

bool ok() {
	for (int i = 0; i < n; i++) {
		if (A1[i] != i) return 0;
	}
	return 1;
}

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    n = N; q = M;
    for (int i = 0; i < n; i++) {
    	A1[i] = S[i]; A2[i] = S[i];
	}
	for (int i = 0; i < q; i++) {
		int i1 = X[i], i2 = Y[i];
		P[i] = 0; Q[i] = 0;
		swap(A2[i1], A2[i2]);
	}
	
	int R = 0;
	for (int i = 0; i < q; i++) {
		if (ok()) break;
		R++;
		int i1 = X[i], i2 = Y[i];
		swap(A1[i1], A1[i2]);
		int x1 = -1, x2 = -1;
		for (int j = 0; j < n; j++) {
			if (A2[j] != j) {
				x1 = A2[j], x2 = A2[A2[j]];
				swap(A2[j], A2[A2[j]]);
				break;
			}
		}
		if (x1 != -1 && x2 != -1) {
			P[i] = find(A1, A1 + n, x1) - A1;
			Q[i] = find(A1, A1 + n, x2) - A1;
		}
		i1 = P[i], i2 = Q[i];
		swap(A1[i1], A1[i2]);
	}
	return R;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:63:32: warning: conversion from 'long int' to 'int' may change value [-Wconversion]
   63 |    P[i] = find(A1, A1 + n, x1) - A1;
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~
sorting.cpp:64:32: warning: conversion from 'long int' to 'int' may change value [-Wconversion]
   64 |    Q[i] = find(A1, A1 + n, x2) - A1;
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 448 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 448 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 356 KB Output is correct
21 Correct 5 ms 604 KB Output is correct
22 Correct 4 ms 832 KB Output is correct
23 Correct 5 ms 836 KB Output is correct
24 Correct 4 ms 848 KB Output is correct
25 Correct 4 ms 860 KB Output is correct
26 Correct 5 ms 604 KB Output is correct
27 Correct 7 ms 608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 528 KB Output isn't correct
2 Halted 0 ms 0 KB -