제출 #115028

#제출 시각아이디문제언어결과실행 시간메모리
115028MladenP정렬하기 (IOI15_sorting)C++17
0 / 100
19 ms512 KiB
#include<bits/stdc++.h> #define STIZE(x) fprintf(stderr, "STIZE%d\n", x); #define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x); #define NL(x) printf("%c", " \n"[(x)]); #define lld long long #define pii pair<int,int> #define pb push_back #define fi first #define se second #define mid (l+r)/2 #define endl '\n' #define all(a) begin(a),end(a) #define sz(a) int((a).size()) #define LINF 1000000000000000LL #define INF 1000000000 #define EPS 1e-9 using namespace std; #define MAXN 200010 int n, s[MAXN], m, x[MAXN], y[MAXN], p[MAXN], q[MAXN], idxx, idx[MAXN]; bool pos[MAXN]; void DFS(int node) { pos[node] = 1; if(!pos[s[node]]) DFS(s[node]); } void DFS1(int node) { pos[node] = 1; if(!pos[s[node]]) { p[idxx] = node; q[idxx] = s[node]; idxx++; DFS1(s[node]); } } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n = N, m = M; int rez; for(int i = 0; i < N; i++) s[i] = S[i], idx[s[i]] = i; for(int i = 0; i < M; i++) { swap(s[X[i]], s[Y[i]]); //swap(idx[s[X[i]], idx[s[Y[i]]]); for(int j = 0; j < N; j++) pos[j] = 0; int cnt = 0; for(int j = 0; j < N; j++) { if(!pos[j]) DFS(j), cnt++; } //PRINT(n-cnt); //PRINT(i); if(n-cnt <= i+1) { rez = i+1; for(int j = 0; j < N; j++) pos[j] = 0; for(int j = 0; j < N; j++) { if(!pos[j]) DFS1(j); } for(int j = 0; j < idxx; j++) P[j] = p[j], Q[j] = q[j]; for(int j = idxx; j < i; j++) P[j] = 0, Q[j] = 0; break; } }// for(int i = 0; i < rez; i++) { swap(S[X[i]], S[Y[i]]); /*for(int j = 0; j < N; j++) cout << S[j] << ' '; cout << endl; for(int j = 0; j < N; j++) cout << idx[j] << ' '; cout << endl;*/ swap(idx[S[X[i]]], idx[S[Y[i]]]); P[i] = idx[s[P[i]]], Q[i] = idx[s[Q[i]]]; swap(S[P[i]], S[Q[i]]); swap(idx[S[P[i]]], idx[S[Q[i]]]); } return rez; }

컴파일 시 표준 에러 (stderr) 메시지

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:69:12: warning: 'rez' may be used uninitialized in this function [-Wmaybe-uninitialized]
     return rez;
            ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...