Submission #301749

#TimeUsernameProblemLanguageResultExecution timeMemory
301749letandatArranging Shoes (IOI19_shoes)C++14
10 / 100
1049 ms2168 KiB
#include<bits/stdc++.h> using namespace std; //3 //-2 2 2 -2 -2 2 int64_t count_swaps(vector <int> a) { int n = a.size()/2; int ans = 0; for (int i=0; i<2*n-1; i+=2) { if (abs(a[i])==abs(a[i+1])) continue; for (int j=i+2; j<2*n; j++) { if (abs(a[j]) == abs(a[i])) { ans += j-i-1; for (int k=j; k>=i+2; k--) { a[k] = a[k-1]; } a[i+1] = a[i]; } } } for (int i=0; i<2*n-1; i+=2) { if (a[i] > 0) ans += 1; } return ans; } void test () { int n; cin >> n; vector<int> a; for (int i=0; i<2*n; i++) { int c; cin >> c; a.push_back(c); } cout << count_swaps(a); }
#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...