Submission #395385

#TimeUsernameProblemLanguageResultExecution timeMemory
395385rocks03Sorting (IOI15_sorting)C++14
20 / 100
4 ms460 KiB
//#pragma GCC target("avx2") //#pragma GCC optimization("O3") //#pragma GCC optimization("unroll-loops") #include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define ff first #define ss second #define pb push_back #define SZ(x) ((int)(x).size()) #define all(x) x.begin(), x.end() #define rep(i, a, b) for(int i = (a); i < (b); i++) #define per(i, a, b) for(int i = (a); i >= (b); i--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]){ vector<int> pos; set<int> st; auto random_sol = [&](){ int ans = 0; while(SZ(st)){ int i = X[ans], j = Y[ans]; auto it = st.find(S[i]); if(it != st.end()) st.erase(it); it = st.find(S[j]); if(it != st.end()) st.erase(it); swap(pos[S[i]], pos[S[j]]); swap(S[i], S[j]); if(S[i] != i) st.insert(i); if(S[j] != j) st.insert(j); if(SZ(st) == 0){ P[ans] = Q[ans++] = 0; break; } int x = rng() % N; it = st.lower_bound(x); if(it == st.end()) it--; x = *it; i = pos[x], j = x; it = st.find(S[i]); if(it != st.end()) st.erase(it); it = st.find(S[j]); if(it != st.end()) st.erase(it); swap(pos[S[i]], pos[S[j]]); swap(S[i], S[j]); if(S[i] != i) st.insert(i); if(S[j] != j) st.insert(j); P[ans] = i, Q[ans++] = j; } return ans; }; while(true){ pos = vector<int>(N); rep(i, 0, N) pos[S[i]] = i; st.clear(); rep(i, 0, N){ if(pos[i] != i) st.insert(i); } int ans = random_sol(); if(ans != -1) return ans; } }

Compilation message (stderr)

sorting.cpp: In lambda function:
sorting.cpp:36:31: warning: operation on 'ans' may be undefined [-Wsequence-point]
   36 |                 P[ans] = Q[ans++] = 0; break;
      |                            ~~~^~
sorting.cpp:36:31: warning: operation on 'ans' may be undefined [-Wsequence-point]
sorting.cpp:38:27: warning: conversion from 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   38 |             int x = rng() % N;
      |                     ~~~~~~^~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:18:39: warning: unused parameter 'M' [-Wunused-parameter]
   18 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]){
      |                                   ~~~~^
#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...