Submission #207307

#TimeUsernameProblemLanguageResultExecution timeMemory
207307balbitArranging Shoes (IOI19_shoes)C++14
10 / 100
11 ms7544 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define SZ(x) (int)((x).size()) #define ALL(x) x.begin(),x.end() #ifdef BALBIT #define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<" = ", _do(__VA_ARGS__) template<typename T> void _do(T &&x) {cerr<<x<<endl;} template<typename T, typename ...S> void _do(T &&x, S&&...y) {cerr<<x<<", "; _do(y...);} #define IOS() #else #define IOS() ios::sync_with_stdio(0), cin.tie(0) #define endl '\n' #define bug(...) #endif // BALBIT const int maxn = 3e5; vector<int> tp[maxn]; ll count_swaps(vector<int> s) { int n = s.size()/2; ll re = 0; for (int i = 0; i<n*2; i++) { int x = abs(s[i]); int sgn = s[i] / x; if (SZ(tp[x]) && tp[x].back() != sgn) { for (int j = i; j>=0; --j) { if (abs(s[j-1]) == x) { if (sgn == -1) swap(s[j], s[j-1]), ++re; break; } swap(s[j], s[j-1]); ++re; } tp[x].pop_back(); }else{ tp[x].pb(sgn); } } // for (int i = 0; i<n*2; i++) { // cerr<<s[i]<<' '; // } // cerr<<endl; return re; } #ifdef BALBIT signed main(){ IOS(); int n; cin>>n; vector<int> x(n*2); for (int i = 0; i<n*2; i++) cin>>x[i]; cout<<count_swaps(x)<<endl; } #endif
#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...