답안 #643651

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643651 2022-09-22T17:38:07 Z ghostwriter 정렬하기 (IOI15_sorting) C++14
20 / 100
1 ms 468 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#include "grader.cpp"
#endif
#define ft front
#define bk back
#define st first
#define nd second
#define ins insert
#define ers erase
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define bg begin
#define ed end
#define all(x) (x).bg(), (x).ed()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    VOI23 gold medal
*/
namespace subtask1234 {
	const int N = 500;
	int pos[N];
	int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
		FOR(i, 0, N - 1) pos[i] = i;
		FOS(i, M - 1, 0) {
			int x = X[i], y = Y[i];
			swap(pos[x], pos[y]);
		}
		bool sorted = 1;
		FOR(i, 1, N - 1)
			if (S[i] < S[i - 1])
				sorted = 0;
		if (sorted) return 1;
		FOR(i, 0, N - 2) {
			int x = X[i], y = Y[i], cur = -1, npos = -1;
			FOR(j, 0, N - 1)
				if (S[j] == i)
					cur = j;
			FOR(j, 0, N - 1)
				if (pos[j] == i)
					npos = j;
			P[i] = cur;
			Q[i] = npos;
			swap(S[cur], S[npos]);
			swap(S[x], S[y]);
			swap(pos[x], pos[y]);
			bool sorted = 1;
			FOR(i, 1, N - 1)
				if (S[i] < S[i - 1])
					sorted = 0;
			if (sorted) return i + 1;
		}
		FOR(i, N - 1, M - 1) {
			int x = X[i], y = Y[i];
			P[i] = Q[i] = 0;
			swap(S[x], S[y]);
			bool sorted = 1;
			FOR(i, 1, N - 1)
				if (S[i] < S[i - 1])
					sorted = 0;
			if (sorted) return i + 1;
		}
		return M;
	}
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	if (N <= 500 && M >= N - 1) return subtask1234::findSwapPairs(N, S, M, X, Y, P, Q);
	assert(0 > 1);
	return 1;
}
/*
*/
/*
From Benq:
    stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
        * DON'T GET STUCK ON ONE APPROACH
*/

Compilation message

sorting.cpp: In function 'int subtask1234::findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:46:24: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   46 |  int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                    ~~~~^
sorting.cpp:44:12: note: shadowed declaration is here
   44 |  const int N = 500;
      |            ^
sorting.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
sorting.cpp:47:3: note: in expansion of macro 'FOR'
   47 |   FOR(i, 0, N - 1) pos[i] = i;
      |   ^~~
sorting.cpp:33:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   33 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
sorting.cpp:48:3: note: in expansion of macro 'FOS'
   48 |   FOS(i, M - 1, 0) {
      |   ^~~
sorting.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
sorting.cpp:53:3: note: in expansion of macro 'FOR'
   53 |   FOR(i, 1, N - 1)
      |   ^~~
sorting.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
sorting.cpp:57:3: note: in expansion of macro 'FOR'
   57 |   FOR(i, 0, N - 2) {
      |   ^~~
sorting.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
sorting.cpp:59:4: note: in expansion of macro 'FOR'
   59 |    FOR(j, 0, N - 1)
      |    ^~~
sorting.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
sorting.cpp:62:4: note: in expansion of macro 'FOR'
   62 |    FOR(j, 0, N - 1)
      |    ^~~
sorting.cpp:70:9: warning: declaration of 'sorted' shadows a previous local [-Wshadow]
   70 |    bool sorted = 1;
      |         ^~~~~~
sorting.cpp:52:8: note: shadowed declaration is here
   52 |   bool sorted = 1;
      |        ^~~~~~
sorting.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
sorting.cpp:71:4: note: in expansion of macro 'FOR'
   71 |    FOR(i, 1, N - 1)
      |    ^~~
sorting.cpp:71:8: warning: declaration of 'i' shadows a previous local [-Wshadow]
   71 |    FOR(i, 1, N - 1)
      |        ^
sorting.cpp:32:32: note: in definition of macro 'FOR'
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                                ^
sorting.cpp:57:7: note: shadowed declaration is here
   57 |   FOR(i, 0, N - 2) {
      |       ^
sorting.cpp:32:32: note: in definition of macro 'FOR'
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                                ^
sorting.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
sorting.cpp:76:3: note: in expansion of macro 'FOR'
   76 |   FOR(i, N - 1, M - 1) {
      |   ^~~
sorting.cpp:80:9: warning: declaration of 'sorted' shadows a previous local [-Wshadow]
   80 |    bool sorted = 1;
      |         ^~~~~~
sorting.cpp:52:8: note: shadowed declaration is here
   52 |   bool sorted = 1;
      |        ^~~~~~
sorting.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
sorting.cpp:81:4: note: in expansion of macro 'FOR'
   81 |    FOR(i, 1, N - 1)
      |    ^~~
sorting.cpp:81:8: warning: declaration of 'i' shadows a previous local [-Wshadow]
   81 |    FOR(i, 1, N - 1)
      |        ^
sorting.cpp:32:32: note: in definition of macro 'FOR'
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                                ^
sorting.cpp:76:7: note: shadowed declaration is here
   76 |   FOR(i, N - 1, M - 1) {
      |       ^
sorting.cpp:32:32: note: in definition of macro 'FOR'
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                                ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 236 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 236 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -