# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
785429 | 2023-07-17T09:05:11 Z | fatemetmhr | 정렬하기 (IOI15_sorting) | C++17 | 60 ms | 10360 KB |
// ~ Be Name Khoda ~ // #include "sorting.h" #include <bits/stdc++.h> //#pragma GCC optimize ("O3") //#pragma GCC target("avx2") //#pragma GCC optimize("unroll-loops,Ofast") using namespace std; typedef long long ll; #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define fi first #define se second const int maxn = 1e6 + 10; const int maxn5 = 6000 + 10; const int maxnt = 1.2e6 + 10; const int maxn3 = 1e3 + 10; const int mod = 1e9 + 7; const ll inf = 1e18; int n, cmp, sz, pt, a[maxn5], b[maxn5], x[maxn5], y[maxn5]; int s1[maxn5], s2[maxn5]; bool mark[maxn5]; void sset(int a, int b){ for(int i = sz - 1; i > pt; i--){ if(a > b) swap(a, b); if(a == b || x[i] == y[i]) continue; if((a == x[i] && b == y[i]) || (a != x[i] && a != y[i] && b != x[i] && b != y[i])) continue; if(a == x[i]) a = y[i]; else if(a == y[i]) a = x[i]; else if(b == x[i]) b = y[i]; else if(b == y[i]) b = x[i]; } s1[pt] = a; s2[pt] = b; pt++; } int rt; void dfs(int v){ mark[v] = true; if(!mark[b[v]]){ //cout << "its " << v << ' ' << b[v] << endl; sset(rt, b[v]); dfs(b[v]); } } bool check(int m){ //cout << "hereeeeee " << m << endl; sz = m; memset(mark, false, sizeof mark); for(int i = 0; i < n; i++){ b[i] = a[i]; } for(int i = 0; i < m; i++) swap(b[x[i]], b[y[i]]); pt = 0; for(int i = 0; i < n; i++) if(!mark[i]){ rt = i; dfs(i); } //cout << "in " << m << ' ' << pt << endl; return pt <= m; } int findSwapPairs(int N, int A[], int m, int X[], int Y[], int p[], int q[]) { n = N; for(int i = 0; i < m; i++){ x[i] = X[i]; y[i] = Y[i]; if(x[i] > y[i]) swap(x[i], y[i]); } for(int i = 0; i < n; i++) a[i] = A[i]; bool re = true; for(int i = 1; i < n; i++) re &= (a[i] > a[i - 1]); if(re) return 0; int lo = -1, hi = m; while(hi - lo > 1){ int mid = (hi + lo) >> 1; if(check(mid)) hi = mid; else lo = mid; } check(hi); for(int i = 0; i < pt; i++){ p[i] = s1[i]; q[i] = s2[i]; } for(int i = pt; i < hi; i++) p[i] = q[i] = 0; return hi; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | 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 | 1 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 | 1 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 | 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 | 1 ms | 340 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 | 1 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 | 1 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 | 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 | 1 ms | 340 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 | 1 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Incorrect | 20 ms | 516 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 35 ms | 452 KB | Output is correct |
2 | Correct | 39 ms | 444 KB | Output is correct |
3 | Correct | 60 ms | 460 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 18 ms | 448 KB | Output is correct |
6 | Correct | 11 ms | 340 KB | Output is correct |
7 | Correct | 19 ms | 468 KB | Output is correct |
8 | Correct | 37 ms | 448 KB | Output is correct |
9 | Correct | 36 ms | 448 KB | Output is correct |
10 | Correct | 46 ms | 460 KB | Output is correct |
11 | Correct | 31 ms | 468 KB | Output is correct |
12 | Correct | 17 ms | 464 KB | Output is correct |
13 | Correct | 39 ms | 448 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 35 ms | 452 KB | Output is correct |
2 | Correct | 39 ms | 444 KB | Output is correct |
3 | Correct | 60 ms | 460 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 18 ms | 448 KB | Output is correct |
6 | Correct | 11 ms | 340 KB | Output is correct |
7 | Correct | 19 ms | 468 KB | Output is correct |
8 | Correct | 37 ms | 448 KB | Output is correct |
9 | Correct | 36 ms | 448 KB | Output is correct |
10 | Correct | 46 ms | 460 KB | Output is correct |
11 | Correct | 31 ms | 468 KB | Output is correct |
12 | Correct | 17 ms | 464 KB | Output is correct |
13 | Correct | 39 ms | 448 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Runtime error | 41 ms | 10360 KB | Execution killed with signal 11 |
16 | Halted | 0 ms | 0 KB | - |